pub struct SharedWorkingMemory { /* private fields */ }Expand description
Thread-safe shared working memory for agents.
SharedWorkingMemory provides a shared context that multiple agents can
read from and write to. It uses deep merging to combine updates with
existing state, preserving values that aren’t being updated.
The memory is thread-safe and can be safely cloned and shared across multiple agents and async tasks.
Implementations§
Sourcepub fn get_working_memory(&self) -> Value
pub fn get_working_memory(&self) -> Value
Get a clone of the current working memory.
Returns a snapshot of the current state. Subsequent changes to the working memory will not affect this returned value.
§Examples
use mojentic::context::SharedWorkingMemory;
use serde_json::json;
let memory = SharedWorkingMemory::new(json!({"count": 1}));
let snapshot = memory.get_working_memory();
assert_eq!(snapshot["count"], 1);Sourcepub fn merge_to_working_memory(&self, new_memory: Value)
pub fn merge_to_working_memory(&self, new_memory: Value)
Merge new values into the working memory.
Performs a deep merge of the provided value with the existing memory. For objects, this recursively merges nested fields. For arrays and primitives, the new value replaces the old value.
§Arguments
new_memory- The JSON value to merge into the working memory
§Examples
use mojentic::context::SharedWorkingMemory;
use serde_json::json;
let memory = SharedWorkingMemory::new(json!({
"user": {
"name": "Charlie",
"age": 25
}
}));
memory.merge_to_working_memory(json!({
"user": {
"age": 26,
"city": "NYC"
}
}));
let result = memory.get_working_memory();
assert_eq!(result["user"]["name"], "Charlie"); // Preserved
assert_eq!(result["user"]["age"], 26); // Updated
assert_eq!(result["user"]["city"], "NYC"); // AddedTrait Implementations§
Source§fn clone(&self) -> SharedWorkingMemory
fn clone(&self) -> SharedWorkingMemory
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
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