# volotat/mini-agi architecture

> Architecture diagram of the GitHub repository volotat/mini-agi, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-09). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/volotat/mini-agi
- Repository: https://github.com/volotat/mini-agi

## Overview

mini-AGI is a byte-level continual-learning language model designed to train and serve on modest GPU memory by paging expert weights from disk. The principal workflow reads text as a stream, tokenizes it, trains the recurrent model while adapting its expert pool, and persists weights; serving generates replies through the model and can feed conversations back into live learning. The README also highlights generated evaluation/training domains and adaptive growth and pruning. Some subsystem links are documented or indexed rather than visible in the sampled excerpts, so uncertain connections are omitted.

Main entry points: [`train.py`](https://github.com/volotat/mini-agi/blob/main/train.py) (Training loop), [`serve.py`](https://github.com/volotat/mini-agi/blob/main/serve.py) (Chat server), [`minagi/recur.py`](https://github.com/volotat/mini-agi/blob/main/minagi/recur.py) (Adaptive recurrence), [`minagi/tokenizer.py`](https://github.com/volotat/mini-agi/blob/main/minagi/tokenizer.py) (Byte tokenizer)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_inputs["Text and corpora"]
  node_files["Text files"]
  node_ingest["Text discovery<br/>[ingest.py]"]
  node_corpus["Corpus builders"]
  node_arithmetic["Arithmetic data<br/>[arithmetic.py]"]
  node_tokenizer["Byte tokenizer<br/>[tokenizer.py]"]
  node_stream["Corpus stream<br/>[stream.py]"]
end

subgraph group_learning["Continual learning"]
  node_train["Training loop<br/>[train.py]"]
  node_config["Model settings<br/>[config.py]"]
  node_optim["Optimizer<br/>[optim.py]"]
  node_plasticity["Pool adaptation<br/>[plasticity.py]"]
end

subgraph group_runtime["Model runtime"]
  node_recur["Adaptive recurrence<br/>[recur.py]"]
  node_model["Model blocks<br/>[model.py]"]
  node_pool["Expert routing<br/>[pool.py]"]
  node_paged["Expert paging<br/>[paged.py]"]
  node_precision["Compute precision<br/>[precision.py]"]
end

subgraph group_serving["Serving and state"]
  node_store[("Weight storage<br/>[store.py]")]
  node_serve["Chat server<br/>[serve.py]"]
  node_decode["Text decoding<br/>[decode.py]"]
  node_live["Live learning<br/>[live.py]"]
end

node_user(("Chat user"))

node_files -->|"scans text"| node_ingest
node_ingest -->|"encodes files"| node_tokenizer
node_corpus -->|"uses byte tokens"| node_tokenizer
node_arithmetic -->|"generates examples"| node_corpus
node_stream -->|"supplies batches"| node_train
node_tokenizer -->|"provides tokens"| node_train
node_ingest -->|"feeds reading"| node_train
node_config -->|"configures run"| node_train
node_train -->|"trains model"| node_recur
node_train -->|"steps optimizer"| node_optim
node_train -->|"adapts capacity"| node_plasticity
node_train -->|"saves weights"| node_store
node_recur -->|"applies blocks"| node_model
node_recur -->|"routes experts"| node_pool
node_pool -.->|"requests experts"| node_paged
node_paged -->|"loads expert files"| node_store
node_paged -->|"uses compute settings"| node_precision
node_serve -->|"streams reply"| node_user
node_serve -->|"runs generation"| node_recur
node_serve -->|"decodes output"| node_decode
node_serve -->|"feeds exchange"| node_live
node_live -.->|"updates weights"| node_store
node_serve -->|"encodes prompt"| node_tokenizer

click node_ingest "https://github.com/volotat/mini-agi/blob/main/minagi/ingest.py"
click node_corpus "https://github.com/volotat/mini-agi/tree/main/corpora"
click node_arithmetic "https://github.com/volotat/mini-agi/blob/main/corpora/arithmetic.py"
click node_tokenizer "https://github.com/volotat/mini-agi/blob/main/minagi/tokenizer.py"
click node_stream "https://github.com/volotat/mini-agi/blob/main/minagi/stream.py"
click node_train "https://github.com/volotat/mini-agi/blob/main/train.py"
click node_config "https://github.com/volotat/mini-agi/blob/main/minagi/config.py"
click node_recur "https://github.com/volotat/mini-agi/blob/main/minagi/recur.py"
click node_model "https://github.com/volotat/mini-agi/blob/main/minagi/model.py"
click node_pool "https://github.com/volotat/mini-agi/blob/main/minagi/pool.py"
click node_paged "https://github.com/volotat/mini-agi/blob/main/minagi/paged.py"
click node_precision "https://github.com/volotat/mini-agi/blob/main/minagi/precision.py"
click node_optim "https://github.com/volotat/mini-agi/blob/main/minagi/optim.py"
click node_plasticity "https://github.com/volotat/mini-agi/blob/main/minagi/plasticity.py"
click node_store "https://github.com/volotat/mini-agi/blob/main/minagi/store.py"
click node_serve "https://github.com/volotat/mini-agi/blob/main/serve.py"
click node_decode "https://github.com/volotat/mini-agi/blob/main/minagi/decode.py"
click node_live "https://github.com/volotat/mini-agi/blob/main/minagi/live.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_files,node_ingest,node_corpus,node_arithmetic,node_tokenizer,node_stream,node_user toneBlue
class node_train,node_config,node_optim,node_plasticity toneAmber
class node_recur,node_model,node_pool,node_paged,node_precision toneMint
class node_store,node_serve,node_decode,node_live toneRose
```

## Components

### Text and corpora

- **Text files**
- [Text discovery](https://github.com/volotat/mini-agi/blob/main/minagi/ingest.py): `minagi/ingest.py`
- [Corpus builders](https://github.com/volotat/mini-agi/tree/main/corpora): `corpora`
- [Arithmetic data](https://github.com/volotat/mini-agi/blob/main/corpora/arithmetic.py): `corpora/arithmetic.py`
- [Byte tokenizer](https://github.com/volotat/mini-agi/blob/main/minagi/tokenizer.py): `minagi/tokenizer.py`
- [Corpus stream](https://github.com/volotat/mini-agi/blob/main/minagi/stream.py): `minagi/stream.py`

### Continual learning

- [Training loop](https://github.com/volotat/mini-agi/blob/main/train.py): `train.py`
- [Model settings](https://github.com/volotat/mini-agi/blob/main/minagi/config.py): `minagi/config.py`
- [Optimizer](https://github.com/volotat/mini-agi/blob/main/minagi/optim.py): `minagi/optim.py`
- [Pool adaptation](https://github.com/volotat/mini-agi/blob/main/minagi/plasticity.py): `minagi/plasticity.py`

### Model runtime

- [Adaptive recurrence](https://github.com/volotat/mini-agi/blob/main/minagi/recur.py): `minagi/recur.py`
- [Model blocks](https://github.com/volotat/mini-agi/blob/main/minagi/model.py): `minagi/model.py`
- [Expert routing](https://github.com/volotat/mini-agi/blob/main/minagi/pool.py): `minagi/pool.py`
- [Expert paging](https://github.com/volotat/mini-agi/blob/main/minagi/paged.py): `minagi/paged.py`
- [Compute precision](https://github.com/volotat/mini-agi/blob/main/minagi/precision.py): `minagi/precision.py`

### Serving and state

- [Weight storage](https://github.com/volotat/mini-agi/blob/main/minagi/store.py): `minagi/store.py`
- [Chat server](https://github.com/volotat/mini-agi/blob/main/serve.py): `serve.py`
- [Text decoding](https://github.com/volotat/mini-agi/blob/main/minagi/decode.py): `minagi/decode.py`
- [Live learning](https://github.com/volotat/mini-agi/blob/main/minagi/live.py): `minagi/live.py`

### Other components

- **Chat user**

## Connections

- Text files → Text discovery: scans text (evidence: `minagi/ingest.py`)
- Text discovery → Byte tokenizer: encodes files (evidence: `minagi/ingest.py`)
- Corpus builders → Byte tokenizer: uses byte tokens (evidence: `corpora/arithmetic.py`)
- Arithmetic data → Corpus builders: generates examples (evidence: `corpora/arithmetic.py`)
- Corpus stream → Training loop: supplies batches (evidence: `train.py`)
- Byte tokenizer → Training loop: provides tokens (evidence: `train.py`)
- Text discovery → Training loop: feeds reading (evidence: `train.py`)
- Model settings → Training loop: configures run (evidence: `train.py`)
- Training loop → Adaptive recurrence: trains model (evidence: `train.py`)
- Training loop → Optimizer: steps optimizer (evidence: `train.py`)
- Training loop → Pool adaptation: adapts capacity (evidence: `train.py`)
- Training loop → Weight storage: saves weights (evidence: `train.py`)
- Adaptive recurrence → Model blocks: applies blocks (evidence: `minagi/recur.py`)
- Adaptive recurrence → Expert routing: routes experts (evidence: `minagi/recur.py`)
- Expert routing → Expert paging: requests experts (evidence: `minagi/paged.py`)
- Expert paging → Weight storage: loads expert files (evidence: `minagi/paged.py`)
- Expert paging → Compute precision: uses compute settings (evidence: `minagi/paged.py`)
- Chat server → Chat user: streams reply (evidence: `serve.py`)
- Chat server → Adaptive recurrence: runs generation (evidence: `serve.py`)
- Chat server → Text decoding: decodes output (evidence: `serve.py`)
- Chat server → Live learning: feeds exchange (evidence: `serve.py`)
- Live learning → Weight storage: updates weights (evidence: `minagi/live.py`)
- Chat server → Byte tokenizer: encodes prompt (evidence: `serve.py`)
