Multi-agent
Multi-agent
Subagents
Give an agent another agent as a tool:
researcher := crux.Must(crux.New("researcher", crux.ClaudeHaiku4_5,
crux.WithInstructions("Find facts and cite sources."),
crux.WithWebSearch()))
lead := crux.Must(crux.New("lead", crux.ClaudeSonnet5_5,
crux.WithSubAgent(researcher, "Researches a question on the web")))- The parent sees a tool named
agent_<name>(hereagent_researcher) that takes{"task": "..."}. - Each call runs in its own child session. The child’s final output (shaped by its output schema, if it has one) is the tool result.
- Approvals the child needs surface on the parent’s
PendingApprovals, withcall.Agentset to the child’s name;ApproveandResumeon the parent. - Entry handlers (
WithEntryHandler) and the store are shared with children. crux.WithoutSubagents()removes them.
Spawning agents
Let the model create agents on the fly:
lead := crux.Must(crux.New("lead", crux.ClaudeSonnet5_5,
crux.WithTools([]string{"search_docs", "read_ticket"}),
crux.WithAgentSpawning(
crux.WithSpawnModels(crux.ClaudeHaiku4_5, crux.ClaudeSonnet5_5),
crux.WithSpawnMaxTurns(5),
crux.WithSpawnConcurrency(4))))- Adds a
spawn_agenttool: the model picks a name, instructions, a task and, within your limits, tools and a model. - Defaults come from the parent: its tools (
WithSpawnTools/WithSpawnToolsRegistrynarrow them), its model, its turn limit. - Spawned agents can’t spawn, have no output schema, and run like subagents (approvals surface on the parent).