Overview
Workflows in the Microsoft Agent Framework .NET SDK enable you to build sophisticated multi-step agentic applications. Workflows orchestrate multiple processing units (executors) connected by edges, supporting patterns like sequential processing, parallel execution, conditional routing, and loops.Core Concepts
Executors
Executors are the processing units in a workflow. Each executor:- Accepts strongly-typed input
- Performs processing (calls an agent, transforms data, etc.)
- Returns strongly-typed output
- Can be stateful or stateless
Edges
Edges define the data flow between executors. They determine:- Which executors are connected
- The order of execution
- Conditional routing logic
WorkflowBuilder
WorkflowBuilder is the fluent API for constructing workflows:Creating Executors
Custom Executor Class
From Lambda Functions
UseBindAsExecutor() to create executors from lambda functions:
From Async Functions
Building Workflows
Simple Sequential Workflow
Workflow with Agents
Integrate AI agents into workflows:Streaming Workflow Events
Stream workflow events as they occur:Parallel Execution (Fan-Out/Fan-In)
Execute multiple executors in parallel:Conditional Edges
Route based on executor output:Loops
Create iterative workflows:Writer-Critic Pattern
Iterative refinement with quality gates:Checkpointing
Save and restore workflow state:Human-in-the-Loop
Pause workflow for human input:Shared State
Share state between executors:Sub-Workflows
Compose workflows hierarchically:Workflow Visualization
Generate workflow diagrams:Best Practices
Keep Executors Focused
Keep Executors Focused
Each executor should have a single, well-defined responsibility. Break complex logic into multiple executors.
Use Strong Types
Use Strong Types
Leverage .NET’s type system with
Executor<TIn, TOut> to catch errors at compile time:Handle Errors Gracefully
Handle Errors Gracefully
Implement error handling in executors:
Add Checkpoints for Long Workflows
Add Checkpoints for Long Workflows
Use checkpointing for workflows that take significant time or process critical data.
Monitor Workflow Events
Monitor Workflow Events
Subscribe to workflow events for observability:
Use Conditional Edges for Complex Routing
Use Conditional Edges for Complex Routing
Prefer conditional edges over complex executor logic for routing decisions.
Limit Loop Iterations
Limit Loop Iterations
Always include iteration limits in loops to prevent infinite execution:
Next Steps
Declarative Workflows
Define workflows using YAML
Durable Workflows
Build reliable, resumable workflows
Multi-Agent Patterns
Common agentic workflow patterns
Observability
Monitor and debug workflows