pub struct MemoryAgent {
pub config: AgentConfig,
pub state: AgentState,
/* private fields */
}Expand description
Autonomous memory management agent.
Call MemoryAgent::tick at the desired cadence to run one full
observe→decide→act cycle. The agent tracks its own state between calls.
Fields§
§config: AgentConfigCurrent configuration (mutable via MemoryAgent::configure).
state: AgentStateLive operational state.
Implementations§
Source§impl MemoryAgent
impl MemoryAgent
Sourcepub fn new(config: AgentConfig) -> Self
pub fn new(config: AgentConfig) -> Self
Create a new agent with the given configuration.
The agent starts in a stopped state (running = false).
Sourcepub fn start(&mut self)
pub fn start(&mut self)
Mark the agent as running and record the start time for uptime tracking.
Sourcepub fn is_running(&self) -> bool
pub fn is_running(&self) -> bool
Returns true if the agent has been started and not yet stopped.
Sourcepub fn tick(&mut self, conn: &Connection) -> Result<CycleResult>
pub fn tick(&mut self, conn: &Connection) -> Result<CycleResult>
Execute one observe→decide→act cycle.
§Phase 1 — Observe
- Run
MemoryGardenerin dry-run mode to score memories and identify prune / merge / archive candidates. - Run
GapDetectorto surface knowledge gaps and acquisition hints.
§Phase 2 — Decide
Actions are prioritised as:
- Urgent prunes (garden score critically low)
- Merge candidates
- Archive candidates
- Garden run (if
should_garden()) - Acquisition suggestions from gap analysis
The total is capped at config.max_actions_per_cycle.
§Phase 3 — Act
The actions list is returned. No DB writes are made by this method. The caller (MCP handler) decides whether to apply them.
§State Update
AgentState.cycles is incremented and timestamps are refreshed.
Sourcepub fn should_garden(&self) -> bool
pub fn should_garden(&self) -> bool
Returns true if enough time has passed since the last garden run to
justify running another one.
- If the garden has never run, returns
true. - Otherwise, returns
trueonly ifgarden_interval_secsseconds have elapsed sincestate.last_garden_at.
Sourcepub fn metrics(&self) -> AgentMetrics
pub fn metrics(&self) -> AgentMetrics
Compute current performance metrics from accumulated state.
Sourcepub fn configure(&mut self, new_config: AgentConfig)
pub fn configure(&mut self, new_config: AgentConfig)
Replace the current configuration.
Changes take effect on the next call to tick().
Sourcepub fn status(&self) -> AgentState
pub fn status(&self) -> AgentState
Return a snapshot of the current agent state.
Auto Trait Implementations§
impl Freeze for MemoryAgent
impl RefUnwindSafe for MemoryAgent
impl Send for MemoryAgent
impl Sync for MemoryAgent
impl Unpin for MemoryAgent
impl UnsafeUnpin for MemoryAgent
impl UnwindSafe for MemoryAgent
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more