Skip to main content

EntityMemory

Struct EntityMemory 

Source
pub struct EntityMemory { /* private fields */ }
Expand description

Map of entity_name → EntityRecord keyed by namespace.

Implementations§

Source§

impl EntityMemory

Source

pub fn new( store: Arc<dyn Store<HashMap<String, EntityRecord>>>, namespace: Namespace, ) -> Self

Build an entity memory over store scoped to namespace.

Source

pub const fn namespace(&self) -> &Namespace

Borrow the bound namespace.

Source

pub async fn set_entity( &self, ctx: &ExecutionContext, entity: &str, fact: impl Into<String>, ) -> Result<()>

Insert or replace the fact for entity. last_seen is set to Utc::now(); created_at is preserved on update or set to now on first insertion.

Source

pub async fn touch(&self, ctx: &ExecutionContext, entity: &str) -> Result<bool>

Refresh last_seen for entity without changing the fact. Use when the agent re-encounters an entity in a way that re-confirms relevance (the entity was mentioned again, even if no new fact was learned). Returns Ok(false) when the entity is not present so callers can distinguish absent vs touched.

Source

pub async fn entity( &self, ctx: &ExecutionContext, entity: &str, ) -> Result<Option<String>>

Look up a single entity’s fact. The lightweight ergonomic accessor — callers needing provenance use Self::entity_record.

Source

pub async fn entity_record( &self, ctx: &ExecutionContext, entity: &str, ) -> Result<Option<EntityRecord>>

Look up a single entity’s full record (fact + timestamps).

Source

pub async fn all( &self, ctx: &ExecutionContext, ) -> Result<HashMap<String, String>>

Read the entity → fact projection over every recorded record. Use Self::all_records to retain timestamps.

Source

pub async fn all_records( &self, ctx: &ExecutionContext, ) -> Result<HashMap<String, EntityRecord>>

Read every recorded entity’s full record.

Source

pub async fn prune_older_than( &self, ctx: &ExecutionContext, ttl: Duration, ) -> Result<usize>

Drop every record whose last_seen is older than ttl ago. Returns the number of records removed so callers can log or expose pruning metrics.

Runs as a single read-modify-write under the namespace’s store key, so the prune is atomic per-thread.

Source

pub async fn remove(&self, ctx: &ExecutionContext, entity: &str) -> Result<()>

Remove a single entity. Idempotent — removing an absent entity is a no-op.

Source

pub async fn clear(&self, ctx: &ExecutionContext) -> Result<()>

Clear every entity in this namespace.

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