Skip to content

Commit 692b38d

Browse files
authored
Merge pull request #535 from Azure/maf-2-3
App Service agent framework - add parts 2 and 3
2 parents 1fc5d07 + 67889d2 commit 692b38d

File tree

5 files changed

+754
-0
lines changed

5 files changed

+754
-0
lines changed
Lines changed: 262 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,262 @@
1+
---
2+
title: "Part 2: Build Long-Running AI Agents on Azure App Service with Microsoft Agent Framework"
3+
author_name: "Jordan Selig"
4+
toc: true
5+
toc_sticky: true
6+
---
7+
8+
Last week, I shared how to [build long-running AI agents on Azure App Service with Microsoft Agent Framework](https://techcommunity.microsoft.com/blog/appsonazureblog/build-long-running-ai-agents-on-azure-app-service-with-microsoft-agent-framework/4463159). If you haven't seen that post yet, I would recommend starting there as this post builds on the foundations introduced there including getting started with [Microsoft Agent Framework](https://learn.microsoft.com/agent-framework/overview/agent-framework-overview). The response so far was great, and one comment in particular stood out:
9+
10+
> "Thanks for the example. Nice job! Just curious (I still have to investigate the ins and outs of MAF) but why didn't you use the workflow pattern/classes of MAF? I thought that was meant to be the way to connect agents and let them cooperate (even in long running job situations)."
11+
>
12+
> β€” [Michel_Schep](https://techcommunity.microsoft.com/users/michel_schep/340533)
13+
14+
Great question! You're absolutely right in questioning thisβ€”the initial sample I created was designed to demonstrate the async request-reply architecture for handling long-running operations on App Service with a single agent. Today, we're taking the next step: a multi-agent workflow sample that addresses exactly what you asked about and is the next leap in building agentic apps in the cloud.
15+
16+
In this post, we'll explore:
17+
18+
- βœ… Building multi-agent systems with specialized, collaborating AI agents
19+
- βœ… When to create agents in code vs. using Azure AI Foundry portal
20+
- βœ… Orchestrating complex workflows with parallel and sequential execution
21+
- βœ… Real-world patterns for production multi-agent applications
22+
23+
πŸ”— **Full Sample Code**: [https://github.com/Azure-Samples/app-service-maf-workflow-travel-agent-dotnet](https://github.com/Azure-Samples/app-service-maf-workflow-travel-agent-dotnet)
24+
25+
## Why Multi-Agent Systems?
26+
27+
The single-agent pattern I showed last week works great for straightforward tasks. But real-world AI applications often need specialized expertise across different domains. That's where multi-agent systems shine.
28+
29+
### The Travel Planning Challenge
30+
31+
Imagine planning a trip to Tokyo. You need:
32+
33+
- Currency expertise for budget conversion and exchange rates
34+
- Weather knowledge for packing recommendations and seasonal planning
35+
- Local insights about customs, culture, and etiquette
36+
- Itinerary skills to create day-by-day schedules
37+
- Budget optimization to allocate funds across categories
38+
- Coordination to assemble everything into a cohesive plan
39+
40+
With a single agent handling all of this, you get a "jack of all trades, master of none" situation. The prompts become complex, the agent loses focus, and results can be inconsistent.
41+
42+
### Enter Multi-Agent Workflows
43+
44+
Instead of one generalist agent, we can create 6 or more specialized agents, each with a focused responsibility:
45+
46+
1. **Currency Converter Agent** - Real-time exchange rates (Frankfurter API integration)
47+
2. **Weather Advisor Agent** - Forecasts and packing tips (National Weather Service API)
48+
3. **Local Knowledge Agent** - Cultural insights and customs
49+
4. **Itinerary Planner Agent** - Day-by-day activity scheduling
50+
5. **Budget Optimizer Agent** - Cost allocation and optimization
51+
6. **Coordinator Agent** - Final assembly and formatting
52+
53+
Each agent has:
54+
55+
- 🎯 **Clear, focused instructions** specific to its domain
56+
- πŸ› οΈ **Specialized tools** (weather API, currency API)
57+
- πŸ“Š **Defined inputs and outputs** for predictable collaboration
58+
- βœ… **Testable behavior** that's easy to validate
59+
60+
Additionally, if you wanted to extend this even further, you could create even more agents and give some of your specialist agents even more knowledge by connecting additional tools and MCP servers. The possibilities are endless, and I hope this post inspires you to start thinking about what you can build and achieve.
61+
62+
## What Makes This Possible? Microsoft Agent Framework
63+
64+
All of this is powered by [Microsoft Agent Framework](https://learn.microsoft.com/agent-framework/overview/agent-framework-overview)β€”a comprehensive platform for building, deploying, and managing AI agents that goes far beyond simple chat completions.
65+
66+
### Understanding Agent Framework vs. Other Approaches
67+
68+
Before diving into the details, it's important to understand what Agent Framework is. Unlike frameworks like Semantic Kernel where you orchestrate AI behavior entirely in your application code with direct API calls, Agent Framework provides a unified abstraction for working with AI agents across multiple backend types.
69+
70+
Agent Framework supports several agent types ([see documentation](https://learn.microsoft.com/agent-framework/user-guide/agents/agent-types/?pivots=programming-language-csharp)):
71+
72+
1. **Simple agents based on inference services** - Agents built on any IChatClient implementation, including:
73+
- Azure OpenAI ChatCompletion
74+
- Azure AI Foundry Models ChatCompletion
75+
- OpenAI ChatCompletion and Responses
76+
- Any other Microsoft.Extensions.AI.IChatClient implementation
77+
78+
2. **Server-side managed agents** - Agents that live as Azure resources:
79+
- Azure AI Foundry Agent (used in this sample)
80+
- OpenAI Assistants
81+
82+
3. **Custom agents** - Fully custom implementations of the AIAgent base class
83+
84+
4. **Proxy agents** - Connections to remote agents via protocols like A2A
85+
86+
In this sample, we use **Azure AI Foundry Agents**β€”the server-side managed agent type. When you use these Foundry agents:
87+
88+
- **Agents are Azure resources** - They exist on the server-side in Azure AI Foundry, not just as code patterns
89+
- **Execution happens on Foundry** - Agent runs execute on Azure's infrastructure with built-in state management
90+
- **You get structured primitives** - Agents, Threads, and Runs are first-class concepts with their own lifecycles
91+
- **Server-side persistence** - Conversation history and context are managed by the platform
92+
93+
This server-side approach is convenient because the platform manages state and execution for you. However, other agent types (like ChatCompletion-based agents) give you more control over orchestration while still benefiting from the unified Agent Framework programming model.
94+
95+
In my next blog post, I'll demonstrate an alternative approach using a different agent typeβ€”likely the Azure OpenAI ChatCompletion agent typeβ€”which doesn't create server-side Foundry resources. Instead, you orchestrate the agent behavior yourself while still benefiting from the Agent Framework's unified programming model.
96+
97+
If you're new to Agent Framework, here's what makes it special:
98+
99+
- πŸ”„ **Persistent Agents**: Server-side agents that maintain context across multiple interactions, not just one-off API calls
100+
- πŸ’¬ **Conversation Threads**: Organized conversation history and state management that persists across agent runs
101+
- 🎯 **Agent Runs**: Structured execution with progress tracking and lifecycle managementβ€”you can monitor exactly what your agents are doing
102+
- πŸ” **Multi-Turn Interactions**: Complex workflows with iterative AI processing, where agents can refine and improve their outputs
103+
- πŸ› οΈ **Tool Integration**: Extensible function calling and integration capabilitiesβ€”agents can call external APIs, execute code, and interact with real-world systems
104+
105+
In our sample, Agent Framework handles:
106+
107+
- Creating and managing 6 specialized agents programmatically
108+
- Maintaining conversation context as agents collaborate
109+
- Tracking execution progress across workflow phases
110+
- Managing agent lifecycle (creation, execution, cleanup)
111+
- Integrating external APIs (weather, currency) seamlessly
112+
113+
The beauty of Agent Framework is that it makes complex multi-agent orchestration feel natural. You focus on defining what your agents should do, and the framework handles the infrastructure, state management, and executionβ€”all running on Azure AI Foundry with enterprise-grade reliability.
114+
115+
## The Multi-Agent Workflow
116+
117+
Here's how these agents collaborate to create a comprehensive travel plan in the sample I put together:
118+
119+
![Multi-agent workflow diagram]({{site.baseurl}}/media/2025/11/workflow.png)
120+
121+
### Execution Phases
122+
123+
**Phase 1: Parallel Information Gathering (10-40%)**
124+
125+
- Currency, Weather, and Local Knowledge agents execute simultaneously
126+
- No dependencies = maximum performance
127+
- Results stored in workflow state for downstream agents
128+
129+
**Phase 2: Itinerary Planning (40-70%)**
130+
131+
- Itinerary Planner uses context from all Phase 1 agents
132+
- Weather data influences activity recommendations
133+
- Local knowledge shapes cultural experiences
134+
- Currency conversion informs budget-conscious choices
135+
136+
**Phase 3: Budget Optimization (70-90%)**
137+
138+
- Budget Optimizer analyzes the proposed itinerary
139+
- Allocates funds across categories (lodging, food, activities, transport)
140+
- Provides cost-saving tips without compromising the experience
141+
142+
**Phase 4: Final Assembly (90-100%)**
143+
144+
- Coordinator compiles all agent outputs
145+
- Formats comprehensive travel plan with tips
146+
- Returns structured, user-friendly itinerary
147+
148+
### Benefits of This Architecture
149+
150+
- βœ… **Faster Execution**: Parallel agents complete in ~30% less time
151+
- βœ… **Better Quality**: Specialized agents produce more focused, accurate results
152+
- βœ… **Easy Debugging**: Each agent's contribution is isolated and traceable
153+
- βœ… **Maintainable**: Update one agent without affecting others
154+
- βœ… **Scalable**: Add new agents (flight booking, hotel search) without refactoring
155+
- βœ… **Testable**: Validate each agent independently with unit tests
156+
157+
## The Complete Architecture
158+
159+
Here's how everything fits together on Azure App Service:
160+
161+
![Complete architecture diagram]({{site.baseurl}}/media/2025/11/architecture.png)
162+
163+
This architecture builds on the async request-reply pattern from our previous post, adding:
164+
165+
- βœ… Multi-agent orchestration in the background worker
166+
- βœ… Parallel execution of independent agents for performance
167+
- βœ… Code-generated agents for production-ready DevOps
168+
- βœ… External API integration (weather, currency) for real-world data
169+
- βœ… Progress tracking across workflow phases (10% β†’ 40% β†’ 70% β†’ 100%)
170+
171+
## Get Started Today
172+
173+
Ready to build your own multi-agent workflows on Azure App Service? Try out the sample today!
174+
175+
πŸ”— **GitHub Repository**: [https://github.com/Azure-Samples/app-service-maf-workflow-travel-agent-dotnet](https://github.com/Azure-Samples/app-service-maf-workflow-travel-agent-dotnet)
176+
177+
The repository includes:
178+
179+
- βœ… Complete .NET 9 source code with 6 specialized agents
180+
- βœ… Infrastructure as Code (Bicep) for one-command deployment
181+
- βœ… Complete web UI with real-time progress tracking
182+
- βœ… Comprehensive README with architecture documentation
183+
- βœ… External API integrations (weather, currency)
184+
185+
### Deploy in Minutes
186+
187+
```bash
188+
git clone https://github.com/Azure-Samples/app-service-maf-workflow-travel-agent-dotnet.git
189+
cd app-service-maf-workflow-travel-agent-dotnet
190+
azd auth login
191+
azd up
192+
```
193+
194+
The `azd up` command provisions:
195+
196+
- Azure App Service (P0v4 Premium)
197+
- Azure Service Bus (message queue for async processing)
198+
- Azure Cosmos DB (state storage with 24-hour TTL)
199+
- Azure AI Foundry (AI Services + Project for Agent Framework)
200+
- GPT-4o model deployment (GlobalStandard 50K TPM)
201+
202+
Then manually deploy the WebJob following the [README instructions](https://github.com/Azure-Samples/app-service-maf-workflow-travel-agent-dotnet#deploy-the-webjob).
203+
204+
## What's Next? Extend This Pattern
205+
206+
This sample demonstrates production-ready patterns you can extend:
207+
208+
### πŸ› οΈ Add More Specialized Agents
209+
210+
- **Flight Expert Agent** - Search and compare flight prices
211+
- **Hotel Specialist Agent** - Find accommodations based on preferences
212+
- **Activity Planner Agent** - Book tours, restaurants, events
213+
- **Transportation Agent** - Plan routes, transit passes, car rentals
214+
215+
### 🀝 Implement Agent-to-Agent Communication
216+
217+
- Agents negotiate conflicting recommendations
218+
- Hierarchical structures with supervisor agents
219+
- Voting mechanisms for decision-making
220+
221+
### 🧠 Add Advanced Capabilities
222+
223+
- **RAG (Retrieval Augmented Generation)** for destination-specific knowledge bases
224+
- **Memory** to remember user preferences across trips
225+
- **Vision models** to analyze travel photos and recommend similar destinations
226+
- **Multi-language support** for international travelers
227+
228+
### πŸ“Š Production Enhancements
229+
230+
- **Authentication** - Microsoft Entra AD for user identity
231+
- **Application Insights** - Distributed tracing and custom metrics
232+
- **VNet Integration** - Private endpoints for security
233+
- **Auto-Scaling** - Scale workers based on queue depth
234+
- **Webhooks** - Notify users when their travel plan is ready
235+
236+
## Key Takeaways
237+
238+
- βœ… Multi-agent systems provide specialized expertise and better results than single generalist agents
239+
- βœ… Azure App Service provides a simple, reliable platform for long-running multi-agent workflows
240+
- βœ… Async request-reply pattern with Service Bus + Cosmos DB ensures scalability and resilience
241+
- βœ… External API integration makes agents more useful with real-world data
242+
- βœ… Parallel execution of independent agents dramatically improves performance
243+
244+
Whether you're building travel planners, document processors, research assistants, or other AI-powered applications, multi-agent workflows on Azure App Service give you the flexibility and sophistication you need.
245+
246+
## Learn More
247+
248+
- [Microsoft Agent Framework Documentation](https://learn.microsoft.com/en-us/agent-framework/overview/agent-framework-overview) - Complete guide to Agent Framework
249+
- [Original Blog Post](https://techcommunity.microsoft.com/blog/appsonazureblog/build-long-running-ai-agents-on-azure-app-service-with-microsoft-agent-framework/4463159) - Single-agent async patterns on App Service
250+
- [Azure App Service Best Practices](https://learn.microsoft.com/azure/app-service/app-service-best-practices) - Production deployment patterns
251+
- [Async Request-Reply Pattern](https://learn.microsoft.com/azure/architecture/patterns/async-request-reply) - Architecture guidance
252+
- [Azure App Service WebJobs](https://learn.microsoft.com/azure/app-service/overview-webjobs) - Background processing documentation
253+
254+
## We Want to Hear From You!
255+
256+
Thanks again to [Michel_Schep](https://techcommunity.microsoft.com/users/michel_schep/340533) for the great question that inspired this follow-up sample!
257+
258+
Have you built multi-agent systems with Agent Framework? Are you using Azure App Service to host your AI and intelligent apps? We'd love to hear about your experience in the comments below.
259+
260+
Questions about multi-agent workflows on App Service? Drop a comment and our team will help you get started.
261+
262+
Happy building! πŸš€

0 commit comments

Comments
Β (0)