tool(). The orchestrating agent calls that tool like any other, and the framework handles usage aggregation automatically.
Use sub-agents when a sub-task needs a different persona or toolset, or when the output of one stage becomes structured input for the next.
Agent delegation flow
Agent-as-tool pattern
Wrap a child agent intool(). The execute function calls the child agent and returns its output.
Usage aggregation
RunResult.usage automatically sums token usage across all nested agent calls. You do not need to track usage manually - the orchestrator’s result.usage reflects the total cost of the entire delegation chain.
Programmatic handoff
You can route to different specialist agents based on runtime conditions. Use a plain TypeScriptif/else inside tool.execute() - there is no special routing API.
When to use sub-agents
Use sub-agents when:- A sub-task requires a different system prompt (different persona, different instructions)
- A sub-task needs different tools that should not be exposed to the orchestrator
- The output of one stage becomes structured input for the next stage
- You want to reuse an agent across multiple orchestrators
- Simple single-tool operations that do not need a separate model call
- Cases where the orchestrator can solve the problem directly without specialist knowledge
API reference
There is no special multi-agent API in Vibes. Sub-agents are just agents wrapped in tools.| Symbol | Description |
|---|---|
agent.run(prompt, options?) | Run an agent and return RunResult<TOutput> |
RunResult.output | The agent’s final output |
RunResult.usage | Token usage - summed across all nested agent calls automatically |
tool({ execute }) | Wrap any async function as a tool, including agent.run() calls |