Tool Call Compression
Compress tool call history to reduce context size.
Tool Call Compression.
1"""2Tool Call Compression3=============================45Tool Call Compression.6"""78from kern.agent import Agent9from kern.db.sqlite import SqliteDb10from kern.models.openai import OpenAIResponses11from kern.tools.websearch import WebSearchTools1213# ---------------------------------------------------------------------------14# Create Agent15# ---------------------------------------------------------------------------16agent = Agent(17 model=OpenAIResponses(id="gpt-5-mini"),18 tools=[WebSearchTools()],19 description="Specialized in tracking competitor activities",20 instructions="Use the search tools and always use the latest information and data.",21 db=SqliteDb(db_file="tmp/dbs/tool_call_compression.db"),22 compress_tool_results=True, # Enable tool call compression23)2425# ---------------------------------------------------------------------------26# Run Agent27# ---------------------------------------------------------------------------28if __name__ == "__main__":29 agent.print_response(30 """31 Use the search tools and always for the latest information and data.32 Research recent activities (last 3 months) for these AI companies:3334 1. OpenAI - product launches, partnerships, pricing35 2. Anthropic - new features, enterprise deals, funding36 3. Google DeepMind - research breakthroughs, product releases37 4. Meta AI - open source releases, research papers3839 For each, find specific actions with dates and numbers.""",40 stream=True,41 )Run the Example
1# Clone and setup repo2git clone https://github.com/kern-ai/kern.git3cd kern/cookbook/02_agents/14_advanced45# Create and activate virtual environment6./scripts/demo_setup.sh7source .venvs/demo/bin/activate89python tool_call_compression.py