Skip to content

Memory Strategies

Short-term strategies control which messages are included in the LLM prompt.

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.

FieldTypeDefaultDescription
memory_strategy_id"max_tokens"requiredStrategy identifier
memory_max_tokensint10000Token budget. -1 = include nothing
conditionsstring[][]simpleeval expressions to filter interactions

JSON example:

{
"memory_strategy_id": "max_tokens",
"memory_max_tokens": 8000,
"conditions": ["message.role != 'tool'"]
}

Long-term strategies trigger when the conversation exceeds a threshold and either summarize or erase old context.

All long-term strategies inherit these fields:

FieldTypeDefaultDescription
input_tokens_thresholdint0Trigger when LLM input tokens exceed this value (0 = disabled)
interaction_keepint0Interactions to keep after the strategy runs
interaction_conditionsstring[][]Filter which interactions count toward thresholds
interaction_threshold_qtyint0Trigger after this many interactions (0 = disabled)
interaction_threshold_tokensint0Trigger after this many interaction tokens (0 = disabled)
on_tools_success_thresholdstring[][]Trigger when any of these tool names succeed
on_tools_error_thresholdstring[][]Trigger when any of these tool names error

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:

  1. Check if any trigger condition is met
  2. Run cod_max_loops iterations of CoD summarization
  3. Optionally store the summary in a vector store (knowledge_base)
  4. Keep the last interaction_keep interactions
FieldTypeDefaultDescription
long_term_memory_id"summarizer"requiredStrategy identifier
interaction_threshold_qtyint20Trigger after N interactions
interaction_threshold_tokensint20000Trigger after N tokens
cod_max_loopsint5CoD densification passes
interaction_keepint0Interactions to keep after summarization
instructionsstringnullCustom summarization instructions
knowledge_baseKnowledgeBasenullStore summaries in a vector store
text_splitterTextSplitterConfigdefaultText 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
}
}

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
FieldTypeDefaultDescription
long_term_memory_id"neuralyzer"requiredStrategy identifier
interaction_threshold_qtyint-1Trigger after N interactions (-1 = never)
interaction_threshold_tokensint-1Trigger after N tokens (-1 = never)
interaction_keepint0Interactions to keep after erasure

JSON example:

{
"long_term_memory_id": "neuralyzer",
"interaction_threshold_qty": 30,
"interaction_keep": 5
}

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.