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:
ContextManagerStrategy::Autotruncates tool results over 1,500 tokens and summarizes at 85% context utilization;ContextManagerStrategy::Agenticlets the model manage its context with thesummarize_context,truncate_contextandpin_contexttools and shows it its usage;ContextManagerConfigbuilds a custom pipeline fromOffloadstrategies andStrategyPresetNamepresets.
Structs§
- Archive
- Key management and content framing over a
Storagefor the context manager’s offloaded content (Archive). - Archive
Config - Archive configuration (
ArchiveConfig). - Archive
Config Builder - Use builder syntax to set the inputs and finish with
build(). - Context
Manager - Manages context reduction for an agent’s conversation (
ContextManager). - Context
Manager Config - Configuration of a
ContextManager(ContextManagerConfig). - Context
Manager Config Builder - Use builder syntax to set the inputs and finish with
build(). - Context
State - What a strategy sees when it runs (
ContextState). - Defer
Conditions - When
Offload::deferdefers tools (DeferConditions). - Defer
Conditions Builder - Use builder syntax to set the inputs and finish with
build(). - Defer
Strategy - A strategy that keeps tools’ input schemas out of the model’s context until the model loads
them with
load_tools(DeferStrategy, built withOffload::defer). - Drop
Strategy - Drops matching content from the context window (
Offload.drop), built withOffload::drop. - Emergency
Truncate Strategy - 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; chainwhento set when and on what it acts. - Offload
Conditions - Conditions that decide when and how an offload strategy fires (
OffloadConditions). - Offload
Conditions Builder - Use builder syntax to set the inputs and finish with
build(). - Summarize
Config - Configuration of the summarize strategy (
SummarizeConfig). - Summarize
Config Builder - Use builder syntax to set the inputs and finish with
build(). - Summarize
Strategy - Replaces content with a model-written summary (
Offload.summarize), built withOffload::summarize. On whole messages it summarizes each contiguous run of eligible messages. - Truncate
Config - Configuration of the truncate method (
TruncateConfig). - Truncate
Config Builder - Use builder syntax to set the inputs and finish with
build(). - Truncate
Strategy - Replaces oversized content with a preview (
Offload.truncate), built withOffload::truncate. On whole messages it keeps the oldest and newest within the preview budget and elides the rest.
Enums§
- Condition
Value - One condition value: a whole number, or a
'N%'share written as a string such as"70%". - Context
Manager Strategy - What
AgentConfig::context_manageraccepts (ContextManagerStrategy). - Defer
Target - Which tools
Offload::deferdefers (DeferTarget). - Offload
Target - What an offload strategy acts on (
OffloadTarget). - Preview
Mode - Which part of the text a preview keeps.
- Strategy
Entry - A strategy or a preset name in
ContextManagerConfig::strategies. - Strategy
Preset Name - A named strategy preset (
StrategyPresetName).
Traits§
- Context
Strategy - A context reduction strategy: offloads, summarizes or otherwise shrinks the conversation
(
ContextStrategy).