Two dominant topologies:
- Supervisor: a coordinator owns the goal and delegates to workers, each with a narrow tool set. Deterministic and easy to trace. - Handoff / swarm: agents transfer control to each other by calling a `transfer_to_x` tool. Flexible but harder to bound.
ts
const workers = {
researcher: makeAgent({ tools: [search, fetchPage], system: "Gather sources. Cite URLs." }),
analyst: makeAgent({ tools: [runSql], system: "Answer with numbers from SQL only." }),
writer: makeAgent({ tools: [], system: "Write the final brief." }),
};
async function supervisor(goal: string) {
const notes: string[] = [];
for (const name of await chooseRoute(goal)) { // e.g. ["researcher","analyst","writer"]
notes.push(await workers[name].run(goal, notes.join("\n---\n")));
}
return notes.at(-1)!;
}Multi-agent systems fail mainly through context loss at the boundary. Pass a structured handoff object (goal, findings, open questions, constraints) rather than a free-text blob, and give the whole run a single trace id.
Exercise: run a research task as one agent with all tools, then as the supervisor above. Compare token cost, latency, and answer quality — single agent wins more often than teams expect.