Skip to main content

Module memory

Module memory 

Source
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.