pub struct CoreMemory { /* private fields */ }Expand description
Core memory - always in LLM context.
TigerStyle:
- Fixed capacity (~32KB)
- One block per type (type-indexed)
- Deterministic render order
- Explicit size tracking
§Example
use umi_memory::memory::{CoreMemory, MemoryBlockType};
let mut core = CoreMemory::new();
core.set_block(MemoryBlockType::System, "You are helpful.").unwrap();
core.set_block(MemoryBlockType::Human, "User: Alice").unwrap();
assert!(core.used_bytes() > 0);
let context = core.render();
assert!(context.contains("You are helpful."));Implementations§
Source§impl CoreMemory
impl CoreMemory
Sourcepub fn with_config(config: CoreMemoryConfig) -> Self
pub fn with_config(config: CoreMemoryConfig) -> Self
Create a new core memory with custom configuration.
Sourcepub fn set_clock_ms(&mut self, ms: u64)
pub fn set_clock_ms(&mut self, ms: u64)
Set the internal clock (for DST).
TigerStyle: Explicit time control for simulation.
Sourcepub fn set_block(
&mut self,
block_type: MemoryBlockType,
content: impl Into<String>,
) -> Result<MemoryBlockId, CoreMemoryError>
pub fn set_block( &mut self, block_type: MemoryBlockType, content: impl Into<String>, ) -> Result<MemoryBlockId, CoreMemoryError>
Set a block by type.
If a block of this type already exists, it is replaced. The old block’s size is reclaimed.
§Errors
Returns error if the content is too large or would exceed capacity.
Sourcepub fn set_block_with_label(
&mut self,
block_type: MemoryBlockType,
label: impl Into<String>,
content: impl Into<String>,
) -> Result<MemoryBlockId, CoreMemoryError>
pub fn set_block_with_label( &mut self, block_type: MemoryBlockType, label: impl Into<String>, content: impl Into<String>, ) -> Result<MemoryBlockId, CoreMemoryError>
Set a block with a label.
§Errors
Returns error if content/label too large or would exceed capacity.
Sourcepub fn get_block(&self, block_type: MemoryBlockType) -> Option<&MemoryBlock>
pub fn get_block(&self, block_type: MemoryBlockType) -> Option<&MemoryBlock>
Get a block by type.
Sourcepub fn get_content(&self, block_type: MemoryBlockType) -> Option<&str>
pub fn get_content(&self, block_type: MemoryBlockType) -> Option<&str>
Get block content by type.
Sourcepub fn has_block(&self, block_type: MemoryBlockType) -> bool
pub fn has_block(&self, block_type: MemoryBlockType) -> bool
Check if a block type exists.
Sourcepub fn remove_block(
&mut self,
block_type: MemoryBlockType,
) -> Result<MemoryBlock, CoreMemoryError>
pub fn remove_block( &mut self, block_type: MemoryBlockType, ) -> Result<MemoryBlock, CoreMemoryError>
Sourcepub fn block_count(&self) -> usize
pub fn block_count(&self) -> usize
Get the number of blocks.
Sourcepub fn used_bytes(&self) -> usize
pub fn used_bytes(&self) -> usize
Get used bytes.
Sourcepub fn available_bytes(&self) -> usize
pub fn available_bytes(&self) -> usize
Get available bytes.
Sourcepub fn utilization(&self) -> f64
pub fn utilization(&self) -> f64
Get utilization as a fraction (0.0 to 1.0).
Sourcepub fn blocks_ordered(&self) -> impl Iterator<Item = &MemoryBlock>
pub fn blocks_ordered(&self) -> impl Iterator<Item = &MemoryBlock>
Iterate over blocks in render order.
TigerStyle: Deterministic ordering by block type priority.
Sourcepub fn render(&self) -> String
pub fn render(&self) -> String
Render core memory as XML for LLM context.
TigerStyle: Deterministic, predictable output format.
§Example Output
<core_memory>
<block type="system">
You are a helpful assistant.
</block>
<block type="human">
User prefers concise responses.
</block>
</core_memory>Sourcepub fn config(&self) -> &CoreMemoryConfig
pub fn config(&self) -> &CoreMemoryConfig
Get configuration.