Expand description
Memory: manages the agent’s context.
The inference loop uses Memory to store conversation history and to
retrieve the full context for each request. This module provides two
ready-to-use implementations:
InMemoryMemory— stores all messages verbatim, never trims;WindowMemory— trims to a recent window against a budget, with pluggable token counting and trim strategies.
Compaction, retrieval, persistence and similar strategies plug in by
implementing Memory (or injecting a TrimStrategy into
WindowMemory) without touching the inference loop. A built-in
summarization strategy is provided as SummarizeStrategy.
Structs§
- Budget
- Window budget: token and round limits (both optional; when both are set, the smaller window wins).
- Char
Token Counter - Default counter: CJK characters count as 1 token each, other characters count as 1 token per 4 characters (rounded up).
- InMemory
Memory - In-memory implementation: stores all messages verbatim.
- Summarize
Strategy - Summarization trim strategy: over-budget old messages → summarizer → one System summary message.
- Trim
Result - Output of a trim strategy: the trimmed message sequence + how the result is handled.
- Window
Drop - Default trim strategy: drops the earliest complete rounds until the remaining sequence fits the budget.
- Window
Memory - Window memory: stores all messages;
context()trims to the budget on retrieval.
Enums§
- Memory
Error - Context access failed.
Traits§
- Memory
- Manages the agent’s context: decides which messages the model sees on each turn.
- Token
Counter - Counts the token number of a text.
- Trim
Strategy - Trim strategy: decides “how to trim” — window dropping, summarization, LLM compaction, etc. Users can inject custom implementations.