ExAgent. Coordination
(ExAgent v3.0.0)
View Source
Orchestration patterns on top of ExAgent.Session and the core loop.
Stability — Stable.
These cover pydanticAI's complexity levels 2 and 3:
- Delegation (level 2) — an agent calls another agent as a tool. The delegate runs its own model⇄tools loop and its output is returned to the parent; the shared execution scope accounts for the delegate's usage.
- Hand-off (level 3) — a model asks a catalog destination to answer
directly with
ExAgent.Handoff. Application code can change a Session's current participant withExAgent.Session.handoff/3.
These complement — but don't replace — the BEAM-native coordination model: in ExAgent, multiple agents are usually separate supervised processes that message each other, rather than one agent calling another as a tool. Delegation is provided for parity with the pydanticAI pattern and for cases where nesting a sub-agent inside a tool is genuinely the simplest design.
ExAgent.Coordination.Composition executes and resumes trusted durable sequences.
ExAgent.Coordination.Flow adds a versioned host router and bounded parallel
fan-out/fan-in with ordered outcomes, fail-fast/collect and the same C7 approvals.
Structural roots have no Model request; leaves use the original agent loop.
Summary
Functions
Build an ExAgent.Tool that delegates a sub-task to another agent.
Types
@type phase() ::
:open | :prepare | :mapping | :select | :execute | :merge | :checkpoint
@type result() :: ExAgent.Coordination.Result.t()
@type step_result() :: %{ id: String.t(), index: non_neg_integer(), run_id: String.t() | nil, status: step_status(), input: term(), output: term(), output_name: String.t() | nil, output_omitted: map() | nil, error: portable_error() | nil, messages: [ExAgent.Message.t()] }
@type step_status() ::
:not_started | :running | :paused | :succeeded | :failed | :cancelled
Functions
Build an ExAgent.Tool that delegates a sub-task to another agent.
When the parent agent's model calls this tool, delegate is run with the
tool's prompt argument (a one-shot ExAgent.run/3) and its output is
returned to the parent. Requests/tools are admitted against every ancestor's
limits before execution and usage is reconciled in the shared ledger, including
failed delegates. The returned tool value never adds that usage a second time.
Arguments
delegate— anExAgent.t(), or a builder(ctx, args -> ExAgent.t())so the delegate can be constructed lazily with the parent's context (e.g. to forwarddepsor pick a model per call).opts—:name(default"delegate"),:description,:max_retries(default1),:prompt_arg(string, default"prompt") and:result_schemafor the delegated result. Optional:permissions,:approve,:deadline,:max_concurrent_requestsand:estimate_costconfigure child restrictions/pricing; none override an ancestor's policy or limits. Use:continuationfor the child's durable definition and bindings. Unknown or duplicate options and invalid values (including the child restrictions and the:continuationdescriptor) raiseArgumentErrorat construction, as does a delegate whose capabilities fail the guard ofExAgent.new/1. Builders only choose the child definition; a builder that returns such an agent fails the call before the child runs, like any other invalid builder result.
Example
chat_model is an explicitly configured ExAgent.Models.ReqLLM instance with
credentials and the qualified :chat_tools_v1 profile (see the README recipe).
delegate = ExAgent.new(model: chat_model, instructions: "You summarize.")
parent =
ExAgent.new(
model: chat_model,
tools: [ExAgent.Coordination.delegation_tool(delegate, name: "summarize")]
)The parent model can then call summarize(prompt: "...") to hand a sub-task
to the delegate and get its result back, with both runs' tokens counted
together.