Module shared_working_memory

Module shared_working_memory 

Source
Expand description

Shared working memory for agent communication.

This module provides SharedWorkingMemory, a thread-safe shared context that agents can read from and write to. It enables agents to maintain and share state across interactions.

§Examples

use mojentic::context::SharedWorkingMemory;
use serde_json::json;

let memory = SharedWorkingMemory::new(json!({
    "user": {
        "name": "Alice",
        "age": 30
    }
}));

let current = memory.get_working_memory();
assert_eq!(current["user"]["name"], "Alice");

memory.merge_to_working_memory(json!({
    "user": {
        "age": 31,
        "city": "Boston"
    }
}));

let updated = memory.get_working_memory();
assert_eq!(updated["user"]["age"], 31);
assert_eq!(updated["user"]["city"], "Boston");
assert_eq!(updated["user"]["name"], "Alice"); // Original value preserved

Structs§

SharedWorkingMemory
Thread-safe shared working memory for agents.