The Problem
Long-running autonomous agents lose context, stall on errors, and can't adapt their own behavior. Most agent frameworks treat every session as a fresh start, forcing repeated setup and manual supervision. Prime Agent targets that gap with durable state and self-modifying behavior.
What This Does
Prime Agent is a TypeScript monorepo (910 TS files) implementing a self-improving agent built on two abstractions: Recursive Language Models (RLM) that treat context as variables, and a Continual Harness storing memories and skill definitions as durable state. The packages/agent/ directory holds the core loop (agent-loop.ts), while packages/ai/ provides provider adapters for Anthropic, OpenAI, Google, Bedrock, and Mistral.
The packages/coding-agent/ package is the production surface. It implements interactive and daemon modes, session management, and a rlm(...) subagent primitive. The /refine command reviews trajectories and applies evidence-backed updates to harness state, with rollback support via recorded snapshots. Skills are importable Python packages.
How It Is Wired
Execution starts at packages/agent/src/index.ts, which exports the agent loop. The packages/ai/src/cli.ts is the CLI entry point. Control flows through packages/coding-agent/src/core/session-manager.ts, which 91 modules import—the widest blast radius in the repo. It manages session lifecycle and routes to agent-session.ts (36 importers, in a circular dependency).
The import graph shows 938 internal modules with 2,856 edges and 22 modules in cycles. Key hubs: theme/theme.ts (121 importers), packages/ai/src/types.ts (92 importers, in a cycle), and session-manager.ts (91 importers). The cycles in types.ts and agent-session.ts mean changing shared type definitions can trigger cascading rebuilds across the monorepo.
Provider calls leave the process through packages/ai/src/providers/ adapters, which route to external APIs. The packages/ai/src/mcp/ directory handles MCP tool integration and OAuth flows.
How To Use It
git clone https://github.com/moses-y/prime-agent
cd prime-agent
npm install
npm run build
Configuration lives in packages/coding-agent/src/core/model-registry.ts for provider setup. API keys go through environment variables or the /login command at first launch. Run the agent from a project directory:
cd /path/to/project
prime-agent
The daemon mode (packages/coding-agent/src/modes/daemon/) keeps sessions alive across terminal disconnects.
Real-World Use
A developer runs Prime Agent in a long-lived research session. The agent maintains a persistent IPython kernel, spawns rlm(...) subagents for parallel file analysis, and uses /refine to update its own skill definitions based on what worked. A background daemon session continues overnight and the developer reattaches the next morning.
Code Health & Issues
Static analysis found 529 findings (164 high, 362 medium, 3 low) across 5 kinds:
- High - Oversized files -
session-manager.ts(1,847 lines),theme.ts,model-registry.ts. Changes ripple across the 91+ modules that import them. - High - Deep nesting -
session-manager.ts,auth-storage.tshit indentation depth 8; hard to follow control flow. - High - Import cycles -
packages/ai/src/types.ts,daemon-protocol.ts,agent-session-runtime.tsparticipate in circular dependencies. - High - Hub modules -
theme.ts(121 importers),types.ts(92),session-manager.ts(91). Churn here is high-blast-radius. - Medium - Branching density -
models.tshas 31 branch points over 88 lines.
CI hygiene findings: no dependency vulnerability scan in workflows, persist-credentials not disabled on checkout, and one workflow lacks job timeouts.
The Bottom Line
Solid architecture for durable, self-improving agents with good provider coverage and 493 test files. The hub modules and cycles will make large refactors expensive. Suitable for teams building long-running autonomous coding agents who can absorb the maintenance cost of the core session code.