pub struct WorkingMemory { /* private fields */ }Expand description
A bounded, key-value working memory for transient agent state.
When capacity is exceeded, the oldest entry (by insertion order) is evicted.
§Guarantees
- Thread-safe via
Arc<Mutex<_>> - Bounded: never exceeds
capacityentries - Deterministic eviction: LRU (oldest insertion first)
Implementations§
Source§impl WorkingMemory
impl WorkingMemory
Sourcepub fn new(capacity: usize) -> Result<Self, AgentRuntimeError>
pub fn new(capacity: usize) -> Result<Self, AgentRuntimeError>
Create a new WorkingMemory with the given capacity.
§Returns
Ok(WorkingMemory)— on successErr(AgentRuntimeError::Memory)— ifcapacity == 0
Sourcepub fn set(
&self,
key: impl Into<String> + Debug,
value: impl Into<String> + Debug,
) -> Result<(), AgentRuntimeError>
pub fn set( &self, key: impl Into<String> + Debug, value: impl Into<String> + Debug, ) -> Result<(), AgentRuntimeError>
Insert or update a key-value pair, evicting the oldest entry if over capacity.
Sourcepub fn clear(&self) -> Result<(), AgentRuntimeError>
pub fn clear(&self) -> Result<(), AgentRuntimeError>
Remove all entries from working memory.
Sourcepub fn len(&self) -> Result<usize, AgentRuntimeError>
pub fn len(&self) -> Result<usize, AgentRuntimeError>
Return the current number of entries.
Sourcepub fn is_empty(&self) -> Result<bool, AgentRuntimeError>
pub fn is_empty(&self) -> Result<bool, AgentRuntimeError>
Return true if no entries are stored.
Trait Implementations§
Source§impl Clone for WorkingMemory
impl Clone for WorkingMemory
Source§fn clone(&self) -> WorkingMemory
fn clone(&self) -> WorkingMemory
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§
impl Freeze for WorkingMemory
impl RefUnwindSafe for WorkingMemory
impl Send for WorkingMemory
impl Sync for WorkingMemory
impl Unpin for WorkingMemory
impl UnsafeUnpin for WorkingMemory
impl UnwindSafe for WorkingMemory
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