pub struct AgentContext {
pub parts: Vec<(String, String)>,
}Expand description
Agent context — layered memory system compatible with Claude Code.
§Two loading modes
§1. Agent home dir (load)
Each agent has a home dir (e.g. .my-agent/).
Inside it, markdown files provide agent-specific context:
| File | Label | What |
|---|---|---|
SOUL.md | Soul | Who the agent is: values, boundaries, tone |
IDENTITY.md | Identity | Name, role, stack, domain |
MANIFESTO.md | Manifesto | Dev principles, harness engineering |
RULES.md | Rules | Coding rules, workflow, constraints |
MEMORY.md | Memory | Cross-session learnings, preferences |
context/*.md | (filename) | User-extensible extras |
§2. Project dir (load_project) — Claude Code compatible
Loads project-level instructions from standard locations.
Prefers AGENTS.md (generic) with fallback to CLAUDE.md (Claude Code compat).
| Priority | File | Scope |
|---|---|---|
| 1 | AGENTS.md / CLAUDE.md / .claude/CLAUDE.md | Project instructions (git) |
| 2 | AGENTS.local.md / CLAUDE.local.md | Local instructions (gitignored) |
| 3 | .agents/rules/*.md / .claude/rules/*.md | Rules by topic |
All files are optional. Missing files are silently skipped.
Fields§
§parts: Vec<(String, String)>Combined context text for system message injection.
Implementations§
Source§impl AgentContext
impl AgentContext
Sourcepub fn load(home_dir: &str) -> Self
pub fn load(home_dir: &str) -> Self
Load context from an agent home directory (SOUL, IDENTITY, MANIFESTO, etc.).
Sourcepub fn load_project(project_dir: &Path) -> Self
pub fn load_project(project_dir: &Path) -> Self
Load project-level context (AGENTS.md/CLAUDE.md + rules).
Claude Code compatible: falls back to CLAUDE.md if AGENTS.md not found.
Sourcepub fn to_system_message(&self) -> Option<String>
pub fn to_system_message(&self) -> Option<String>
Combine all parts into a single string for system message injection.
Sourcepub fn to_system_message_with_budget(&self, max_tokens: usize) -> Option<String>
pub fn to_system_message_with_budget(&self, max_tokens: usize) -> Option<String>
Combine parts with a token budget (chars/4 estimate).
Priority order (lowest dropped first):
- Memory (learned) — tentative entries already GC’d
- context/* extras
- Manifesto
- Rules, Identity, Project/Local Instructions
- Soul, Memory (user notes) — never dropped