Handoff Tools
Utilities for creating agent-to-agent transfer tools used in multi-agent swarm patterns.
Import path: agentflow.prebuilt.tools.handoff
Handoff tools are special tools that tell an LLM it can transfer control to another agent. When the LLM calls a handoff tool, the graph routing layer intercepts the call and navigates to the target node directly — the tool function body never actually executes. This keeps the conversation history clean (no spurious tool-result messages).
create_handoff_tool
Factory function that creates a transfer_to_<agent_name> tool.
Concept
In a swarm or peer-to-peer multi-agent graph, each agent needs to know which other agents it can route to. create_handoff_tool creates one tool per target. The naming convention transfer_to_<name> is what the graph routing layer detects to perform the handoff.
Agent calls transfer_to_researcher
↓
Graph routing layer detects "transfer_to_" prefix
↓
Graph routes to the RESEARCHER node
(tool body never runs)
Signature
def create_handoff_tool(
agent_name: str,
description: str | None = None,
) -> Callable