Skip to main content

Module context_manager

Module context_manager 

Source
Expand description

Strategy-driven context management.

A ContextManager keeps an agent’s conversation within its context window. It runs a pipeline of ContextStrategys before each model call and on overflow, offloads content to an Archive the model can read back with the retrieve_context tool, and protects pinned messages. Set it with AgentConfig::context_manager:

Structs§

Archive
Key management and content framing over a Storage for the context manager’s offloaded content (Archive).
ArchiveConfig
Archive configuration (ArchiveConfig).
ArchiveConfigBuilder
Use builder syntax to set the inputs and finish with build().
ContextManager
Manages context reduction for an agent’s conversation (ContextManager).
ContextManagerConfig
Configuration of a ContextManager (ContextManagerConfig).
ContextManagerConfigBuilder
Use builder syntax to set the inputs and finish with build().
ContextState
What a strategy sees when it runs (ContextState).
DeferConditions
When Offload::defer defers tools (DeferConditions).
DeferConditionsBuilder
Use builder syntax to set the inputs and finish with build().
DeferStrategy
A strategy that keeps tools’ input schemas out of the model’s context until the model loads them with load_tools (DeferStrategy, built with Offload::defer).
DropStrategy
Drops matching content from the context window (Offload.drop), built with Offload::drop.
EmergencyTruncateStrategy
The last-resort strategy the context manager appends: when the window still overflows after every configured strategy, it drops the oldest 20% of the messages after message 0, ignoring pins so an all-pinned overflow is still recoverable (EmergencyTruncateStrategy).
Offload
Builds the offload strategies (Offload). Each returns a strategy; chain when to set when and on what it acts.
OffloadConditions
Conditions that decide when and how an offload strategy fires (OffloadConditions).
OffloadConditionsBuilder
Use builder syntax to set the inputs and finish with build().
SummarizeConfig
Configuration of the summarize strategy (SummarizeConfig).
SummarizeConfigBuilder
Use builder syntax to set the inputs and finish with build().
SummarizeStrategy
Replaces content with a model-written summary (Offload.summarize), built with Offload::summarize. On whole messages it summarizes each contiguous run of eligible messages.
TruncateConfig
Configuration of the truncate method (TruncateConfig).
TruncateConfigBuilder
Use builder syntax to set the inputs and finish with build().
TruncateStrategy
Replaces oversized content with a preview (Offload.truncate), built with Offload::truncate. On whole messages it keeps the oldest and newest within the preview budget and elides the rest.

Enums§

ConditionValue
One condition value: a whole number, or a 'N%' share written as a string such as "70%".
ContextManagerStrategy
What AgentConfig::context_manager accepts (ContextManagerStrategy).
DeferTarget
Which tools Offload::defer defers (DeferTarget).
OffloadTarget
What an offload strategy acts on (OffloadTarget).
PreviewMode
Which part of the text a preview keeps.
StrategyEntry
A strategy or a preset name in ContextManagerConfig::strategies.
StrategyPresetName
A named strategy preset (StrategyPresetName).

Traits§

ContextStrategy
A context reduction strategy: offloads, summarizes or otherwise shrinks the conversation (ContextStrategy).