New in v2.x: Chain multiple filters with
input_filter=[filter1, filter2] and use compress_history to reduce token usage.Overview
Handoff filters let you control what context is passed when one agent hands off to another. This helps:- Reduce token usage by removing unnecessary messages
- Focus context on relevant information
- Protect privacy by filtering sensitive data
Quick Start
1
Single filter
2
Chain filters
Available Filters
compress_history
Compresses all messages into a single summary message. Great for reducing token usage.remove_all_tools
Removes all tool-related messages (tool calls and tool results).keep_last_n_messages
Keeps only the last N messages.remove_system_messages
Removes all system messages from the history.Filter Chaining
How It Works
The user asks the coordinator; on handoff the input filters run in order to trim the history before the target agent receives it.Custom Filters
Create your own filter function:API Reference
HandoffInputData
The data structure passed to filter functions:Filter Function Signature
Examples
Token-Efficient Handoff
Token-Efficient Handoff
Privacy-Aware Handoff
Privacy-Aware Handoff
Focus on Recent Context
Focus on Recent Context
Best Practices
Compress history before large handoffs
Compress history before large handoffs
Passing a full conversation to a specialist wastes tokens on context it doesn’t need. Use
handoff_filters.compress_history (or a custom trim) so the receiving agent gets a focused brief, not the entire transcript.Strip tool calls the next agent can't use
Strip tool calls the next agent can't use
Tool-call messages from the source agent are noise to a specialist with different tools. Filter them out (
remove_tools) so the receiving model reasons over content, not stale tool invocations it will never repeat.Redact sensitive data at the boundary
Redact sensitive data at the boundary
Handoffs are the natural place to drop secrets, PII, or credentials before another agent sees them. Add a redaction filter to the chain so sensitive fields never cross into an agent that doesn’t need them.
Chain filters in order of intent
Chain filters in order of intent
Filters compose left to right, each receiving the previous filter’s output. Order them so structural cuts (remove tools) run before compression, and redaction runs last, so nothing sensitive slips through a later transform.
Related
Handoffs
Agent-to-agent delegation
Agent as Tool
Use agents as callable tools
Context Policies
Control context sharing across agents
Handoff Tool Policy
Secure tool boundaries during handoff

