Memory Strategies
Short-term memory strategies
Section titled “Short-term memory strategies”Short-term strategies control which messages are included in the LLM prompt.
MemoryMaxTokensStrategy
Section titled “MemoryMaxTokensStrategy”class MemoryMaxTokensStrategy(ShortTermMemoryStrategyBase): memory_strategy_id: Literal["max_tokens"] = "max_tokens" memory_max_tokens: int = 10000 conditions: list[str] = []Algorithm: Walks the conversation backwards, grouping messages by human turn (Interaction). Keeps interactions until memory_max_tokens is reached.
| Field | Type | Default | Description |
|---|---|---|---|
memory_strategy_id | "max_tokens" | required | Strategy identifier |
memory_max_tokens | int | 10000 | Token budget. -1 = include nothing |
conditions | string[] | [] | simpleeval expressions to filter interactions |
JSON example:
{ "memory_strategy_id": "max_tokens", "memory_max_tokens": 8000, "conditions": ["message.role != 'tool'"]}Long-term memory strategies
Section titled “Long-term memory strategies”Long-term strategies trigger when the conversation exceeds a threshold and either summarize or erase old context.
Shared trigger fields
Section titled “Shared trigger fields”All long-term strategies inherit these fields:
| Field | Type | Default | Description |
|---|---|---|---|
input_tokens_threshold | int | 0 | Trigger when LLM input tokens exceed this value (0 = disabled) |
interaction_keep | int | 0 | Interactions to keep after the strategy runs |
interaction_conditions | string[] | [] | Filter which interactions count toward thresholds |
interaction_threshold_qty | int | 0 | Trigger after this many interactions (0 = disabled) |
interaction_threshold_tokens | int | 0 | Trigger after this many interaction tokens (0 = disabled) |
on_tools_success_threshold | string[] | [] | Trigger when any of these tool names succeed |
on_tools_error_threshold | string[] | [] | Trigger when any of these tool names error |
SummarizerStrategy
Section titled “SummarizerStrategy”Uses Chain of Density (CoD) summarization to compress conversation history.
class SummarizerStrategy(LongTermMemoryStrategyBase): long_term_memory_id: Literal["summarizer"] = "summarizer" interaction_threshold_qty: int = 20 interaction_threshold_tokens: int = 20000 cod_max_loops: int = 5 knowledge_base: KnowledgeBases | None = None instructions: str | None = None text_splitter: TextSplitterConfig = Field(default_factory=TextSplitterConfig)Algorithm:
- Check if any trigger condition is met
- Run
cod_max_loopsiterations of CoD summarization - Optionally store the summary in a vector store (
knowledge_base) - Keep the last
interaction_keepinteractions
| Field | Type | Default | Description |
|---|---|---|---|
long_term_memory_id | "summarizer" | required | Strategy identifier |
interaction_threshold_qty | int | 20 | Trigger after N interactions |
interaction_threshold_tokens | int | 20000 | Trigger after N tokens |
cod_max_loops | int | 5 | CoD densification passes |
interaction_keep | int | 0 | Interactions to keep after summarization |
instructions | string | null | Custom summarization instructions |
knowledge_base | KnowledgeBase | null | Store summaries in a vector store |
text_splitter | TextSplitterConfig | default | Text splitting config for vector store ingestion |
JSON example:
{ "long_term_memory_id": "summarizer", "interaction_threshold_qty": 15, "interaction_threshold_tokens": 15000, "cod_max_loops": 3, "interaction_keep": 2, "instructions": "Focus on decisions made and action items.", "knowledge_base": { "collection_id": "session-memory", "search_mode": "always", "top_k": 3 }}NeuralyzerStrategy
Section titled “NeuralyzerStrategy”Erases conversation history beyond a threshold. Faster than summarization — use when historical context is not needed.
class NeuralyzerStrategy(LongTermMemoryStrategyBase): long_term_memory_id: Literal["neuralyzer"] = "neuralyzer" interaction_threshold_qty: int = -1 interaction_threshold_tokens: int = -1| Field | Type | Default | Description |
|---|---|---|---|
long_term_memory_id | "neuralyzer" | required | Strategy identifier |
interaction_threshold_qty | int | -1 | Trigger after N interactions (-1 = never) |
interaction_threshold_tokens | int | -1 | Trigger after N tokens (-1 = never) |
interaction_keep | int | 0 | Interactions to keep after erasure |
JSON example:
{ "long_term_memory_id": "neuralyzer", "interaction_threshold_qty": 30, "interaction_keep": 5}The Interaction model
Section titled “The Interaction model”Both strategies group messages into Interaction objects — one per human turn (human message + all subsequent AI/tool messages until the next human message).
This grouping ensures that related messages (a tool call and its result) are always kept or discarded together.
Related pages
Section titled “Related pages”- Memory concepts — when and why to use each strategy
- Agent Configuration — where to configure memory