Expand description
Conversation memory and context management. Memory management module for conversation context and user memory.
This module provides utilities for:
- Building agent context with memory
- Formatting memory for LLM prompts
- Managing conversation history windows
User memory facts and preferences are stored in the database (TursoClient). This module provides utilities for working with that stored memory.
Constants§
- DEFAULT_
HISTORY_ WINDOW - Default number of recent messages to include in context.
- MAX_
FACTS_ IN_ PROMPT - Maximum number of facts to include in a prompt to avoid token overflow.
- MAX_
PREFERENCES_ IN_ PROMPT - Maximum number of preferences to include in a prompt.
Functions§
- build_
context - Builds an agent context from components.
- estimate_
tokens - Estimates token count for a message (rough approximation).
- filter_
facts_ by_ category - Filters memory facts by category.
- filter_
preferences_ by_ category - Filters preferences by category.
- format_
memory_ for_ prompt - Formats user memory into a string suitable for inclusion in system prompts.
- format_
preferences_ compact - Formats user preferences into a compact string for prompt inclusion.
- truncate_
history - Truncates conversation history to a window of recent messages.
- truncate_
history_ to_ tokens - Truncates history to fit within a token budget.