pub struct AgentId(/* private fields */);Expand description
Identifiant d’agent (tenant logique d’une mémoire).
Implementations§
Source§impl AgentId
impl AgentId
Sourcepub fn new(id: impl Into<String>) -> Option<Self>
pub fn new(id: impl Into<String>) -> Option<Self>
Construit un AgentId. Vide => None (un agent valide est requis).
Examples found in repository?
examples/llm_consolidation.rs (line 54)
52async fn main() -> Result<(), Box<dyn std::error::Error>> {
53 let store = Store::open_in_memory().await?;
54 let agent = AgentId::new("consolidation-demo").expect("non-empty id");
55 let memory = Memory::open(store, Box::new(FakeEmbedder), agent).await?;
56
57 // Store a raw episode (what happened).
58 memory
59 .remember(
60 "Alice attended a conference in Paris, the capital of France.",
61 MemoryLayer::Episodic,
62 )
63 .await?;
64
65 // Consolidate: extract facts + populate graph via FakeLlm.
66 let report = consolidate(&memory, &FakeLlm).await?;
67 println!(
68 "Consolidation: {} episode(s) seen, {} fact(s) added, {} entity(ies) upserted, {} relation(s).",
69 report.episodes_seen, report.facts_added, report.entities_upserted, report.relations_upserted,
70 );
71
72 // The extracted fact should now be searchable in semantic layer.
73 let facts = memory
74 .recall_by_layer("What is the capital of France?", MemoryLayer::Semantic, 5)
75 .await?;
76 println!("\nSemantic facts after consolidation ({}):", facts.len());
77 for f in &facts {
78 println!(" • {}", f.text);
79 }
80
81 Ok(())
82}More examples
examples/temporal_replacement.rs (line 45)
43async fn main() -> Result<(), Box<dyn std::error::Error>> {
44 let store = Store::open_in_memory().await?;
45 let agent = AgentId::new("temporal-demo").expect("non-empty id");
46 let memory = Memory::open(store, Box::new(DemoEmbedder), agent).await?;
47
48 let old_id = memory
49 .remember("The user is on the Free billing plan.", MemoryLayer::Semantic)
50 .await?;
51
52 println!("Initially remembered: Free plan ({old_id})");
53
54 memory.invalidate(&old_id).await?;
55 let new_id = memory
56 .remember("The user is on the Pro billing plan.", MemoryLayer::Semantic)
57 .await?;
58
59 println!("Invalidated old fact and remembered: Pro plan ({new_id})");
60
61 let hits = memory.recall_hybrid("current billing plan", 5).await?;
62 println!("\nRecall for `current billing plan`:");
63 for hit in &hits {
64 println!(" [{layer}] {text}", layer = hit.layer.table(), text = hit.text);
65 }
66
67 assert!(
68 hits.iter().any(|r| r.text.contains("Pro billing plan")),
69 "the current fact should be recalled"
70 );
71 assert!(
72 hits.iter().all(|r| !r.text.contains("Free billing plan")),
73 "the invalidated fact should not be recalled"
74 );
75
76 Ok(())
77}examples/memory_basic.rs (line 31)
29async fn main() -> Result<(), Box<dyn std::error::Error>> {
30 let store = Store::open_in_memory().await?;
31 let agent = AgentId::new("demo-agent").expect("non-empty id");
32 let memory = Memory::open(store, Box::new(FakeEmbedder), agent).await?;
33
34 memory
35 .remember("The Eiffel Tower is in Paris.", MemoryLayer::Semantic)
36 .await?;
37 memory
38 .remember("Paris is the capital of France.", MemoryLayer::Semantic)
39 .await?;
40 memory.remember("Bonjour!", MemoryLayer::ShortTerm).await?;
41
42 println!("=== recall (top 2) ===");
43 let results = memory.recall("What city is the Eiffel Tower in?", 2).await?;
44 for r in &results {
45 println!(
46 " [{layer}] {score:.3} {text}",
47 layer = r.layer.table(),
48 score = r.score,
49 text = r.text
50 );
51 }
52
53 let first_id = results[0].id.clone();
54 memory.invalidate(&first_id).await?;
55 println!("\nInvalidated id={first_id}");
56
57 let after = memory.recall("Eiffel Tower", 5).await?;
58 println!("Recall after invalidation: {} result(s)", after.len());
59
60 let stats = memory.stats().await?;
61 println!(
62 "\nStats: {} semantic, {} short-term (valid).",
63 stats.semantic, stats.short_term
64 );
65
66 Ok(())
67}pub fn as_str(&self) -> &str
Trait Implementations§
impl Eq for AgentId
impl StructuralPartialEq for AgentId
Auto Trait Implementations§
impl Freeze for AgentId
impl RefUnwindSafe for AgentId
impl Send for AgentId
impl Sync for AgentId
impl Unpin for AgentId
impl UnsafeUnpin for AgentId
impl UnwindSafe for AgentId
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
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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>
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 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>
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