Skip to main content

Module agent_loop

Module agent_loop 

Source
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

  1. Observe — score memories with MemoryGardener, detect knowledge gaps with GapDetector.
  2. Decide — prioritise actions: urgent prunes first, then merges, archives, then acquisition suggestions. Capped at max_actions_per_cycle.
  3. Act — return the decided actions as a CycleResult. The agent does NOT apply DB changes itself; MCP handlers optionally apply them.
  4. Update state — increment cycle counter and action totals.

§Invariants

  • The agent starts in a stopped state (running = false).
  • tick() may be called regardless of running state; callers decide.
  • AgentMetrics.uptime_secs is 0 until start() is called.
  • All timestamps in AgentState are RFC3339 UTC strings.
  • No unwrap() in production paths.

Structs§

AgentConfig
Configuration for the memory agent.
AgentMetrics
Performance and health metrics for the agent.
AgentState
Live state of the memory agent.
CycleResult
The result of one observe→decide→act cycle.
MemoryAgent
Autonomous memory management agent.

Enums§

AgentAction
A single action decided by the agent during one cycle.