Workflow:Microsoft Autogen Graph Based Agent Orchestration
| Knowledge Sources | |
|---|---|
| Domains | Multi_Agent_Systems, LLM_Orchestration, Workflow_Automation, DAG_Execution |
| Last Updated | 2026-02-11 18:00 GMT |
Overview
End-to-end process for orchestrating agents through a directed graph (DAG) that defines sequential, parallel, conditional, and cyclic execution patterns using the GraphFlow team and DiGraphBuilder API.
Description
This workflow demonstrates how to build complex multi-agent pipelines using GraphFlow and DiGraphBuilder. Unlike simple round-robin or selector patterns, graph-based orchestration lets you define precise control flow between agents: sequential chains, parallel fan-outs, conditional branches based on message content, and iterative loops with exit conditions.
The process covers constructing a directed graph of agents using the fluent builder API, defining edge conditions for branching logic, configuring message filtering for agents in loops, and executing the graph as a team. This is the most flexible orchestration pattern in AutoGen, suitable for complex business processes.
Usage
Execute this workflow when your multi-agent process requires structured control flow beyond simple turn-taking. Typical scenarios include:
- Multi-stage pipelines where some stages run in parallel and merge results
- Conditional routing where agent output determines the next processing path
- Iterative refinement loops where agents review and revise each other's work until a quality threshold is met
- Complex business workflows with branching, merging, and conditional logic
You need fine-grained control over which agents run, in what order, and under what conditions.
Execution Steps
Step 1: Design the Agent Graph
Plan the execution topology by identifying the agents involved and the flow of control between them. Determine which patterns are needed: sequential chains, parallel execution, conditional branches, or iterative loops.
Key patterns:
- Sequential: A produces output, then B processes it, then C finalizes
- Parallel: A produces output, then B and C process it simultaneously
- Conditional: A produces output, and either B or C processes it based on content
- Cyclic: A and B iterate in a loop until an exit condition is met
Step 2: Create Agent Instances
Instantiate each agent that participates in the graph. For agents in iterative loops, consider wrapping them with MessageFilterAgent to control which messages they see on each iteration, preventing context explosion from accumulated message history.
Key considerations:
- Each agent must have a unique name matching the graph node identifier
- Use MessageFilterAgent with PerSourceFilter to limit history (e.g., keep only the last message from each source)
- Agents in parallel branches execute concurrently on the same message thread
Step 3: Build the Graph with DiGraphBuilder
Use the DiGraphBuilder fluent API to construct the directed graph. Add agents as nodes, connect them with edges, and optionally attach conditions to edges for branching logic.
What happens:
- add_node registers an agent as a graph vertex with an activation mode ("all" or "any")
- add_edge connects two nodes with an optional condition (string match or callable)
- set_entry_point designates the starting node
- build validates the graph structure and returns a DiGraph object
Condition types:
- String conditions activate when the text appears in the agent's output
- Callable conditions receive the message and return a boolean
Step 4: Configure Graph Execution Parameters
Wrap the graph in a GraphFlow team with optional termination conditions and turn limits. The GraphFlow manages DAG execution, tracking which agents are ready based on completed dependencies.
Key considerations:
- Activation mode "all" waits for all parent edges before activating a node
- Activation mode "any" activates when any single parent edge fires
- Cycles must have at least one conditional exit edge to prevent infinite loops
- max_turns provides a safety limit on total execution steps
Step 5: Execute the Graph Workflow
Submit a task to the GraphFlow team. The execution engine processes the graph topologically, running ready agents, evaluating edge conditions, and advancing the frontier until no more agents are ready or a termination condition fires.
Execution flow:
- Start nodes (no incoming edges or entry point) execute first
- After each agent completes, its outgoing edge conditions are evaluated
- Satisfied edges add target nodes to the ready queue
- Multiple ready nodes execute in parallel
- The process continues until the ready queue is empty
Step 6: Collect and Interpret Results
Consume the output stream or blocking result. The TaskResult contains the full message thread from all agents that executed, preserving the order of execution. Inspect which branches were taken and which conditions fired.
Output includes:
- Messages from each agent that executed in the graph
- Event data including speaker selection events showing the execution order
- The termination reason (natural graph completion, condition, or turn limit)