Fan-Out
Fan-out distributes multiple tasks to worker agents in parallel and collects results.
Setup
researcher := agent.New(llmClient,
agent.WithSystemPrompt("Research the given topic thoroughly."),
)
coordinator := agent.New(llmClient,
agent.WithSystemPrompt("You coordinate parallel research tasks."),
agent.WithFanOut(agent.FanOutConfig{
Name: "research",
Description: "Research multiple topics in parallel",
Agent: researcher,
MaxConcurrency: 3,
}),
)
response, _ := coordinator.Chat(ctx, "Compare AI, blockchain, and quantum computing")
How It Works
- The
FanOutConfigregisters a tool that accepts multiple tasks - When the coordinator calls the fan-out tool, all tasks run concurrently
MaxConcurrencylimits how many worker agents run at the same time- Results are collected and returned to the coordinator