Skip to main content
Handoff filters control what context passes when one agent hands off to another — reducing tokens, focusing relevance, and stripping sensitive data.
The user asks the coordinator; filtered context is passed on handoff.
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

Filters are applied in order. Put removal filters first, then compression last.

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

Best Practices

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.
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.
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.
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.

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