Context Manager • AI Agent SDK

ContextManager: Unified facade for context management.

ContextManager

Defined in the manager module.

AI Agent

Unified facade for context management.

Orchestrates budgeting, composition, optimization, and monitoring. Provides hooks for exact LLM boundary snapshots. Tracks optimization history for debugging.

Constructor

ParamField str

No description available.

ParamField Optional[ManagerConfig]

No description available.

ParamField str

No description available.

ParamField str

No description available.

ParamField Optional[SessionDeduplicationCache]

No description available.

ParamField Optional[Callable]

No description available.

Methods

Usage

python
manager = ContextManager(model="gpt-4o")

    # Process messages before LLM call
    result = manager.process(
        messages=messages,
        system_prompt=system_prompt,
        tools=tools,
    )

    # Get optimized messages
    optimized_messages = result["messages"]

    # Check if optimization occurred
    if result["optimized"]:
        print(f"Saved {result['tokens_saved']} tokens")

Source

View on GitHub

praisonaiagents/context/manager.py at line 225


Related Documentation