Introduction
"An agent shouldn't reset to blank after every session — it should get better at the job as it works."
This is the 175th article in the "One Open Source Project a Day" series. Today's project is prime-agent.
Most AI coding tools work like this: you describe a task, the agent executes, the session ends, and next time you start over. The agent knows nothing about your work habits, code style, or toolchain. You re-explain context every single time.
prime-agent does something different: it accumulates experience as it works, distilling patterns from the session trajectory into a persisted harness state via the /refine command. That state carries over to the next session — and the whole process is conservative and reversible.
19.6k Stars, MIT license, built by the PrimeIntellect AI team.
What You Will Learn
- The core idea behind RLM's "context as variables" model
- How Continual Harness stores and manages persistent agent state
- The design philosophy of
/refineas conservative self-improvement - Why Python REPL was chosen as the primary tool interface
- How subagents coordinate via
rlm(...)function calls - The Daemon/Worker/Kernel three-layer process model
Prerequisites
- Familiarity with AI coding tools (Claude Code, Cursor, etc.)
- Basic understanding of Python REPL
- Optional: understanding the distinction between autonomous agents and conversational AI
Project Background
What It Is
prime-agent's official description: "\"A self-improving RLM agent for coding workflows and long-running autonomous tasks.\""
Two key terms need unpacking:
RLM (Recursive Language Model): Not a new model architecture, but a runtime paradigm that deeply integrates language models with programmatic execution. Context is a variable. Tool calls are functions. Subagents are subroutines that can be called recursively. The entire interaction happens inside a persistent Python REPL.
Self-improving: Not unconstrained rewriting, but finding patterns in the session trajectory that can improve harness state (supplemental prompts, memories, skill descriptions, subagent specs), applying "small, evidence-backed updates," and retaining snapshots for rollback.
Author / Team
- Team: PrimeIntellect AI (Karten, Zhang, Thomas, Müller et al.)
- Website: PrimeIntellect.ai
- License: MIT
- Language: TypeScript + Python
Project Stats
- ⭐ GitHub Stars: 19,600+
- 🍴 Forks: 2,100+
- 📄 License: MIT
- 💻 Primary Language: TypeScript + Python
- 📦 Install:
curl -fsSL https://app.primeintellect.ai/prime-agent/install.sh | sh
Core Features
What Problem It Solves
prime-agent inserts a new abstraction layer between tools and agent persistence:
Traditional coding agent:
User input → session context → tool calls → output
↑ Session ends, context clears, state resets
prime-agent:
User input
↓
Python REPL (primary tool interface)
↓
rlm(...) subagent calls ←──── parallel/recursive
↓
Continual Harness (persistence layer)
├── Supplemental prompts (behavioral corrections)
├── Memories (habits, conventions, project context)
├── Skills (importable Python packages)
└── Subagent specs (specialized subagent configs)
↓
/refine ← session trajectory → incremental harness updates (reversible)
Usage Scenarios
-
Long-running code refactoring
- Large-scale refactors spanning multiple sessions. The harness remembers project conventions — no need to re-explain "this project's naming convention is..."
-
Research workflow automation
- Scientific evaluations, batch experiments. Daemon mode keeps tasks running after terminal disconnect; heartbeat checks in on progress.
-
Multi-agent orchestration
- The main agent calls specialized subagents (code review, doc generation, test writing) via
rlm(...), receiving results as return values.
- The main agent calls specialized subagents (code review, doc generation, test writing) via
-
Custom skill development
- Package repetitive workflows as Python packages (skills), reusable at project or personal level, shareable across a team.
-
Autonomous mode
- Set turn counts, token budgets, time limits; define quality gates to validate results; let the agent work unattended.
Quick Start
# Install
curl -fsSL https://app.primeintellect.ai/prime-agent/install.sh | sh
# Verifies SHA-256 checksum; installs prime-agent CLI + Python runtime
# Navigate to your project
cd /path/to/project
# Launch
prime-agent
# First time: configure model provider
/login
# View persistent goal
/goal
# Trigger harness refinement
/refine
# Reattach from another terminal
prime-agent attach <agent-name>
Core Features
1. RLM: Context as Variables
The RLM paradigm centers on "prompt-as-a-variable" — context is not a static string but a programmable variable:
# Subagent calls are ordinary function calls inside the Python REPL
result = rlm("Analyze src/auth/ and find all missing permission checks")
# Parallel execution
import asyncio
results = await asyncio.gather(
rlm("Write unit tests", files=["src/auth.py"]),
rlm("Generate API docs", files=["src/routes.py"])
)
# Results are Python objects — work with them directly
for r in results:
print(r.summary)
"Everything is programmatic" — file operations, shell commands, tool use, subagent spawning all happen through executable code, not conversation.
2. Continual Harness: Persistent Agent State
Harness is the structural difference between prime-agent and a standard chat agent:
| Harness Component | Content | Purpose |
|---|---|---|
| Supplemental prompts | Behavioral correction instructions | Adjust default decision style |
| Memories | Work habits, project conventions, known context | Eliminate repeated context setup |
| Skill descriptions | Registered Python skill package specs | Agent knows when to invoke which skill |
| Subagent specs | Role and capability definitions | Main agent knows how to delegate |
Harness state is stored locally by default, persists across sessions, and fully recovers on restart.
3. /refine: Conservative Self-Improvement
This is prime-agent's most philosophically deliberate feature:
/refine workflow:
1. Review current session trajectory
(what was done, what problems hit, what tools used)
2. Identify improvement opportunities
(recurring patterns, inefficient tool chains, missing memories)
3. Generate "small, evidence-backed" harness update proposals
↳ Update supplemental prompts → adjust behavior
↳ Add memory entries → retain context
↳ Refine skill descriptions → improve invocation accuracy
4. Apply updates (create snapshot)
5. If results are poor: roll back to any snapshot
Hard constraint: base system prompt is immutable — never modified
"Conservative" is a design choice, not a limitation: each /refine makes only small updates, snapshots make every step reversible, and users can always review and intervene.
4. Daemon/Worker/Kernel Three-Layer Process Model
┌─────────────────────────────────────────┐
│ Kernel │
│ Manages persistence boundaries, │
│ coordinates state reads/writes │
│ │
│ Worker │
│ Lifecycle isolation and crash recovery │
│ (stability isolation, NOT a security │
│ sandbox) │
│ │
│ Daemon │
│ Continues running after terminal close │
│ Reattach via: prime-agent attach <name> │
└─────────────────────────────────────────┘
These three layers guarantee reliability for long-running tasks: sessions don't depend on terminal windows, crashes recover automatically, and reconnection restores full state.
5. Autonomous Mode and Quality Gates
# Configure budget boundaries
/autonomous --turns 50 --tokens 200k --time 2h
# Set a persistent goal (tracked across turns until completion or manual clear)
/goal "Refactor auth module, pass all existing tests, ≥ 85% code coverage"
Key design detail: "A passed quality gate only verifies what that gate checks; reaching a budget limit does not imply task success."
The agent stops at limits and reports status — it never pretends the task is done.
6. Heartbeat and Schedule System
Three temporal re-entry mechanisms:
# Manual (TUI command)
/heartbeat
# Programmatic (from within the Python REPL)
rlm_heartbeat()
# Time-based scheduling
prime-agent schedule --interval 30m "Check CI status and handle failing tests"
Heartbeats let the agent come back and continue long tasks on schedule — no external cron, no server needed.
7. Skills: Importable Python Packages
Skills are executable Python packages, not prompt templates:
# Use a built-in skill
from skills.code_review import run_review
result = run_review(files=["src/"], style="strict")
# Create a custom skill
prime-agent skill create "git-workflow"
# Generates a skill package scaffold; register at project or user level
Deep Dive
Why a Persistent Python REPL
Most coding agents use a "tool call list" interface — the agent picks a tool, passes parameters, waits for a return value. prime-agent took a different path: the Python REPL is the primary tool interface.
This choice has several deep implications:
- Composability: Tool calls can be composed into arbitrarily complex programs, unconstrained by a predefined tool set
- State retention: Variables, functions, and imported modules persist throughout the session
-
Natural expression for subagents:
rlm(...)is a function call; its return value is usable on the next line - Debug-friendly: Any intermediate state can be inspected and manipulated — not a black box
Why Harness Conservatism Matters
A self-improving agent faces an obvious risk: if it can modify its own behavior, who ensures the modifications are correct?
prime-agent's answer: conservatism + auditability + reversibility.
-
Conservatism: Each/refinemakes only small updates; large-scale base behavior rewrites are prohibited -
Auditability: Every update is justified by session trajectory evidence, not random inference -
Reversibility: Snapshots are created before each update is applied; rollback is available at any point -
Immutable floor: The base system prompt is never modified; only the supplemental harness components can change
This design transforms self-improvement from "untrustworthy black-box operation" into "incremental update process the user can understand and intervene in."
Positioning vs. Other Coding Agents
| Tool | Positioning | Key Difference |
|---|---|---|
| Claude Code | Interactive coding assistant | Each session is independent, no persistent harness |
| Cursor Agent | IDE-embedded AI | Coupled to the editor, not suited for long autonomous tasks |
| OpenHands | Fully autonomous software engineering | Independent execution, lacks conservative self-improvement |
| prime-agent | Self-improving RLM agent | Persistent harness + conservative /refine + cross-session state |
prime-agent's differentiation isn't "doing more things" — it's "becoming more suited to doing this thing as it works."
Long-Running Task Design Details
Every detail in prime-agent is tuned for long-running execution:
- Automatic context compaction: Long sessions auto-compact; context overflow never interrupts the task
-
Persistent goals (
/goal): Tracked across turns until completed; never lost in compaction - Daemon persistence: Tasks decouple from terminal windows; SSH disconnect doesn't interrupt
- Crash recovery (Worker layer): Process crashes restart automatically; state restores from persistence
- Heartbeat scheduling: No need to watch the screen; the agent comes back and checks in on schedule
Project Links & Resources
Official Resources
- 🌟 GitHub: https://github.com/PrimeIntellect-ai/prime-agent
- 🌐 Website: primeintellect.ai
- 📦 Install:
curl -fsSL https://app.primeintellect.ai/prime-agent/install.sh | sh - 📄 License: MIT
Related Projects
- PrimeIntellect/pi — the TUI layer underlying prime-agent
- Claude Code — one of the major coding agents prime-agent complements
- OpenHands — another autonomous software engineering agent with complementary positioning
Summary
Key Takeaways
- RLM = context as variables: subagents are function calls, tool chains are programmable, REPL is the primary interface — not conversation, but code
- Continual Harness = persistent agent state: cross-session retention of prompt supplements, memories, skills, and subagent specs
-
/refine= conservative self-improvement: small updates + snapshot rollback + immutable floor — self-improvement becomes auditable - Daemon/Worker/Kernel = long-task infrastructure: sessions decouple from terminals, crash auto-recovery, hours/days-scale task support
- Heartbeat scheduling = temporal autonomy: agent comes back to work on schedule without user supervision
Who This Is For
- Engineers running long AI-driven tasks: large refactors, batch test generation, multi-file doc sync — without rebuilding context each time
- AI researchers: evaluation pipelines, experiment automation; daemon mode keeps tasks running unattended
- Teams propagating AI workflows: package and share skills rather than just prompts — validated best practices, not hope-it-works patterns
- Developers curious about agent memory: prime-agent's harness is a visible, inspectable, editable persistent state — not a black-box memory system
One-Line Verdict
prime-agent's question: if an agent can accumulate experience, improve its own working methods, and remain human-auditable and controllable throughout — what does that look like?
Check out PrimeSkills — a curated marketplace of AI agents and skills that have been validated in real-world, enterprise-grade workflows. No fluff, just what actually works.
Find more useful knowledge and interesting products on my Homepage
Top comments (0)