pub struct EntityMemory { /* private fields */ }Expand description
Map of entity_name → EntityRecord keyed by namespace.
Implementations§
Source§impl EntityMemory
impl EntityMemory
Sourcepub fn new(
store: Arc<dyn Store<HashMap<String, EntityRecord>>>,
namespace: Namespace,
) -> Self
pub fn new( store: Arc<dyn Store<HashMap<String, EntityRecord>>>, namespace: Namespace, ) -> Self
Build an entity memory over store scoped to namespace.
Sourcepub async fn set_entity(
&self,
ctx: &ExecutionContext,
entity: &str,
fact: impl Into<String>,
) -> Result<()>
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.
Sourcepub async fn touch(&self, ctx: &ExecutionContext, entity: &str) -> Result<bool>
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.
Sourcepub async fn entity(
&self,
ctx: &ExecutionContext,
entity: &str,
) -> Result<Option<String>>
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.
Sourcepub async fn entity_record(
&self,
ctx: &ExecutionContext,
entity: &str,
) -> Result<Option<EntityRecord>>
pub async fn entity_record( &self, ctx: &ExecutionContext, entity: &str, ) -> Result<Option<EntityRecord>>
Look up a single entity’s full record (fact + timestamps).
Sourcepub async fn all(
&self,
ctx: &ExecutionContext,
) -> Result<HashMap<String, String>>
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.
Sourcepub async fn all_records(
&self,
ctx: &ExecutionContext,
) -> Result<HashMap<String, EntityRecord>>
pub async fn all_records( &self, ctx: &ExecutionContext, ) -> Result<HashMap<String, EntityRecord>>
Read every recorded entity’s full record.
Sourcepub async fn prune_older_than(
&self,
ctx: &ExecutionContext,
ttl: Duration,
) -> Result<usize>
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.
Sourcepub async fn remove(&self, ctx: &ExecutionContext, entity: &str) -> Result<()>
pub async fn remove(&self, ctx: &ExecutionContext, entity: &str) -> Result<()>
Remove a single entity. Idempotent — removing an absent entity is a no-op.
Sourcepub async fn clear(&self, ctx: &ExecutionContext) -> Result<()>
pub async fn clear(&self, ctx: &ExecutionContext) -> Result<()>
Clear every entity in this namespace.