Skip to main content

MemoryAgent

Struct MemoryAgent 

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

Current configuration (mutable via MemoryAgent::configure).

§state: AgentState

Live operational state.

Implementations§

Source§

impl MemoryAgent

Source

pub fn new(config: AgentConfig) -> Self

Create a new agent with the given configuration. The agent starts in a stopped state (running = false).

Source

pub fn start(&mut self)

Mark the agent as running and record the start time for uptime tracking.

Source

pub fn stop(&mut self)

Mark the agent as stopped. The accumulated state is preserved.

Source

pub fn is_running(&self) -> bool

Returns true if the agent has been started and not yet stopped.

Source

pub fn tick(&mut self, conn: &Connection) -> Result<CycleResult>

Execute one observe→decide→act cycle.

§Phase 1 — Observe
  • Run MemoryGardener in dry-run mode to score memories and identify prune / merge / archive candidates.
  • Run GapDetector to surface knowledge gaps and acquisition hints.
§Phase 2 — Decide

Actions are prioritised as:

  1. Urgent prunes (garden score critically low)
  2. Merge candidates
  3. Archive candidates
  4. Garden run (if should_garden())
  5. 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.

Source

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 true only if garden_interval_secs seconds have elapsed since state.last_garden_at.
Source

pub fn metrics(&self) -> AgentMetrics

Compute current performance metrics from accumulated state.

Source

pub fn configure(&mut self, new_config: AgentConfig)

Replace the current configuration.

Changes take effect on the next call to tick().

Source

pub fn status(&self) -> AgentState

Return a snapshot of the current agent state.

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<Unshared, Shared> IntoShared<Shared> for Unshared
where Shared: FromUnshared<Unshared>,

Source§

fn into_shared(self) -> Shared

Creates a shared type from an unshared type.
Source§

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

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more