Expand description
Memory Agent Loop — RML-1223
Ties together proactive acquisition (RML-1221) and gardening (RML-1222) into a single observe→decide→act cycle for autonomous memory management.
§Design
The agent is not a background thread. It is a struct with a MemoryAgent::tick
method. The caller — an MCP handler or binary — is responsible for invoking
tick() at the desired interval (see check_interval_secs).
§Cycle Phases
- Observe — score memories with
MemoryGardener, detect knowledge gaps withGapDetector. - Decide — prioritise actions: urgent prunes first, then merges, archives,
then acquisition suggestions. Capped at
max_actions_per_cycle. - Act — return the decided actions as a
CycleResult. The agent does NOT apply DB changes itself; MCP handlers optionally apply them. - Update state — increment cycle counter and action totals.
§Invariants
- The agent starts in a stopped state (
running = false). tick()may be called regardless ofrunningstate; callers decide.AgentMetrics.uptime_secsis 0 untilstart()is called.- All timestamps in
AgentStateare RFC3339 UTC strings. - No
unwrap()in production paths.
Structs§
- Agent
Config - Configuration for the memory agent.
- Agent
Metrics - Performance and health metrics for the agent.
- Agent
State - Live state of the memory agent.
- Cycle
Result - The result of one observe→decide→act cycle.
- Memory
Agent - Autonomous memory management agent.
Enums§
- Agent
Action - A single action decided by the agent during one cycle.