Skip to main content
context_management.py
The clear_tool_uses_20250919 edit activates once the prompt contains more than two tool use/result pairs. It keeps the newest pair and clears older tool results. By default, Anthropic keeps the original tool-call inputs. Set clear_tool_inputs=True in the edit only when those inputs can also be removed. Context editing runs on Anthropic’s server before the request reaches Claude. The SQLite database stores Agno’s session and run history independently of those server-side edits. Clearing content can invalidate the affected prompt-cache prefix. Thinking blocks require a separate clear_thinking_20251015 edit. When both strategies are used, list the thinking edit first. Context-edit metrics are finalized at the end of a response, including a streamed response. See Anthropic’s context-editing documentation for strategy defaults and additional fields.

Run the Example

1

Set up your virtual environment

2

Install dependencies

3

Set your API key

4

Save and run

Save the example as context_management.py, then run: