- Let one agent call others by naming them in
delegates. - Run agents as ordered workflow steps.
model and use openai/gpt-5.4-nano, set "auto" for runtime selection, or set an explicit provider/model override when you need one.
Prerequisites
Agent-as-tool
Convert an agent into a tool that another agent can call:web_search tool name and requires a
provider/model that supports it. Use providerTools for provider-executed
tools. Use tools for local tools that your app defines.
delegates becomes an agent_<id> tool. The orchestrator decides when to call each agent based on its system prompt, and each sub-agent runs its own tool loop independently.
Name the delegates rather than building the tools yourself. Discovery loads agents/ in filename order, so a top-level getAgentsAsTools() in orchestrator.ts runs before researcher.ts and writer.ts have registered and returns nothing. delegates resolves each agent when the run starts, so load order cannot matter. Reach for agentAsTool() or getAgentsAsTools() only where you register the agents yourself and control the order.
Invoke the orchestrator
Expose the orchestrator through an AG-UI route:researcher and writer as tools when the model decides they are needed.
Single agent-as-tool
For wrapping a single agent:Declarative delegation with delegates
Code and markdown agents can opt into orchestration by listing the exact
specialists they may call. The runtime gives the agent one agent_{id} tool
per delegate. Each scoped tool accepts { input: string } and runs the actual
delegate definition with its own model, skills, MCP servers, and tools.
delegates: [] when an agent must not delegate. invoke_agent is the
generic platform tool for dynamic agent selection. Enable it explicitly in a
direct runtime with tools: { invoke_agent: true }; hosted runtimes expose it
when generic delegation is allowed and delegates is absent. Self-delegation
and delegate ids that cannot form a valid provider tool name are rejected with
explicit diagnostics. Declare direct tools by name when using delegates;
tools: true is intentionally rejected because it would hide the agent’s
capability boundary.
Hosted nested delegation carries trusted invocation lineage from parent to
child runs. The root conversation and run stay stable, the immediate parent is
updated for each handoff, and hosted runtimes stop delegation after eight
nested levels.
Workflow-based composition
For multi-agent pipelines with explicit execution order, use workflows:createWorkflowClient() start route.
When to use which
Agent-as-tool is more flexible but harder to predict. Workflows make execution
order explicit and easier to debug.
Agent registry
All agents inagents/ are registered automatically. Access them programmatically:
Verify it worked
After wiring delegation, run a request against the orchestrator and watch the dev-server logs:- Logs show the orchestrator calling each sub-agent in order.
- The final AG-UI response contains output that could only come from the sub-agents (research output then writer output, for example).
runId events instead.