Skip to content

Sub-agents & teams

One agent doing everything ends up with a bloated context and every dangerous tool at once. The fix is the same one every serious coding agent ships: delegate. Define a small team of scoped agents; the parent’s model calls the built-in task tool; each child runs on a fresh transcript with only its tools, and returns one final answer.

  • Context isolation. A research detour burns the child’s context, not the parent’s. The parent sees one tool message per delegation — never the child’s 40-turn transcript.
  • Least privilege. uses scopes what a child can touch. Give the explorer read-only tools and keep the writer away from bash — scoping is the security model.
  • Parallel fan-out. Multiple task calls in one turn run concurrently, and the child’s tokens/turns roll up into the parent’s usage, so one number still tells you what a run cost.
  • Budgets that actually stop things. maxTokens, maxTurns, maxWallMs… enforced live across the whole tree; a limit stop is a loud status: "incomplete", never a silent success.
import { agents } from "toolnexus"
const explore = agents.agent("explore", {
does: "read-only research",
uses: { tools: [lookup] }, // least privilege: only these tools
})
const coder = agents.agent("coder", {
does: "implements changes",
soulFile: "./AGENTS.md",
team: [explore], // team = who `task` can reach
budget: { maxTokens: 10_000 },
})
const r = await coder.run("fix the failing test", {
llm: {
baseUrl: "https://openrouter.ai/api/v1",
style: "openai",
model: "openai/gpt-4o-mini",
},
})
console.log(r.status, r.text, r.totalTokens)

That’s the whole wiring: listing an agent in team is what makes it delegable. The parent gains one built-in task { agent, prompt } tool whose description advertises only its team; an agent without a team gets no task tool at all (delegation — and recursion — are opt-in).

Full detail — suspension escalation, durable resume, budgets, and the six host verbs — in Sub-agents & teams.