Overview
The Microsoft Agent Framework integrates seamlessly with Azure Functions to host agents as serverless HTTP services. TheAgentFunctionApp (Python) and ConfigureDurableAgents (C#) provide automatic endpoint generation, session management, and multi-agent hosting capabilities.
Key Features
- Auto-generated HTTP endpoints per agent (
/api/agents/{name}/run) - Session management for multi-turn conversations
- Multi-agent hosting in a single Functions app
- Health checks for monitoring
- Durable orchestrations for complex workflows
- Reliable streaming with response callbacks
Quick Start
Python Setup
Install Azure Functions Core Tools
Install Azure Functions Core Tools v4.x:
C# Setup
Single Agent Hosting
Host a single agent with automatic HTTP endpoint generation:Testing the Agent
Response Format
Synchronous (default):wait_for_response: false):
Multi-Agent Hosting
Host multiple specialized agents in a single Functions app:Testing Multiple Agents
Agent Orchestrations
Create complex workflows by orchestrating multiple agent calls:Testing Orchestrations
Configuration
host.json
Configure the Functions runtime:local.settings.json
- Python
- C#
Advanced Features
Session Management
Maintain conversation context across requests:Health Checks
Monitor agent availability:Time-to-Live (TTL)
Configure agent session expiration:Reliable Streaming
Implement resumable streaming with Redis:Deployment to Azure
Best Practices
Use Managed Identity in Production
Use Managed Identity in Production
Avoid API keys in production. Configure managed identity for Azure OpenAI access:
Enable Application Insights
Enable Application Insights
Monitor performance and errors:
Configure Proper TTL
Configure Proper TTL
Set appropriate session expiration based on use case:
- Short-lived (30 min - 1 hour): Customer support chats
- Medium-lived (2-4 hours): Development assistants
- Long-lived (24+ hours): Personal assistants
Use Azure Storage for State
Use Azure Storage for State
For production, use Azure Storage instead of emulator:
Implement Rate Limiting
Implement Rate Limiting
Protect against abuse with Azure API Management or custom middleware.
Troubleshooting
Connection Errors
Connection Errors
Error: Cannot connect to Durable Task SchedulerSolution: Ensure DTS emulator is running:
Authentication Failures
Authentication Failures
Error: Azure OpenAI authentication failedSolution: Verify authentication:
Agent Not Found
Agent Not Found
Error: Agent name not found in registered agentsSolution: Verify agent registration and exact name match:
Next Steps
DurableTask Integration
Build long-running orchestrations
A2A Protocol
Connect distributed agents