BabyAGI Inside
A bounded agent loop, compiled into the weights of Qwen3.5-4B. No training. After one prompt, the host only samples tokens until the model halts itself.
Now on Qwen3.5-4B. Every run executes exactly as built, and the loop solves 28 of 32 tasks. Plain Qwen given the same token budget solves 29. Results
The arrow flips
A wave of projects compiles machines into Qwen's weights: a CPU, a GPU, a filesystem, a TPU, a Linux box. In each, Qwen calls the machine. Here the compiled loop calls Qwen.
everyone else
Qwen is the agent. It decides when to use the CPU, GPU or filesystem compiled into its weights.
babyagi inside
The loop decides when Qwen speaks and where its words go. Qwen decides what to say.
| Project | Base | Compiled in | Who drives |
|---|---|---|---|
| Qwenputer | 4B | RISC-V CPU, filesystem | Qwen → CPU |
| qwenFS | 2B | Filesystem, 7 tools | Qwen → files |
| qwenGPU | 2B | SIMT GPU running CUDA | Qwen → GPU |
| qwenTPU | 0.8–4B | Matrix-multiply array | Qwen → TPU |
| linuxformer | 4B | CPU that boots Linux | Qwen → shell |
| BabyAGI Inside | 4B, 2B | Agent loop, task ledger, halt, on qwenFS | loop → Qwen |
Related precedents: workflows internalized by fine-tuning (Dennis et al.), compiled modules gated with a pretrained LM (Neural Comprehension), and a compiled oversight monitor inside Qwen (Agrawal). BabyAGI Inside is training-free and runs a whole multi-cycle task loop.
One cycle, repeated N times
The weights implement the controller and the filesystem. The ledger and results a run produces live in its inference state. Qwen writes only inside the blue boxes; every transition between boxes is compiled.
host.py · the whole runtime
ids = prefill(objective) + [START]
while ids[-1] != HALT:
ids.append(argmax(model(ids)))
No scheduler, parser, tool executor, retry logic or logits processor. Every prompt, tool call, file response and control symbol after the objective comes from the checkpoint.
2023 → 2026
BabyAGI (2023) was a Python loop around GPT-4: create, prioritize, execute, store. Here what Python did is compiled and what GPT-4 did, Qwen does, in a simplified form: one up-front plan, fixed-order prioritization and a cycle count fixed at build. The checkpoint widens Qwen's residual stream to 4,096 and leaves Qwen's own weights unchanged apart from norm rescaling.
Separate lanes, one network
The loop lives in its own lanes of a widened residual stream, so Qwen's computation is left alone. A compiled gate can also restrict Qwen to legal tokens without changing which of them it prefers.
residual stream · 4,096 dims × 40 layers
Qwen3.5-4B's 2,560 native dimensions continue above qwenFS, and each part writes only to its own lanes. With the loop inactive, the merged model matches stock Qwen on tested prefixes (top-1 4/4, maximum KL 3.8e-5 nats).
typed choice gate · v17 protocol, 2B
One residual coordinate adds the same boost to "1" and "2". Qwen's own scores still decide between them; every other token loses by at least 1,893 logits. Bars not to scale.
One cycle, token by token
Abridged excerpt of cycle 2 of the five-cycle multiply-first run on Qwen3.5-4B. Each row is labeled by who emitted it. Markup is abridged; full traces are in the repository.
The failure moved from the plan to the details
Because orchestration is fixed, every failure shows up at the point where it happens. On Qwen3.5-2B the loop ran the structured tasks perfectly and the plan Qwen wrote was wrong. On Qwen3.5-4B, with the same loop and the same tasks, Qwen plans and solves every structured task; the four failures left are exact-string slips, such as casing or punctuation, inside runs where the loop did everything right.
qwen3.5-2b · structured, eight cycles
- ✓24 of 24 phases in order, every read exact, then HALT
- ✓Every result executed Qwen's own task (8/8)
- ✗The plan: task 1 added the combined amount, tasks 2 to 8 each added one
- ✗0 of 8 transitions correct; 0 of 24 non-arithmetic chains solved
A wrong plan, executed faithfully. Arithmetic chains, where the plan is easy, came out right every time.
qwen3.5-4b · same loop, same 32 tasks
- ✓32 of 32 runs pass every system check
- ✓Structured chains 8/8, often with the steps paraphrased
- ✗"Uppercase only the word lanterns" gave Lanterns, not LANTERNS
- ✗A final ! placed inside the bracket
All four 4B failures are exact-string slips like these, at five and eight cycles.
Exact control, not extra capability
A frozen, preregistered 32-task live evaluation of the compiled Qwen3.5-4B checkpoints: four task families, two to eight cycles, Apple M5 (MPS, bf16), greedy decoding.
| Arm | Solved of 32 | Tokens generated | Wall time | |
|---|---|---|---|---|
| Qwen3.5-4B | ||||
| Compiled loop | 28 | 100,545 | 4.6 h | |
| Plain Qwen | 29 | 46,800 | 1.2 h | |
| Qwen3.5-2B | ||||
| Compiled loop | 8 | 104,586 | about 3.5 h | |
| Plain Qwen | 12 | 52,256 | 0.6 h | |
On 4B the two arms reach the same verdict on 31 of 32 tasks (compiled minus plain −3.1 points, 95% CI [−9.4, 0.0]); on 2B plain Qwen wins four tasks and loses none. The compiled loop never solves a task plain Qwen misses. An earlier one-turn plain baseline (15 and 5 of 32) stopped every run before Qwen finished thinking, so it measured truncation, not capability. Budget-forced results
Longer tasks. On 48 held-out tasks of 4 to 32 steps, an adaptive version of the loop, run as host code around stock Qwen3.5-4B, solved 20, or 25 when stopped at the true length, against plain Qwen's 38 at the same budget. The preregistered decision was not to compile it. Longer-task screen
On 2B, in two runs, tool-call markup inside Qwen's reasoning switched qwenFS into write mode, a parser behavior inherited from qwenFS. It did not occur in the 4B sweep, though the parser is unchanged.
What this is, and what it isn't
it is
- A working prototype of an agent loop compiled into a pretrained model's weights, without training.
- A checkpoint whose host loop only samples tokens.
- A way to see exactly which tokens the model wrote, and where it went wrong.
it isn't
- A smarter Qwen. Plain Qwen3.5-4B at the same token budget solves as many of these tasks, in about a quarter of the time.
- Unbounded. The cycle count is fixed when the checkpoint is built, and on longer tasks a host-run adaptive version lost to plain Qwen.
- Proven for every possible output. Validation covers the tested traces on Apple MPS, bf16.
@misc{nakajima2026babyagiinside,
author = {Nakajima, Yohei},
title = {BabyAGI Inside: Compiling a Bounded Agent Loop into Qwen Weights},
year = {2026},
doi = {10.5281/zenodo.23966216},
url = {https://babyagi.yohei.me}
}