State-driven transitions pattern.
Enables dynamic transfer of control between agent processes.
A handoff tool is added to an agent's tools list. When the LLM
invokes it, the agent's tool loop returns a {:handoff, target, context}
tuple to the caller, who can then redirect future messages.
Summary
Functions
Delivers a context to the target agent, which adopts it and returns to idle.
Builds one handoff tool per target agent.
Produces a trimmed context suitable for the receiving agent.
Types
Functions
@spec run(pid() | atom(), ExAgent.Context.t()) :: :ok
Delivers a context to the target agent, which adopts it and returns to idle.
This is the pattern's entry point, named run/2 like every other pattern.
Unlike the others it returns :ok rather than a result: the work here is the
transfer itself.
@spec tools([spec()]) :: [ExAgent.Tool.t()]
Builds one handoff tool per target agent.
Each tool is named handoff_to_<name> and takes a "summary" argument the
model fills in before transferring.
Handoff.tools([
%{name: "billing", agent: billing_agent, description: "Transfer billing questions"},
%{name: "tech", agent: tech_agent, description: "Transfer technical problems"}
])
@spec transfer_context(ExAgent.Context.t(), map()) :: ExAgent.Context.t()
Produces a trimmed context suitable for the receiving agent.
Adds a system message summarizing the handoff.