context.window_manager
Context window manager.
Orchestrates summarization, eviction, and history archiving for long-running durable agents. Hooks into the message processing pipeline before each model request.
ContextWindowManager Objects
class ContextWindowManager()
Manage the context window for long-running durable agents.
Coordinates auto-summarization, tool output eviction, and history archiving. Designed to be used as a pre-processing step before each model request.
Parameters
config : ContextWindowConfig Configuration for context management.
process_messages
async def process_messages(messages: list[dict[str, Any]],
model: str | None = None) -> list[dict[str, Any]]
Process messages before a model request.
Steps:
- Archive new messages (for history search)
- Evict large tool outputs to files
- Check token usage percentage
- If above threshold, summarize older messages
Parameters
messages : list[dict] The full message list. model : str | None The model name (for auto-detecting max_tokens).
Returns
list[dict] The processed message list (possibly with summarized older messages).
process_tool_result
def process_tool_result(tool_name: str, result: Any) -> Any
Process a tool result through the eviction system.
get_usage_info
def get_usage_info() -> dict
Return current context usage information.
get_archive
def get_archive() -> HistoryArchive | None
Return the history archive (if enabled).
from_spec
@classmethod
def from_spec(cls, spec_context: dict | None) -> "ContextWindowManager"
Create from AgentSpec context_management config.