agentTool, handoff, and forkAgentTool let the model decide when another agent takes part in a run. To decide the control flow in your own code, see Agents in workflows.
Sub-agents and handoffs
agentTool runs another agent as a tool. handoff transfers the run to another agent:
agentTool:- The sub-agent receives the task as a new conversation, together with the parent’s
context. Its answer becomes the tool result, and its token usage counts toward the parent’s usage. - Its progress events reach the parent as
tool-progressevents, and its approval requests reach the parent’sonApprovalhandlers. The sub-agent’s ownonHumanApprovaland guardrails apply to its tool calls, not the parent’s. - A sub-agent that stops at a limit returns a tool error with the code
agent_stoppedand its summary as the message. An interrupted sub-agent returns acancelledresult. - Pass
background: trueto let the parent continue while the sub-agent runs.
- The sub-agent receives the task as a new conversation, together with the parent’s
handoff:- After the current tool calls finish, the target agent’s model, instructions, and tools take over the steps of the same run and its history. Tools that you passed to
runstay available. - The agent that started the run keeps its output schema, limits,
beforeRun,beforeSteering, andafterRun, and its models for summaries of the context and of a stopped run. ItsbeforeStep,beforeTool, andafterToolkeep running together with the target’s. - The
onApprovalhandlers of both agents receive approval requests, and the target’sonHumanApprovaldecides them if the target sets one. - The handoff takes effect only if its tool call succeeds, so a
beforeToolrejection keeps the current agent. A step can hand off once: the run rejects a batch with two handoffs before any of its calls run.
- After the current tool calls finish, the target agent’s model, instructions, and tools take over the steps of the same run and its history. Tools that you passed to
Forks
forkAgentTool starts a copy of the running agent for one task. Unlike a sub-agent, a fork starts with the conversation so far:
- The fork copies the run’s history, agent, instructions, policies, limits, and tools as of the step that called the tool. The provider can serve the shared part of the request from its prompt cache.
- The fork skips
beforeRunandafterRun. Use the parent’sbeforeToolandafterToolhooks to check the fork’s task and reply. - Only the fork’s plain-text reply returns to the parent. Its tool calls stay out of the parent’s history.
- A fork can’t start forks or sub-agents. Such a call returns an error with the code
fork_nested. maxConcurrent(default 6) limits how many forks of one fork tool run at once in a run. A call over the limit returns an error with the codefork_limit.
agentTool for a specialist with its own model, instructions, or tools, or for work that needs a clean context.
Sub-agents and forks run in the parent’s invocation, so their steps add to the parent’s journal. For long, independent work, run the agent in its own service, and let the model call it as a Restate service tool or call it from your code as a worker service.