Skip to main content

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

Use ConcurrentBuilder 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, use add_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
Switch-case evaluates cases in order. The first matching condition routes the message. Always include a Default case.

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

  • 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
  • Always include a Default case in switch-case routing
  • Set max_iterations to prevent infinite loops
  • Add error handling in executors to gracefully handle failures
  • Use type hints for better error detection
  • 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
  • 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