Skip to main content

ContextManager

Defined in the manager module.
Unified facade for context management. Orchestrates budgeting, composition, optimization, and monitoring. Provides hooks for exact LLM boundary snapshots. Tracks optimization history for debugging.

Constructor

model
str
default:"'gpt-4o-mini'"
No description available.
config
Optional
No description available.
session_id
str
default:"''"
No description available.
agent_name
str
default:"''"
No description available.
session_cache
Optional
No description available.
llm_summarize_fn
Optional
No description available.

Methods

Usage

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")