WithName. The main agent sees each specialist as a delegation tool the LLM can invoke.
When delegation fires, the runtime determines how it runs:
- Temporal — the specialist runs as a child workflow on its task queue.
- Restate — the specialist is an independent agent (own
AgentLoopservice and listen port); the parent invokes that service and stream events fan in to the parent’s event log. - Local runtime — it executes in-process.
Setup
Build each specialist withNewAgent, then register it on the main agent:
Sub-agent names must differ from the root. Use clear
WithName and WithDescription values — they appear in the delegation tool schema the LLM sees for routing decisions.
Each delegation is a tool round on the main agent — it consumes one iteration from
WithMaxIterations. An orchestrator that delegates twice and then generates a final answer uses at least 3 iterations. With the default of 5, headroom is tight. Increase WithMaxIterations on the main agent to match your expected delegation depth: a good starting point is 2 × expected delegations + 2.Behavior
- Conversation isolation — sub-agents do not inherit the main agent’s conversation ID. They run without session history from the parent.
- Independent approval policies — parent and child policies are independent (see Approvals).
- Worker pairing — with
DisableLocalWorker, pair eachNewAgentWorkerwith the same options as theNewAgentit runs. - Validation at build — sub-agent graphs are validated for cycles and depth violations at
NewAgent. Errors fail fast.
Streaming and STEP events
Subscribe once on the main agent — sub-agent events fan in to the same channel. When the specialist actually runs, the parent stream emitsSTEP_STARTED and STEP_FINISHED events with StepName set to the specialist’s WithName value. STEP_FINISHED fires whether the child run succeeded or failed.
Tool events, approval requests, and RUN_FINISHED from each level all appear on the main stream. See Streaming for the full event reference and approval handling patterns.
Dynamic registration
Add or remove specialists from a running agent viaa.SubAgentRegistry() — the next call picks up the updated set with no restart:
Example
Sub-agents
Orchestrator delegating to a math specialist
Related
A2A
Remote agents over the A2A protocol
Approvals
Parent vs specialist approval policies