Skip to main content

AgentContext

Struct AgentContext 

Source
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:

FileLabelWhat
SOUL.mdSoulWho the agent is: values, boundaries, tone
IDENTITY.mdIdentityName, role, stack, domain
MANIFESTO.mdManifestoDev principles, harness engineering
RULES.mdRulesCoding rules, workflow, constraints
MEMORY.mdMemoryCross-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).

PriorityFileScope
1AGENTS.md / CLAUDE.md / .claude/CLAUDE.mdProject instructions (git)
2AGENTS.local.md / CLAUDE.local.mdLocal instructions (gitignored)
3.agents/rules/*.md / .claude/rules/*.mdRules 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

Source

pub fn load(home_dir: &str) -> Self

Load context from an agent home directory (SOUL, IDENTITY, MANIFESTO, etc.).

Source

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.

Source

pub fn merge(&mut self, other: Self)

Merge another context into this one (appends parts).

Source

pub fn is_empty(&self) -> bool

Whether any context was found.

Source

pub fn to_system_message(&self) -> Option<String>

Combine all parts into a single string for system message injection.

Source

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):

  1. Memory (learned) — tentative entries already GC’d
  2. context/* extras
  3. Manifesto
  4. Rules, Identity, Project/Local Instructions
  5. Soul, Memory (user notes) — never dropped

Trait Implementations§

Source§

impl Debug for AgentContext

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for AgentContext

Source§

fn default() -> AgentContext

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.