mirror of
https://github.com/microsoft/agent-framework.git
synced 2026-06-16 21:04:09 +08:00
..
2026-01-26 08:21:02 -08:00
2026-01-26 08:21:02 -08:00
2026-01-26 08:21:02 -08:00
2026-01-26 08:21:02 -08:00
2026-01-26 08:21:02 -08:00
Fan-out/Fan-in Workflow with AI Agents
This sample demonstrates the Fan-out/Fan-in pattern using real AI agents in a durable workflow. A question is sent to multiple AI "expert" agents in parallel, and their responses are aggregated into a final result.
Overview
The sample implements an expert consultation workflow using Azure OpenAI:
- A question is parsed and prepared
- The question is sent to 2 AI agents in parallel (Fan-out)
- AI agent responses are collected and aggregated (Fan-in)
Components
| Component | Type | Description |
|---|---|---|
| ParseQuestion | Executor | Validates and formats the incoming question |
| Physicist | AI Agent | Azure OpenAI agent with physics expertise |
| Chemist | AI Agent | Azure OpenAI agent with chemistry expertise |
| Aggregator | Executor | Combines all AI agent responses |
Workflow Pattern
???????????????????
? ParseQuestion ?
???????????????????
?
???????????????????????????????
? ?
? ?
??????????????????? ???????????????????
? Physicist ? ? Chemist ?
? (AI Agent) ? ? (AI Agent) ?
??????????????????? ???????????????????
? ?
? PARALLEL EXECUTION ?
? ?
???????????????????????????????
?
?
???????????????????
? Aggregator ?
???????????????????
Key Concepts Demonstrated
- Fan-out (AddFanOutEdge): One executor sends to multiple AI agents in parallel
- Fan-in (AddFanInEdge): Multiple AI agent results are collected into an array
- AI Agents in Workflows: Using Azure OpenAI agents as workflow executors
- Durability: If interrupted, completed AI agent responses are preserved on restart
Configuration
When using AI agents in durable workflows, ConfigureDurableWorkflows automatically registers any AI agents found in the workflow. You only need a single configuration call:
services.ConfigureDurableWorkflows(
options => options.Workflows.AddWorkflow(expertReview),
workerBuilder: builder => builder.UseDurableTaskScheduler(dtsConnectionString),
clientBuilder: builder => builder.UseDurableTaskScheduler(dtsConnectionString));
This is similar to how ConfigureDurableOptions works in Azure Functions samples.
Environment Setup
This sample requires:
- Durable Task Scheduler - See the parent README for setup instructions
- Azure OpenAI - You need an Azure OpenAI resource with a deployed model
Environment Variables
| Variable | Description |
|---|---|
DURABLE_TASK_SCHEDULER_CONNECTION_STRING |
Connection string for DTS (defaults to local emulator) |
AZURE_OPENAI_ENDPOINT |
Your Azure OpenAI endpoint URL |
AZURE_OPENAI_DEPLOYMENT |
Name of your deployed model (e.g., gpt-4) |
AZURE_OPENAI_KEY |
(Optional) API key - if not set, uses Azure CLI credential |
Running the Sample
cd dotnet/samples/DurableAgents/ConsoleApps/09_Workflow_Concurrency
dotnet run --framework net10.0
Sample Session
??????????????????????????????????????????????????????????????????????
? Fan-out/Fan-in Workflow with AI Agents ?
??????????????????????????????????????????????????????????????????????
? This sample demonstrates parallel AI agent consultation. ?
? ?
? Workflow: Question ? [Physicist, Chemist] ? Aggregator ?
? (AI agents run in parallel) ?
??????????????????????????????????????????????????????????????????????
?? TIP: Stop during execution to test durability - completed agent responses are preserved!
? Checking for pending workflows...
Enter a science question (or 'exit' to quit):
Example: "What is water?"
Question: What is water
Starting expert review workflow...
Instance ID: abc123-def456-...
???????????????????????????????????????????????????????????????????
? [ParseQuestion] Preparing question for AI agents...
? [ParseQuestion] Question: "What is water?"
? [ParseQuestion] ? Sending to Physicist and Chemist in PARALLEL...
???????????????????????????????????????????????????????????????????
... (AI agents process in parallel)
???????????????????????????????????????????????????????????????????
? [Aggregator] ?? Received 2 AI agent responses
? [Aggregator] Combining into comprehensive answer...
? [Aggregator] ? Aggregation complete!
???????????????????????????????????????????????????????????????????
??????????????????????????????????????????????????????????????????????
? ? Expert review completed! ?
??????????????????????????????????????????????????????????????????????
???????????????????????????????????????????????????????????????
AI EXPERT PANEL RESPONSES
???????????????????????????????????????????????????????????????
?? PHYSICIST:
Water is H2O - two hydrogen atoms bonded to one oxygen atom. From a physics
perspective, water exhibits unique properties like high specific heat capacity
and surface tension due to hydrogen bonding.
?? CHEMIST:
Water (H2O) is a polar molecule formed by covalent bonds. Its bent molecular
geometry creates a dipole moment, making it an excellent solvent for ionic
and polar compounds.
???????????????????????????????????????????????????????????????
Summary: Received perspectives from 2 AI experts.
???????????????????????????????????????????????????????????????
Durability with AI Agents
If you stop the application while one AI agent is processing:
- The completed agent's response is preserved (cached by Durable Task)
- On restart, only the incomplete agent re-runs
- The aggregator waits for all agents to complete
Related Samples
- 08_SingleWorkflow - Sequential workflow with durability demonstration
- 10_WorkflowConcurrent - Azure Functions version
- 02_AgentOrchestration_Chaining - Agent chaining with durable orchestration