Microsoft.Agents.AI.Hosting.AzureFunctions
1.0.0-preview.251219.1
Prefix Reserved
dotnet add package Microsoft.Agents.AI.Hosting.AzureFunctions --version 1.0.0-preview.251219.1
NuGet\Install-Package Microsoft.Agents.AI.Hosting.AzureFunctions -Version 1.0.0-preview.251219.1
<PackageReference Include="Microsoft.Agents.AI.Hosting.AzureFunctions" Version="1.0.0-preview.251219.1" />
<PackageVersion Include="Microsoft.Agents.AI.Hosting.AzureFunctions" Version="1.0.0-preview.251219.1" />
<PackageReference Include="Microsoft.Agents.AI.Hosting.AzureFunctions" />
paket add Microsoft.Agents.AI.Hosting.AzureFunctions --version 1.0.0-preview.251219.1
#r "nuget: Microsoft.Agents.AI.Hosting.AzureFunctions, 1.0.0-preview.251219.1"
#:package Microsoft.Agents.AI.Hosting.AzureFunctions@1.0.0-preview.251219.1
#addin nuget:?package=Microsoft.Agents.AI.Hosting.AzureFunctions&version=1.0.0-preview.251219.1&prerelease
#tool nuget:?package=Microsoft.Agents.AI.Hosting.AzureFunctions&version=1.0.0-preview.251219.1&prerelease
Microsoft.Agents.AI.Hosting.AzureFunctions
This package adds Azure Functions integration and serverless hosting for Microsoft Agent Framework on Azure Functions. It builds upon the Microsoft.Agents.AI.DurableTask package to provide the following capabilities:
- Stateful, durable execution of agents in distributed, serverless environments
- Automatic conversation history management in supported Durable Functions backends
- Long-running agent workflows as "durable orchestrator" functions
- Tools and dashboards for managing and monitoring agents and agent workflows
Install the package
From the command-line:
dotnet add package Microsoft.Agents.AI.Hosting.AzureFunctions
Or directly in your project file:
<ItemGroup>
<PackageReference Include="Microsoft.Agents.AI.Hosting.AzureFunctions" Version="[CURRENTVERSION]" />
</ItemGroup>
Usage Examples
For a comprehensive tour of all the functionality, concepts, and APIs, check out the Azure Functions samples in the Microsoft Agent Framework GitHub repository.
Hosting single agents
This package provides a ConfigureDurableAgents extension method on the FunctionsApplicationBuilder class to configure the application to host Microsoft Agent Framework agents. These hosted agents are automatically registered as durable entities with the Durable Task runtime and can be invoked via HTTP or Durable Task orchestrator functions.
// Create agents using the standard Microsoft Agent Framework.
// Invocable via HTTP via http://localhost:7071/api/agents/SpamDetectionAgent/run
AIAgent spamDetector = new AzureOpenAIClient(new Uri(endpoint), new AzureCliCredential())
.GetChatClient(deploymentName)
.CreateAIAgent(
instructions: "You are a spam detection assistant that identifies spam emails.",
name: "SpamDetectionAgent");
AIAgent emailAssistant = new AzureOpenAIClient(new Uri(endpoint), new AzureCliCredential())
.GetChatClient(deploymentName)
.CreateAIAgent(
instructions: "You are an email assistant that helps users draft responses to emails with professionalism.",
name: "EmailAssistantAgent");
// Configure the Functions application to host the agents.
using IHost app = FunctionsApplication
.CreateBuilder(args)
.ConfigureFunctionsWebApplication()
.ConfigureDurableAgents(options =>
{
options.AddAIAgent(spamDetector);
options.AddAIAgent(emailAssistant);
})
.Build();
app.Run();
By default, each agent can be invoked via a built-in HTTP trigger function at the route http[s]://[host]/api/agents/{agentName}/run.
Orchestrating hosted agents
This package also provides a set of extension methods such as GetAgent on the TaskOrchestrationContext class for interacting with hosted agents within orchestrations.
[Function(nameof(SpamDetectionOrchestration))]
public static async Task<string> SpamDetectionOrchestration(
[OrchestrationTrigger] TaskOrchestrationContext context)
{
Email email = context.GetInput<Email>() ?? throw new InvalidOperationException("Email is required");
// Get the spam detection agent
DurableAIAgent spamDetectionAgent = context.GetAgent("SpamDetectionAgent");
AgentThread spamThread = spamDetectionAgent.GetNewThread();
// Step 1: Check if the email is spam
AgentRunResponse<DetectionResult> spamDetectionResponse = await spamDetectionAgent.RunAsync<DetectionResult>(
message:
$"""
Analyze this email for spam content and return a JSON response with 'is_spam' (boolean) and 'reason' (string) fields:
Email ID: {email.EmailId}
Content: {email.EmailContent}
""",
thread: spamThread);
DetectionResult result = spamDetectionResponse.Result;
// Step 2: Conditional logic based on spam detection result
if (result.IsSpam)
{
// Handle spam email
return await context.CallActivityAsync<string>(nameof(HandleSpamEmail), result.Reason);
}
else
{
// Generate and send response for legitimate email
DurableAIAgent emailAssistantAgent = context.GetAgent("EmailAssistantAgent");
AgentThread emailThread = emailAssistantAgent.GetNewThread();
AgentRunResponse<EmailResponse> emailAssistantResponse = await emailAssistantAgent.RunAsync<EmailResponse>(
message:
$"""
Draft a professional response to this email. Return a JSON response with a 'response' field containing the reply:
Email ID: {email.EmailId}
Content: {email.EmailContent}
""",
thread: emailThread);
EmailResponse emailResponse = emailAssistantResponse.Result;
return await context.CallActivityAsync<string>(nameof(SendEmail), emailResponse.Response);
}
}
Scheduling orchestrations from custom code tools
Agents can also schedule and interact with orchestrations from custom code tools. This is useful for long-running tool use cases where orchestrations need to be executed in the context of the agent.
The DurableAgentContext.Current AsyncLocal property provides access to the current agent context, which can be used to schedule and interact with orchestrations.
class Tools
{
[Description("Starts a content generation workflow and returns the instance ID for tracking.")]
public string StartContentGenerationWorkflow(
[Description("The topic for content generation")] string topic)
{
// ContentGenerationWorkflow is an orchestrator function defined in the same project.
string instanceId = DurableAgentContext.Current.ScheduleNewOrchestration(
name: nameof(ContentGenerationWorkflow),
input: topic);
// Return the instance ID so that it gets added to the LLM context.
return instanceId;
}
[Description("Gets the status of a content generation workflow.")]
public async Task<OrchestrationMetadata> GetContentGenerationStatus(
[Description("The instance ID of the workflow to check")] string instanceId,
[Description("Whether to include detailed information")] bool includeDetails = true)
{
OrchestrationMetadata? status = await DurableAgentContext.Current.Client.GetOrchestrationStatusAsync(
instanceId,
includeDetails);
return status ?? throw new InvalidOperationException($"Workflow instance '{instanceId}' not found.");
}
}
These tools are registered with the agent using the tools parameter when creating the agent.
Tools tools = new();
AIAgent agent = new AzureOpenAIClient(new Uri(endpoint), new AzureCliCredential())
.GetChatClient(deploymentName)
.CreateAIAgent(
instructions: "You are a content generation assistant that helps users generate content.",
name: "ContentGenerationAgent",
tools: [
AIFunctionFactory.Create(tools.StartContentGenerationWorkflow),
AIFunctionFactory.Create(tools.GetContentGenerationStatus)
]);
using IHost app = FunctionsApplication
.CreateBuilder(args)
.ConfigureFunctionsWebApplication()
.ConfigureDurableAgents(options => options.AddAIAgent(agent))
.Build();
app.Run();
Feedback & Contributing
We welcome feedback and contributions in our GitHub repo.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- Microsoft.Agents.AI.DurableTask (>= 1.0.0-preview.251219.1)
- Microsoft.Azure.Functions.Worker (>= 2.50.0)
- Microsoft.Azure.Functions.Worker.Extensions.DurableTask (>= 1.11.0)
- Microsoft.Azure.Functions.Worker.Extensions.Http (>= 3.3.0)
- Microsoft.Azure.Functions.Worker.Extensions.Mcp (>= 1.0.0)
- Microsoft.Bcl.AsyncInterfaces (>= 10.0.1)
- Microsoft.DurableTask.Client (>= 1.18.0)
- Microsoft.DurableTask.Worker (>= 1.18.0)
- Microsoft.Extensions.AI (>= 10.1.1)
- Microsoft.Extensions.AI.Abstractions (>= 10.1.1)
- Microsoft.Extensions.Caching.Memory (>= 10.0.0)
- Microsoft.Extensions.Configuration (>= 10.0.0)
- Microsoft.Extensions.Configuration.Binder (>= 10.0.0)
- Microsoft.Extensions.Configuration.EnvironmentVariables (>= 10.0.0)
- Microsoft.Extensions.Configuration.Json (>= 10.0.0)
- Microsoft.Extensions.Configuration.UserSecrets (>= 10.0.0)
- Microsoft.Extensions.DependencyInjection (>= 10.0.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.1)
- Microsoft.Extensions.Hosting (>= 10.0.0)
- Microsoft.Extensions.Logging (>= 10.0.0)
- Microsoft.Extensions.Logging.Abstractions (>= 10.0.1)
- Microsoft.Extensions.Logging.Console (>= 10.0.0)
- Microsoft.Extensions.VectorData.Abstractions (>= 9.7.0)
- Newtonsoft.Json (>= 13.0.4)
- System.ClientModel (>= 1.8.1)
-
net8.0
- Microsoft.Agents.AI.DurableTask (>= 1.0.0-preview.251219.1)
- Microsoft.Azure.Functions.Worker (>= 2.50.0)
- Microsoft.Azure.Functions.Worker.Extensions.DurableTask (>= 1.11.0)
- Microsoft.Azure.Functions.Worker.Extensions.Http (>= 3.3.0)
- Microsoft.Azure.Functions.Worker.Extensions.Mcp (>= 1.0.0)
- Microsoft.Bcl.AsyncInterfaces (>= 10.0.1)
- Microsoft.DurableTask.Client (>= 1.18.0)
- Microsoft.DurableTask.Worker (>= 1.18.0)
- Microsoft.Extensions.AI (>= 10.1.1)
- Microsoft.Extensions.AI.Abstractions (>= 10.1.1)
- Microsoft.Extensions.Caching.Memory (>= 10.0.0)
- Microsoft.Extensions.Configuration (>= 10.0.0)
- Microsoft.Extensions.Configuration.Binder (>= 10.0.0)
- Microsoft.Extensions.Configuration.EnvironmentVariables (>= 10.0.0)
- Microsoft.Extensions.Configuration.Json (>= 10.0.0)
- Microsoft.Extensions.Configuration.UserSecrets (>= 10.0.0)
- Microsoft.Extensions.DependencyInjection (>= 10.0.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.1)
- Microsoft.Extensions.Hosting (>= 10.0.0)
- Microsoft.Extensions.Logging (>= 10.0.0)
- Microsoft.Extensions.Logging.Abstractions (>= 10.0.1)
- Microsoft.Extensions.Logging.Console (>= 10.0.0)
- Microsoft.Extensions.VectorData.Abstractions (>= 9.7.0)
- Newtonsoft.Json (>= 13.0.4)
- System.ClientModel (>= 1.8.1)
- System.Diagnostics.DiagnosticSource (>= 10.0.1)
- System.Text.Json (>= 10.0.1)
- System.Threading.Channels (>= 10.0.1)
-
net9.0
- Microsoft.Agents.AI.DurableTask (>= 1.0.0-preview.251219.1)
- Microsoft.Azure.Functions.Worker (>= 2.50.0)
- Microsoft.Azure.Functions.Worker.Extensions.DurableTask (>= 1.11.0)
- Microsoft.Azure.Functions.Worker.Extensions.Http (>= 3.3.0)
- Microsoft.Azure.Functions.Worker.Extensions.Mcp (>= 1.0.0)
- Microsoft.Bcl.AsyncInterfaces (>= 10.0.1)
- Microsoft.DurableTask.Client (>= 1.18.0)
- Microsoft.DurableTask.Worker (>= 1.18.0)
- Microsoft.Extensions.AI (>= 10.1.1)
- Microsoft.Extensions.AI.Abstractions (>= 10.1.1)
- Microsoft.Extensions.Caching.Memory (>= 10.0.0)
- Microsoft.Extensions.Configuration (>= 10.0.0)
- Microsoft.Extensions.Configuration.Binder (>= 10.0.0)
- Microsoft.Extensions.Configuration.EnvironmentVariables (>= 10.0.0)
- Microsoft.Extensions.Configuration.Json (>= 10.0.0)
- Microsoft.Extensions.Configuration.UserSecrets (>= 10.0.0)
- Microsoft.Extensions.DependencyInjection (>= 10.0.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.1)
- Microsoft.Extensions.Hosting (>= 10.0.0)
- Microsoft.Extensions.Logging (>= 10.0.0)
- Microsoft.Extensions.Logging.Abstractions (>= 10.0.1)
- Microsoft.Extensions.Logging.Console (>= 10.0.0)
- Microsoft.Extensions.VectorData.Abstractions (>= 9.7.0)
- Newtonsoft.Json (>= 13.0.4)
- System.ClientModel (>= 1.8.1)
- System.Diagnostics.DiagnosticSource (>= 10.0.1)
- System.Text.Json (>= 10.0.1)
- System.Threading.Channels (>= 10.0.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories (1)
Showing the top 1 popular GitHub repositories that depend on Microsoft.Agents.AI.Hosting.AzureFunctions:
| Repository | Stars |
|---|---|
|
rwjdk/MicrosoftAgentFrameworkSamples
Samples demonstrating the Microsoft Agent Framework in C#
|
| Version | Downloads | Last Updated |
|---|---|---|
| 1.0.0-preview.251219.1 | 224 | 12/19/2025 |
| 1.0.0-preview.251204.1 | 348 | 12/5/2025 |
| 1.0.0-preview.251125.1 | 379 | 11/26/2025 |
| 1.0.0-preview.251114.1 | 202 | 11/15/2025 |
| 1.0.0-preview.251113.1 | 220 | 11/14/2025 |
| 1.0.0-preview.251112.1 | 267 | 11/13/2025 |