Tool Call Compression

Compress tool call history to reduce context size.

Tool Call Compression.

1"""
2Tool Call Compression
3=============================
4
5Tool Call Compression.
6"""
7
8from kern.agent import Agent
9from kern.db.sqlite import SqliteDb
10from kern.models.openai import OpenAIResponses
11from kern.tools.websearch import WebSearchTools
12
13# ---------------------------------------------------------------------------
14# Create Agent
15# ---------------------------------------------------------------------------
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 compression
23)
24
25# ---------------------------------------------------------------------------
26# Run Agent
27# ---------------------------------------------------------------------------
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:
33
34 1. OpenAI - product launches, partnerships, pricing
35 2. Anthropic - new features, enterprise deals, funding
36 3. Google DeepMind - research breakthroughs, product releases
37 4. Meta AI - open source releases, research papers
38
39 For each, find specific actions with dates and numbers.""",
40 stream=True,
41 )

Run the Example

1# Clone and setup repo
2git clone https://github.com/kern-ai/kern.git
3cd kern/cookbook/02_agents/14_advanced
4
5# Create and activate virtual environment
6./scripts/demo_setup.sh
7source .venvs/demo/bin/activate
8
9python tool_call_compression.py