Octopus
Parallel Agent Execution
When a user request spans multiple domains, the orchestrator can invoke multiple specialist agents simultaneously and merge their results into a single coherent response. This is the fan-out/fan-in pattern for multi-agent systems.
When to Use Parallel Execution
Parallel execution is appropriate when:
- A single user request genuinely requires two or more independent domains (e.g., "What are my leave balance and my current expense report status?")
- The sub-questions are independent — one agent's result does not depend on another's
- Latency matters — sequential calls would be noticeably slower
Parallel execution should not be used when one specialist's output feeds into another's input — use sequential handoff in that case.
Parallel Execution API
public class ParallelAgentExecutor
{
public async Task<ParallelAgentResult> ExecuteAsync(
IReadOnlyList<ParallelAgentRequest> requests,
ConversationComposite conversation,
CancellationToken ct = default)
{
// Fan out: invoke all specialist agents concurrently
var tasks = requests.Select(req => _agentExecutor.ExecuteAsync(
agent: await _agentRepo.GetCompositeAsync(req.AgentId, conversation.TenantId),
conversation: conversation,
newMessage: req.FocusedPrompt,
ct: ct));
var results = await Task.WhenAll(tasks);
// Fan in: merge results
return new ParallelAgentResult
{
AgentResponses = requests.Zip(results).Select((pair, _) => new AgentResponse
{
AgentId = pair.First.AgentId,
Content = pair.Second.Content,
ToolCalls = pair.Second.ToolCalls
}).ToList()
};
}
}
Response Merging
After parallel execution, the orchestrator merges results. Three merging strategies are supported:
| Strategy | How | When to Use |
|---|---|---|
| Concatenation | Join responses with section headers | Independent answers that don't need synthesis |
| LLM Synthesis | Pass all results to orchestrator LLM to write a unified answer | When responses need to be coherently combined |
| Template Merge | Fill a response template with values from each agent | Structured outputs (tables, summaries) |
// LLM Synthesis merge
var synthesisPrompt = $"""
The user asked: "{userMessage}"
Here are the specialist responses:
HR Agent: {hrResult.Content}
Finance Agent: {financeResult.Content}
Write a single, clear response that incorporates both answers.
""";
var merged = await _orchestratorLLM.CompleteAsync(
new[] { new LLMMessage(Role.User, synthesisPrompt) },
tools: null, options: orchestratorOptions);
Cost Consideration
Parallel execution multiplies your LLM call cost — invoking 3 agents in parallel costs 3x the token cost of a single call. Budget this carefully. Use parallel execution only when the response quality improvement justifies the cost.