Skip to main content

CoreMemory

Trait CoreMemory 

Source
pub trait CoreMemory: Send + Sync {
    // Required methods
    fn blocks(
        &self,
    ) -> impl Future<Output = Result<Vec<CoreMemoryBlock>>> + Send;
    fn put_block(
        &self,
        block: CoreMemoryBlock,
    ) -> impl Future<Output = Result<()>> + Send;
    fn append_block(
        &self,
        label: &str,
        text: &str,
    ) -> impl Future<Output = Result<()>> + Send;
    fn remove_block(
        &self,
        label: &str,
    ) -> impl Future<Output = Result<bool>> + Send;

    // Provided methods
    fn get_block(
        &self,
        label: &str,
    ) -> impl Future<Output = Result<Option<CoreMemoryBlock>>> + Send { ... }
    fn render(&self) -> impl Future<Output = Result<String>> + Send { ... }
}
Expand description

Trait for always-in-context core memory backends.

Core memory is distinct from Memory: it is not a chronological log, it is a small set of labeled blocks that are rendered as a whole and re-injected into the system prompt every turn. The agent itself (via a tool) or the host application can read and edit blocks between turns.

Required Methods§

Source

fn blocks(&self) -> impl Future<Output = Result<Vec<CoreMemoryBlock>>> + Send

Returns all blocks currently stored.

Source

fn put_block( &self, block: CoreMemoryBlock, ) -> impl Future<Output = Result<()>> + Send

Creates a block (if block.label is new) or overwrites the value and limit of an existing one. Fails if block.value exceeds block.limit.

Source

fn append_block( &self, label: &str, text: &str, ) -> impl Future<Output = Result<()>> + Send

Appends text to an existing block’s value (creating an unbounded block first if label is unknown). Fails without modifying the block if the result would exceed the block’s limit.

Source

fn remove_block(&self, label: &str) -> impl Future<Output = Result<bool>> + Send

Removes a block. Returns true if it existed.

Provided Methods§

Source

fn get_block( &self, label: &str, ) -> impl Future<Output = Result<Option<CoreMemoryBlock>>> + Send

Returns a single block by label, if it exists.

Source

fn render(&self) -> impl Future<Output = Result<String>> + Send

Renders all blocks into a single string suitable for splicing into a system prompt. Default rendering is "## {label}\n{value}" per block, joined by blank lines, in the order returned by blocks.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§