Intermediate~14 minHazelJS
Parallel Fan-Out / Fan-In
Run independent branches concurrently with AgentGraph parallel nodes, then merge.
- Authors
- editorial-team
- Published
- Last reviewed
Problem
Independent subtasks run serially and waste latency budget.
Context
Research, multi-source fetch, or shardable analysis with a reduce/merge stage.
Forces and constraints
- Latency budgets favor concurrency
- Merge/reduce must handle partial failures
- Budgets multiply across branches
Recommended design
Use AgentGraph addNode with type: 'parallel' and branches, then a merge node. Cap per-branch maxSteps/budgets. Do not invent Flow callAgent fan-out—use documented AgentGraph parallel nodes.
Minimal pseudocode
const g = createGraph();
g.addNode('fanout', {
type: 'parallel',
branches: [docsAgent, codeAgent, ticketsAgent],
});
g.addNode('merge', mergeAgent);
g.addEdge('fanout', 'merge');Failure modes
- Unbounded parallel branches blow cost
- Merge assumes all branches succeeded
- Shared mutable state across branches
Security considerations
- Per-branch ToolRegistry isolation
Observability signals
- Per-branch executionId linkage
- merge latency
Evaluation approach
Partial-failure fixtures; cost ceiling across fan-out.
Trade-offs
- Complexity vs serial simplicity