- Wrap agents as tools with
agentAsToolorgetAgentsAsTools. - Run agents as ordered workflow steps.
model and inherit the runtime default, 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.
getAgentsAsTools() wraps each agent as a tool. The orchestrator decides when to call each agent based on its system prompt. Each sub-agent runs its own tool loop independently.
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:Workflow-based composition
For deterministic multi-agent pipelines, use workflows:createWorkflowClient() start route.
When to use which
| Pattern | Use when |
|---|---|
| Agent-as-tool | The orchestrator decides dynamically which agents to call and in what order |
| Workflow | The execution order is known in advance: sequential, parallel, or branching |
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.