Skip to main content

AgentId

Struct AgentId 

Source
pub struct AgentId(/* private fields */);
Expand description

Identifiant d’agent (tenant logique d’une mémoire).

Implementations§

Source§

impl AgentId

Source

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
Hide additional 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}
Source

pub fn as_str(&self) -> &str

Trait Implementations§

Source§

impl Clone for AgentId

Source§

fn clone(&self) -> AgentId

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for AgentId

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for AgentId

Source§

impl Hash for AgentId

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for AgentId

Source§

fn eq(&self, other: &AgentId) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for AgentId

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

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

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + 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: Sized + 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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