rune-chain-core 0.1.1

Core traits and types for the rune-chain LLM orchestration framework
Documentation
use async_trait::async_trait;

use crate::{ChainError, Message};

/// Persistent conversation history attached to a [`Chain`](crate::Chain).
///
/// A memory implementation stores and retrieves [`Message`] turns so that
/// subsequent chain calls have access to prior context. Implementations may
/// keep history in process memory, a database, or a vector store.
///
/// # Example
///
/// ```rust,ignore
/// use rune_chain_core::{Memory, Message};
///
/// memory.add(Message::human("What is 2 + 2?")).await?;
/// memory.add(Message::ai("4")).await?;
///
/// let history = memory.messages().await?;
/// assert_eq!(history.len(), 2);
/// ```
#[async_trait]
pub trait Memory: Sync + Send {
    /// Return all messages currently stored in this memory.
    async fn messages(&self) -> Result<Vec<Message>, ChainError>;

    /// Append a single message to the stored history.
    async fn add(&self, message: Message) -> Result<(), ChainError>;

    /// Clear all stored messages, resetting the conversation to zero turns.
    async fn clear(&self) -> Result<(), ChainError>;
}