How Prime Agent's Continual Harness and /refine Command Enable Persistent Session Capabilities
Prime Agent's Continual Harness provides a durable ledger for session state, while the /refine command enables incremental updates to that state without modifying the base system prompt, together delivering long-term memory and continuous learning across sessions.
The PrimeIntellect-ai/prime-agent repository implements a sophisticated session management system that distinguishes between immutable base prompts and mutable contextual data. By separating these concerns, Prime Agent can maintain persistent knowledge across restarts while allowing runtime refinement of skills and memories.
What is the Continual Harness?
The Continual Harness is a durable JSON ledger that stores supplemental prompts, memories, reusable skill descriptions, sub-agent specifications, and refinement events. According to the source code in packages/coding-agent/docs/rlm-runtime.md, this state persists as harness/harness_state.json within the session's artifact directory, with support for global entries under ~/.prime/agent/harness/.
During runtime, the base system prompt remains immutable. The Harness supplies additional context that is merged into the prompt dynamically. This architecture ensures that:
- Sessions can be resumed with accumulated knowledge intact
- Context evolves without rewriting the original prompt
- State changes are tracked independently of core system instructions
How the /refine Command Works
The /refine command triggers a dedicated review of the current trajectory, creating granular updates to the Harness state. As implemented in packages/coding-agent/src/core/refinement/refinement.ts, this mechanism records before/after snapshots for rollback capabilities while keeping the original prompt unchanged.
When you invoke /refine, the system:
- Analyzes the current session trajectory
- Creates, updates, or deletes small Harness state entries (e.g., new memories or skills)
- Persists change logs for auditability
- Injects the updated context into subsequent turns
This supplemental approach means refinements are additive—the base system prompt remains static while the session gains new capabilities.
Technical Implementation and Code Examples
The Harness state management is exposed through the handleRefineHostRequest method, allowing programmatic interaction with the refinement system.
To capture a lesson or insight from the current conversation:
await harness.session.handleRefineHostRequest(
"refine.run",
{ instructions: "Summarize the key takeaway from this conversation" }
);
To inspect the current Harness state directly:
const harnessState = await harness.session.handleRefineHostRequest(
"refine.status"
);
console.log("Current Harness entries:", harnessState.entries);
To add reusable skills that persist across sessions:
await harness.session.handleRefineHostRequest(
"refine.run",
{
instructions: `
Add a new skill named "summarize_code" that:
- Takes a code snippet as input
- Returns a concise summary
`
}
);
The system prompt integration is validated in packages/coding-agent/test/system-prompt.test.ts, which confirms that every session includes a # Continual Harness State section, ensuring the Harness is automatically injected into the agent's context.
Benefits for Session Management
Together, these components provide two critical capabilities for long-running agent deployments:
- Session-level continuity: State survives process restarts and system reboots through JSON persistence in both local artifact directories and global configuration paths.
- Incremental learning: Small, evidence-backed updates can be added on the fly without redeployment, allowing the agent to build on past interactions and evolve its toolset organically.
This architecture enables Prime Agent to function as a continuously learning system rather than a stateless request processor.
Summary
- The Continual Harness stores session data, skills, and memories as JSON in
harness/harness_state.jsonand~/.prime/agent/harness/. - The
/refinecommand updates Harness entries without modifying the immutable base system prompt. - Session context is merged at runtime, enabling persistent knowledge across restarts.
- The
handleRefineHostRequestAPI supports programmatic refinement and state inspection. - All Harness updates maintain before/after snapshots for rollback safety.
Frequently Asked Questions
What data types does the Continual Harness store?
The Harness stores supplemental prompts, episodic memories, reusable skill descriptions, sub-agent specifications, and refinement event logs. This data persists as structured JSON, enabling both human-readable inspection and programmatic access.
How does /refine differ from editing the system prompt directly?
The /refine command creates supplemental updates to the Harness state while leaving the base system prompt immutable. This separation allows for iterative refinements and rollbacks without risking corruption of the core agent instructions, whereas direct prompt editing would require full redeployment and risk losing previous context.
Can I access the Harness state from multiple sessions?
Yes. The Harness supports both session-local storage (harness/harness_state.json within the artifact directory) and global storage (~/.prime/agent/harness/). Global entries are accessible across all sessions, while local entries maintain session-specific context.
Is there a way to undo a refinement?
Yes. The refinement system records before/after snapshots of the Harness state during each /refine operation. These snapshots enable rollback capabilities, allowing you to revert to previous states if a refinement introduces unwanted behavior or incorrect information.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →