Memory
ARES provides conversation memory and user context management for maintaining state across agent interactions.
Features
- Sliding window over conversation history (
DEFAULT_HISTORY_WINDOW = 10) - Token-budget-aware history truncation
- User memory formatting (facts, preferences) for system prompts
- Integration with Eruka for persistent cross-session context
Core Functions
History Management
#![allow(unused)] fn main() { use ares::memory::{truncate_history, truncate_history_to_tokens}; // Keep last N messages let recent = truncate_history(&messages, 10); // Keep messages within a token budget let within_budget = truncate_history_to_tokens(&messages, 4096); }
Context Building
#![allow(unused)] fn main() { use ares::memory::{build_context, format_memory_for_prompt}; // Format user memory (facts + preferences) into a system prompt section let memory_text = format_memory_for_prompt(&user_memory); // Build full context with history window and memory injection let context = build_context(&user_memory, &history, window_size); }
Filtering
#![allow(unused)] fn main() { use ares::memory::{filter_facts_by_category, filter_preferences_by_category}; // Filter facts by category (e.g., "health", "technical") let health_facts = filter_facts_by_category(&facts, "health"); // Filter preferences similarly let prefs = filter_preferences_by_category(&preferences, "communication"); }
Constants
| Constant | Value | Purpose |
|---|---|---|
DEFAULT_HISTORY_WINDOW | 10 | Default number of messages to keep |
MAX_FACTS_IN_PROMPT | 20 | Max facts injected into system prompt |
MAX_PREFERENCES_IN_PROMPT | 10 | Max preferences injected |
Token Estimation
#![allow(unused)] fn main() { use ares::memory::estimate_tokens; let tokens = estimate_tokens("Hello, how are you?"); // Rough estimate: ~5 tokens (word count * 1.3) }
Eruka Integration
When ARES is paired with Eruka (via the ContextProvider trait), the memory flow becomes:
- On session start,
ContextProvider::get_context()fetches user state from Eruka - Facts and preferences are formatted and injected into the agent system prompt
- After exchanges, agent signals (emotional state, topics, preferences) are written back to Eruka
- Next session starts with updated context — agents remember users across conversations