BabyAGI Inside
research prototype · nov 2026 · yohei nakajima

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

run/multiply-first-5 · qwen3.5-4b · live compiled · replay
loop · compiled into the weights
Objective: one unseen five-step arithmetic chain (multiply-first). It is the only input. Everything after it is emitted by the checkpoint.
emitter · who writes each token
outforced by circuit
circuitqwenFSQwen
Compiled layersdecides
Qwen's 32 layersruns
state
0 / 3,340 tokens
written by Qwen: 0 (0 thinking)
circuit qwenFS Qwen thinking Qwen writing HALT
Token counts per stage and results are exact. Order within each stage is reconstructed; compiled tokens play fast-forward.
§01 what's new

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

Qwentool call →compiled machine

Qwen is the agent. It decides when to use the CPU, GPU or filesystem compiled into its weights.

babyagi inside

compiled loopevery step →Qwen

The loop decides when Qwen speaks and where its words go. Qwen decides what to say.

ProjectBaseCompiled inWho drives
Qwenputer4BRISC-V CPU, filesystemQwen → CPU
qwenFS2BFilesystem, 7 toolsQwen → files
qwenGPU2BSIMT GPU running CUDAQwen → GPU
qwenTPU0.8–4BMatrix-multiply arrayQwen → TPU
linuxformer4BCPU that boots LinuxQwen → shell
BabyAGI Inside4B, 2BAgent loop, task ledger, halt, on qwenFSloop → 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.

§02 how it works

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.

Objective prefill host, once Create task ledger Qwen writes JSON HALT circuit Point to task circuit, fixed order Think (256) Qwen, span forced shut Write result Qwen Persist result qwenFS, read back next cycle after N Repeats N times; N is fixed when the checkpoint is built (2, 3, 5 or 8)

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.

§03 under the hood

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

Qwen 0–2047qwenFSQwenloop
8 compiled32 Qwen layers, unchanged

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

Qwen's raw next-token scores

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.

§04 inside a run

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.

circuit
<tool_call> read_file result.json </tool_call>
qwenFS
<tool_response> {"result": 30} </tool_response> cycle 1's result, read back exactly
circuit
<tool_call> read_file ledger.json </tool_call>
qwenFS
<tool_response> {"initial": 10, "tasks": ["multiply the result by 3", "add 7", …]} </tool_response> the ledger Qwen wrote in cycle 1
circuit
EXECUTE LEDGER TASK 2/5. … Use exactly array entry 1 … the pointer advances
Qwen · think
<think> … 256 tokens of Qwen's own reasoning … </think> closed by the circuit at 256
circuit
<tool_call> write_file result.json {"result": the circuit opens the write
Qwen · write
37} </tool_call> Qwen writes the new state and closes the call
qwenFS
saved result.json
circuit
… three more cycles … HALT after cycle 5: 30, 37, 33, 66, 73
§05 what a bigger model fixed

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.

§06 results

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.

32/32
runs passed every system check: phases in order (432/432), file reads exact (256/256), HALT, token accounting
6,280
of 6,280 forced tokens matched the reference, across the four checkpoints
28/32
tasks solved by the compiled loop, up from 8/32 on Qwen3.5-2B
29/32
solved by plain Qwen3.5-4B given the same token budget
The compiled loop against plain Qwen at the loop's token budget: thinking closed at a cap, then an answer. All 32 tasks, one Apple M5.
ArmSolved of 32Tokens generatedWall time
Qwen3.5-4B
Compiled loop28100,5454.6 h
Plain Qwen2946,8001.2 h
Qwen3.5-2B
Compiled loop8104,586about 3.5 h
Plain Qwen1252,2560.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.

§07 scope

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.
§08 paper and code

BabyAGI Inside: Compiling a Bounded Agent Loop into Qwen Weights

Yohei Nakajima, 2026. Built on qwenFS by Vixhal Baraiya, whose compiler lineage traces to Qwenputer by Divyansh Agrawal. Inspired by BabyAGI (2023).

cite
@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}
}