Overview
Microsoft Agent Framework provides multiple orchestration patterns for coordinating agents and executors. Choose the pattern that best fits your use case:- Sequential: Process steps in order, one after another
- Concurrent: Run multiple agents/executors in parallel
- Conditional: Route based on message content or state
- Loops: Iterate until a condition is met
- Complex graphs: Combine patterns for sophisticated workflows
Sequential Orchestration
Sequential workflows execute executors in a linear pipeline, where each step processes the output of the previous step.Concurrent Orchestration
Concurrent workflows fan out work to multiple executors in parallel, then aggregate results.High-Level API
UseConcurrentBuilder for agent-based concurrent workflows:
Custom Aggregation
Define custom aggregation logic for concurrent results:Python
Low-Level Fan-Out/Fan-In
For custom concurrent patterns, useadd_fan_out_edge and add_fan_in_edge:
Python
Conditional Routing
Route messages to different executors based on conditions.Conditional Edges
Python
Switch-Case Routing
For mutually exclusive routing (exactly one target):Python
Loop Patterns
Create feedback loops for iterative refinement.Simple Loop
Python
Agent Feedback Loop
Real-world example with agents:Python
Complex Graph Patterns
Combine patterns for sophisticated orchestration.Multi-Stage Pipeline with Fan-Out
Python
Conditional Fan-Out with Dynamic Routing
Python
Decision Tree Pattern
Python
Streaming and Events
Monitor orchestration progress in real-time:Python
Best Practices
Choose the Right Pattern
Choose the Right Pattern
- Use sequential for linear pipelines where order matters
- Use concurrent when tasks are independent and can run in parallel
- Use conditional when routing depends on message content
- Use loops for iterative refinement with feedback
Handle Edge Cases
Handle Edge Cases
- Always include a
Defaultcase in switch-case routing - Set
max_iterationsto prevent infinite loops - Add error handling in executors to gracefully handle failures
- Use type hints for better error detection
Optimize for Performance
Optimize for Performance
- Use concurrent execution when possible (parallelism)
- Minimize state size - only store what’s needed
- Use selective fan-out to reduce unnecessary work
- Stream results for long-running workflows
Design for Observability
Design for Observability
- Use descriptive executor IDs
- Log important state transitions
- Monitor workflow events for debugging
- Use structured data for messages
Next Steps
Checkpoints
Save and restore workflow state for fault tolerance
Human-in-the-Loop
Integrate human decision points into workflows