Self-improving agent harnesses: Recursive Language Models, Continual Harness and Prime Agent
Instead of stuffing everything into the model's context, let the model hold its context in variables, write code over it, call copies of itself, and edit its own notes, skills and helpers as it learns.
Start here (no maths needed)
A "harness" is everything wrapped around an AI model so it can do long jobs. The new idea: let the model organise its own notes and helpers, and improve them as it goes.
Think of it like this
Imagine doing a huge school project. You can't hold every page of every book in your head at once. So you keep a binder with labelled tabs, you ask friends to read some chapters and report back, and you keep a "tips that worked" sheet that you update after every mistake. Smart students don't just read harder. They get better at organising.
- The binder is the RLM idea: keep the material in labelled places and look up only what you need.
- The friends are sub-agents: copies of the AI that each handle a piece and report back.
- The tips sheet is the Continual Harness: the AI writes down what worked and fixes its own instructions.
How it works
- The AI gets a notebook it can run code in. Big inputs (whole books, codebases, logs) sit in the notebook as named variables, not in its "head".
- It writes small programs to search, cut up and filter that material.
- For big jobs, it sends pieces to helper copies of itself, which work in parallel and message back.
- After a while, it looks back at what happened and makes a small, careful change to its notes, skills or helpers, and can undo it if it was a bad idea.
- It keeps going (bounded by limits on time, tokens and turns) until a check says the job is done.
Why robots care
The "tips sheet that improves itself" idea was first built for an AI playing Pokémon. That's a game where you can't restart, can only see part of the world, and must plan for a very long time, just like a real robot. Robots can't press "reset" in your kitchen, so learning while doing, without restarts, matters a lot.
Try it
- Next time you study for a test, keep a "what tripped me up" list. After each practice session, add or change one line. Notice how small, regular fixes add up.
- In the demo below, drag Context size up to a million tokens or more, then change Sub-call window. See how many helper calls and how many levels of helpers it takes, while the main AI still only reads a small amount.
Words to know
- Harness
- The software around an AI model: tools, memory, instructions and helpers.
- Context window
- How much text the model can "see" at once.
- REPL
- A notebook where you type code, run it, and see results straight away.
- Sub-agent
- A helper copy of the AI given part of the job.
- Context rot
- Models getting worse as their context fills up with lots of text.
Going deeper: everything below is the full version. On a first read, look at the three-ideas table, the demo and the robotics section.
Track: LLM + Robotics. RLMs and Prime Agent are LLM agent technology. Continual Harness, one of Prime Agent's two pillars, was designed for embodied agents with long horizons and partial observability, so it connects directly to robot autonomy.
- Summary
- Why this matters for robotics
- Deep dive: Recursive Language Models (interactive)
- Deep dive: Continual Harness, an agent that edits its own harness
- Deep dive: Prime Agent, putting it together
- Deep dive: results, and how to read them
- Deep dive: safety and bounds
- Playbook
- Self-check
- Glossary & further reading
1. Summary
TL;DR
Prime Agent (Prime Intellect with collaborators, Aug 2026) is an open-source (MIT) coding and research agent built on two ideas:
- Recursive Language Models (RLMs): the model's only tool is a persistent Python REPL. Long context lives there as variables ("prompt-as-a-variable"), and sub-agents are async function calls.
- Continual Harness: the harness's own prompts, skills, memories and sub-agent specs are durable state the agent can create, read, update and delete. A
/refinestep makes small, evidence-backed edits from the agent's own trajectory, never touching the base system prompt, with rollback.
The design philosophy: the harness standardises execution, recovery, verification and accounting, but leaves strategy to the model, so harness failures don't masquerade as model failures.
| Idea | Problem it attacks | Core mechanism | Source |
|---|---|---|---|
| RLM | Context rot and context-window limits | Context stored in a REPL variable; the model programmatically examines and decomposes it and recursively calls itself on snippets | Zhang, Kraska & Khattab, arXiv 2512.24601 (blog Oct 2025; paper Dec 2025, revised May 2026) |
| Continual Harness | Hand-engineered prompts, skills and memory that never adapt; prompt optimisation that needs episode resets | Harness state H = (ρ, G, K, M), meaning prompt, sub-agents, skills and memory, refined online within a single run | Karten et al., arXiv 2605.09998 (May 2026) |
| Prime Agent | Harnesses built around older models' limits (fixed tool schemas, compaction) | RLM REPL + Continual Harness + persistent sub-agents + agent-to-agent messaging + a background daemon | Karten, Zhang et al., arXiv 2608.23552 (Aug 2026); repo |
2. Why this matters for robotics
- Continual Harness was born embodied. It came from the Gemini Plays Pokémon experiments, where human-in-the-loop harness refinement helped the agent become, per the paper, the first AI system to complete Pokémon Blue, Yellow Legacy on hard mode, and Crystal without a lost battle. Continual Harness then removed the human from that loop. Long horizons plus partial observability is the robot setting.
- Reset-free learning is the real-world constraint. Prompt-optimisation methods need episode resets. Continual Harness adapts within a single run. A home robot can't reset the kitchen between attempts.
- Skills libraries and sub-agents mirror robot stacks. Many robot systems already use an LLM planner that calls skills (grasp, navigate, open-door) and delegates to specialised policies. A harness that can add and refine its own skill descriptions and helper specs is a software version of that stack learning on the job.
- Programmatic context fits sensor data. An hour of robot logs (joint states, detections, events) is far too big for a context window. Holding it as a variable and querying it with code ("when did the gripper last slip?") is the RLM pattern.
- Bounded autonomy is a safety envelope. Prime Agent's autonomous mode runs within turn, token and time budgets with quality gates. Robots need the same idea with physical limits. See Module 03, levels of automation.
3. Deep dive: Recursive Language Models
The problem. Per-token cost rises with context length, and quality tends to fall as contexts grow. This is called context rot. Common fixes: summarise or compact the history (lossy), or pass state between agents through files.
The RLM move. Don't give the model the context at all. Give it the query, plus a REPL in which the context is pre-loaded as a variable. The model (the "root" LM, depth 0) writes code to peek at, search, slice and transform that variable. It can also call sub-LMs, fresh copies of itself, on pieces of it, and combine their answers. From the outside it's a drop-in replacement for a normal completion call.
# the shape of an RLM call (illustrative, not the library's exact API)
answer = rlm.completion(query, context=huge_text) # same interface as an LM call
# inside, the root model might write:
chunks = split(context, 100_000)
notes = llm_batch([f"Find mentions of X in:\n{c}" for c in chunks]) # parallel sub-LMs
answer = llm(f"Combine these findings to answer: {query}\n{notes}")
- No summarisation, so no forced loss. The full context stays available in memory. The model chooses what to read.
- Test-time compute becomes programmable: loops, filters, parallel fan-out.
- Prime Intellect's variant (in their
verifierslibrary): only sub-LLMs get tools beyond the REPL, so tool output tokens don't flood the root. Answers are returned via a variable. Anllm_batchfunction runs sub-calls in parallel.
Reported results (RLM paper abstract):
- Handles inputs up to two orders of magnitude beyond the model's context window.
- With GPT-5, it beats common scaffolds at comparable cost. The median improvements across four long-context tasks were 26% over compaction, 130% over CodeAct with sub-calls, and 13% over Claude Code.
- A small post-trained model, RLM-Qwen3-8B, beat its base Qwen3-8B by 28.3% on average.
Interactive: what a recursive call tree costs
Exact arithmetic for a simple split-and-delegate strategy. Each level splits its input into pieces that fit the sub-call window, and each parent reads only short notes from its children. No accuracy is modelled here; this shows structure and token cost only.
4. Deep dive: Continual Harness, an agent that edits its own harness
The observation. In the Gemini Plays Pokémon runs, people kept improving the harness. In the hardest stages, the agent itself began iterating on its strategy through long-context memory. Continual Harness formalises and automates that loop.
The formalism. The harness state is
H = (ρ, G, K, M) # prompt, sub-agents, skills, memory
Starting from only a minimal environment interface, the agent alternates between acting and refining H, drawing on any past trajectory data, all without resetting the environment.
- Result (paper abstract): on Pokémon Red and Emerald across frontier models, starting from scratch, it substantially cut button-press cost compared with a minimal baseline. It also recovered most of the gap to a hand-engineered expert harness. Gains depended on model capability.
- Closing the loop with the model: an online process-reward co-learning loop. An open-source agent's rollouts through the refining harness are relabelled by a frontier teacher and used to update the model, again without environment resets. It's the distillation pattern of Module 04, run continuously.
In Prime Agent, the harness state lives in the REPL as rlm.harness, with one create/read/update/delete surface for all four kinds (prompt notes, memories, skills, sub-agent specs), persisted to disk.
/refine reads the trajectory and applies the smallest relevant edit, recording its trigger and outcome. The planning runs in the background, and the apply step blocks only briefly at a turn boundary. The base system prompt is immutable, and refinements can be rolled back by ID.
Why "small, evidence-backed, reversible" matters: self-modifying systems can drift, the same failure as reward hacking in Module 07. Small diffs, recorded evidence, a fixed core and rollback are the harness-level equivalent of a KL leash.
5. Deep dive: Prime Agent, putting it together
| Component | What it does |
|---|---|
| Persistent IPython kernel | The model's only tool. Files, shell, tools, skills and sub-agents are all called as functions from code. |
rlm(...) sub-agents | Async: spawning returns a handle immediately. Each child is a full Prime Agent session (own model, kernel, history). Results arrive as messages, and children can be steered mid-flight or kept as persistent sub-agents. |
| Agent-to-agent messaging | Through a background daemon. Limited to the "nuclear family" (parent, sibling, child) to avoid unwanted cross-talk between independent sessions. |
| Daemon + Agents View | Sessions keep running when the terminal detaches. Crashed workers recover from the session's append-only JSONL plus a kernel snapshot. Idle sub-agents unload after 30 minutes and reload on demand. |
| Session & context | The full history is append-only JSONL. Compaction cleans the active context, but the full history stays reachable from the kernel. A spawned agent "garbage-collects" REPL memory. |
| Skills | Importable Python packages. A built-in skill creator turns recurring workflows into skills. |
| Autonomous mode | Goal + heartbeats + continuation, bounded by max turns, tokens and time, with a quality-gate command that must pass before finishing. |
Compare the two ways of beating long context in this course. Module 05 changes the architecture (Kimi K3's fixed-size linear-attention memory). RLMs change the scaffolding, so the model manages context with code. They're complementary. External, addressable memory also echoes the Neural Turing Machine (Module 06, Day 17), now with Python as the memory controller.
6. Deep dive: results, and how to read them
- ARC-AGI-3: the paper reports raising RHAE Best@1 from 30% to 95.5%. The launch post attributes the best result to Opus 5 inside Prime Agent, notes the ARC-reported human-expert baseline of 95.4%, and gives three runs of 95.0, 95.2 and 95.5, with Best@3 99.97% and all 183 levels completed. The only ARC-specific change was the task prompt.
- Token efficiency: the post reports higher maximum scores than the models' native harnesses at lower token use. Its explanation is that running functions over data costs fewer tokens than reading the data through tools.
- Long-context suite: using the open-weights GLM-5.2 in Prime Agent against closed models in their own harnesses, the post shows Prime Agent competitive or ahead on several tasks. One example: OOLONG (128k), 0.700 for Prime Agent with GLM-5.2 vs 0.420 for Pi-mono with sub-agents.
- Also reported: results on GPU-kernel generation, emulator construction, autonomous nanoGPT speedruns and Factorio. In Factorio, refinement enabled continuous technology progression and dedicated sub-agents parallelised work.
Reading these critically (Module 01 and Module 08 Stage 10 habits):
- These are the authors' own results. The post notes that no model has been trained around Prime Agent yet.
- For Claude Code and Codex, the authors used the official reported numbers because their own runs scored lower. That's fair, but it means the comparison mixes evaluation setups.
- Harness comparisons depend heavily on prompts, budgets and gates. Look for matched token and time budgets before concluding one harness is "better".
- The paper's thesis cuts both ways: if harness failures can look like model failures, then benchmark scores measure the model + harness pair, never the model alone.
7. Deep dive: safety and bounds
- Not a sandbox: the README warns that Prime Agent executes model-generated Python and project commands with your user permissions. Its process isolation is for recovery, not security. Use disposable clones or worktrees, trusted repos and skills only, and an external sandbox for untrusted code.
- Bounded autonomy: autonomous mode stops at configured turn, token and time limits. The README notes that passing a gate checks only what that gate verifies, and that hitting a limit doesn't mean success.
- Self-editing risk: refinement edits only the supplemental layer, keeps the base prompt immutable, records history and supports rollback. Review refinements as you would code changes.
- Communication scope: agent-to-agent messaging is restricted to parent, sibling and child sessions.
8. Playbook
- Try the minimal RLM first: rlm-minimal. Put a long document in a REPL variable and let a model answer questions by writing code over it.
- Compare against "paste it all in" and "summarise then answer" on the same questions. Measure accuracy and total tokens.
- Run Prime Agent in a disposable worktree. Give it a goal, a quality gate (tests) and tight turn, token and time budgets.
- Watch
/refine: read each proposed edit, keep the good ones, and roll back the rest. Treat harness state like code under review. - Robotics exercise: log a simulated robot run (states, events, failures) to a file, load it as a variable, and have an RLM-style agent answer "why did grasp attempt 7 fail?" by querying the log with code.
9. Self-check
What's the key difference between an RLM and summarisation-based compaction?
Compaction replaces history with a lossy summary. An RLM keeps the full context available as a variable and lets the model choose what to read or delegate. Nothing is thrown away by default.
Why does Prime Intellect's RLM give tools only to sub-LLMs?
Tools often produce many tokens. Pushing tool use to sub-LLMs keeps the root model's context lean, and the root sees only the condensed results.
What does "reset-free" mean in Continual Harness, and why does it matter for robots?
The agent refines its prompts, skills, memory and sub-agents online within a single run, without restarting the environment. Real robots can't reset the world between attempts.
Name three safeguards on Prime Agent's self-improvement.
Small, evidence-backed edits with recorded triggers and outcomes; an immutable base system prompt; and rollback of refinements by ID.
Why should benchmark results be read as "model + harness"?
The harness shapes what the model can do: tools, context handling, budgets, gates. Different harnesses give the same model very different scores, which is the paper's own central claim.
How do Module 05's linear attention and an RLM both address long context?
Linear attention changes the architecture so memory stays fixed-size. An RLM changes the scaffolding so the model manages context with code and sub-calls. They're complementary approaches.
10. Glossary & further reading
| Term | Meaning |
|---|---|
| Harness / scaffold | Software around a model: tools, memory, prompts, control loop |
| RLM | Recursive Language Model: the model manages context as REPL variables and recursively calls sub-LMs |
| Prompt-as-a-variable | Context held in program memory, not in the model's context window |
| Programmatic tool calling | Calling tools and sub-agents as functions from code, not via fixed schemas |
| Continual Harness | A reset-free method where the agent refines its own prompt, sub-agents, skills and memory |
| /refine | Prime Agent's step that makes small, evidence-backed harness edits |
| Context rot | Quality decline as context grows |
| Context folding | Methods that manage the context window during a long rollout (branch/return, hierarchical summaries) |
| Quality gate | A command (e.g. tests) that must pass before an autonomous run may finish |
- Karten, Zhang et al., Prime Agent: A Self-Improving RLM Harness (arXiv 2608.23552) · repo · launch post · project page
- Zhang, Kraska & Khattab, Recursive Language Models (arXiv 2512.24601) · original blog post · library · minimal implementation
- Karten et al., Continual Harness: Online Adaptation for Self-Improving Foundation Agents (arXiv 2605.09998)
- Prime Intellect, Recursive Language Models: the paradigm of 2026 · verifiers · prime-rl
- The 2h36m video walkthrough (Yacine Mahdid with Seth Karten)
- In this course: 05 (architectural long context), 06 Day 17 (external memory), 07 (verifiers and process rewards), 04 (teacher relabelling), 03 (levels of autonomy), 08 Stage 10 (evals)