create-and-run-durable-agent
Learn how to create and run a durable AI agent with Azure Functions and the durable task extension for Microsoft Agent Framework
$ npx -y skills add managedcode/dotnet-skills --agent claude-codeHow it fires
How this agent gets triggered: by you, by Claude, or both.
- Fires itselfAuto-invocation. Claude auto-loads it when your prompt matches the work.Auto-invocation is when the right skill fires by itself at the right moment, driven by a FLOW.md router and a hook, instead of you invoking it by name. It is the difference between a skill being installed and a skill actually getting used.Read the full definition →
- You can call itInvoke it directly when you want it.
Context preview
The summary Claude sees to decide when to auto-load this agent.
Learn how to create and run a durable AI agent with Azure Functions and the durable task extension for Microsoft Agent Framework
Agent definition
create-and-run-durable-agent.mdtitle: Create and run a durable agent
description: Learn how to create and run a durable AI agent with Azure Functions and the durable task extension for Microsoft Agent Framework
zone_pivot_groups: programming-languages
author: anthonychu
ms.topic: tutorial
ms.author: antchu
ms.date: 11/05/2025
ms.service: agent-framework
Create and run a durable agent
This tutorial shows you how to create and run a [durable AI agent](../../user-guide/agents/agent-types/durable-agent/create-durable-agent.md) using the durable task extension for Microsoft Agent Framework. You'll build an Azure Functions app that hosts a stateful agent with built-in HTTP endpoints, and learn how to monitor it using the Durable Task Scheduler dashboard.
Durable agents provide serverless hosting with automatic state management, allowing your agents to maintain conversation history across multiple interactions without managing infrastructure.
Prerequisites
Before you begin, ensure you have the following prerequisites:
::: zone pivot="programming-language-csharp"
- [.NET 9.0 SDK or later](https://dotnet.microsoft.com/download)
- [Azure Functions Core Tools v4.x](/azure/azure-functions/functions-run-local#install-the-azure-functions-core-tools)
- [Azure Developer CLI (azd)](/azure/developer/azure-developer-cli/install-azd)
- [Azure CLI installed](/cli/azure/install-azure-cli) and [authenticated](/cli/azure/authenticate-azure-cli)
- [Docker Desktop](https://www.docker.com/products/docker-desktop/) installed and running (for local development with Azurite and the Durable Task Scheduler emulator)
- An Azure subscription with permissions to create resources
> [!NOTE] > Microsoft Agent Framework is supported with all actively supported versions of .NET. For the purposes of this sample, we recommend the .NET 9 SDK or a later version.
::: zone-end
::: zone pivot="programming-language-python"
- [Python 3.10 or later](https://www.python.org/downloads/)
- [Azure Functions Core Tools v4.x](/azure/azure-functions/functions-run-local#install-the-azure-functions-core-tools)
- [Azure Developer CLI (azd)](/azure/developer/azure-developer-cli/install-azd)
- [Azure CLI installed](/cli/azure/install-azure-cli) and [authenticated](/cli/azure/authenticate-azure-cli)
- [Docker Desktop](https://www.docker.com/products/docker-desktop/) installed and running (for local development with Azurite and the Durable Task Scheduler emulator)
- An Azure subscription with permissions to create resources
::: zone-end
Download the quickstart project
Use Azure Developer CLI to initialize a new project from the durable agents quickstart template.
::: zone pivot="programming-language-csharp"
1. Create a new directory for your project and navigate to it:
[Bash](#tab/bash)
mkdir MyDurableAgent
cd MyDurableAgent
[PowerShell](#tab/powershell)
New-Item -ItemType Directory -Path MyDurableAgent
Set-Location MyDurableAgent
---
1. Initialize the project from the template:
azd init --template durable-agents-quickstart-dotnet
When prompted for an environment name, enter a name like `my-durable-agent`.
This downloads the quickstart project with all necessary files, including the Azure Functions configuration, agent code, and infrastructure as code templates.
::: zone-end
::: zone pivot="programming-language-python"
1. Create a new directory for your project and navigate to it:
[Bash](#tab/bash)
mkdir MyDurableAgent
cd MyDurableAgent
[PowerShell](#tab/powershell)
New-Item -ItemType Directory -Path MyDurableAgent
Set-Location MyDurableAgent
---
1. Initialize the project from the template:
azd init --template durable-agents-quickstart-python
When prompted for an environment name, enter a name like `my-durable-agent`.
1. Create and activate a virtual environment:
[Bash](#tab/bash)
python3 -m venv .venv
source .venv/bin/activate
[PowerShell](#tab/powershell)
python3 -m venv .venv
.venv\Scripts\Activate.ps1
---
1. Install the required packages:
python -m pip install -r requirements.txt
This downloads the quickstart project with all necessary files, including the Azure Functions configuration, agent code, and infrastructure as code templates. It also prepares a virtual environment with the required dependencies.
::: zone-end
Provision Azure resources
Use Azure Developer CLI to create the required Azure resources for your durable agent.
1. Provision the infrastructure:
azd provision
This command creates:
- An Azure OpenAI service with a gpt-4o-mini deployment
- An Azure Functions app with Flex Consumption hosting plan
- An Azure Storage account for the Azure Functions runtime and durable storage
- A Durable Task Scheduler instance (Consumption plan) for managing agent state
- Necessary networking and identity configurations
1. When prompted, select your Azure subscription and choose a location for the resources.
The provisioning process takes a few minutes. Once complete, azd stores the created resource information in your environment.
Review the agent code
Now let's examine the code that defines your durable agent.
::: zone pivot="programming-language-csharp"
Open `Program.cs` to see the agent configuration:
using Azure.AI.OpenAI;
using Azure.Identity;
using Microsoft.Agents.AI;
using Microsoft.Agents.AI.Hosting.AzureFunctions;
using Microsoft.Azure.Functions.Worker.Builder;
using Microsoft.Extensions.AI;
using Microsoft.Extensions.Hosting;
using OpenAI;
var endpoint = Environment.GetEnvironmentVariable("AZURE_OPENAI_ENDPOINT")
?? throw new InvalidOperationException("AZURE_OPENAI_ENDPOINT environment variable is not set");
var deploymentName = Environment.GetEnvironmentVariaRead more
title: Create and run a durable agent description: Learn how to create and run a durable AI agent with Azure Functions and the durable task extension for Microsoft Agent Framework zone_pivot_groups: programming-languages author: anthonychu ms.topic: tutorial ms.author: antchu ms.date: 11/05/2025 ms.service: agent-framework
Create and run a durable agent
This tutorial shows you how to create and run a [durable AI agent](../../user-guide/agents/agent-types/durable-agent/create-durable-agent.md) using the durable task extension for Microsoft Agent Framework. You'll build an Azure Functions app that hosts a stateful agent with built-in HTTP endpoints, and learn how to monitor it using the Durable Task Scheduler dashboard.
Durable agents provide serverless hosting with automatic state management, allowing your agents to maintain conversation history across multiple interactions without managing infrastructure.
Prerequisites
Before you begin, ensure you have the following prerequisites:
::: zone pivot="programming-language-csharp"
- [.NET 9.0 SDK or later](https://dotnet.microsoft.com/download)
- [Azure Functions Core Tools v4.x](/azure/azure-functions/functions-run-local#install-the-azure-functions-core-tools)
- [Azure Developer CLI (azd)](/azure/developer/azure-developer-cli/install-azd)
- [Azure CLI installed](/cli/azure/install-azure-cli) and [authenticated](/cli/azure/authenticate-azure-cli)
- [Docker Desktop](https://www.docker.com/products/docker-desktop/) installed and running (for local development with Azurite and the Durable Task Scheduler emulator)
- An Azure subscription with permissions to create resources
> [!NOTE] > Microsoft Agent Framework is supported with all actively supported versions of .NET. For the purposes of this sample, we recommend the .NET 9 SDK or a later version.
::: zone-end
::: zone pivot="programming-language-python"
- [Python 3.10 or later](https://www.python.org/downloads/)
- [Azure Functions Core Tools v4.x](/azure/azure-functions/functions-run-local#install-the-azure-functions-core-tools)
- [Azure Developer CLI (azd)](/azure/developer/azure-developer-cli/install-azd)
- [Azure CLI installed](/cli/azure/install-azure-cli) and [authenticated](/cli/azure/authenticate-azure-cli)
- [Docker Desktop](https://www.docker.com/products/docker-desktop/) installed and running (for local development with Azurite and the Durable Task Scheduler emulator)
- An Azure subscription with permissions to create resources
::: zone-end
Download the quickstart project
Use Azure Developer CLI to initialize a new project from the durable agents quickstart template.
::: zone pivot="programming-language-csharp"
1. Create a new directory for your project and navigate to it:
[Bash](#tab/bash)
mkdir MyDurableAgent cd MyDurableAgent
[PowerShell](#tab/powershell)
New-Item -ItemType Directory -Path MyDurableAgent Set-Location MyDurableAgent
---
1. Initialize the project from the template:
azd init --template durable-agents-quickstart-dotnet
When prompted for an environment name, enter a name like `my-durable-agent`.
This downloads the quickstart project with all necessary files, including the Azure Functions configuration, agent code, and infrastructure as code templates.
::: zone-end
::: zone pivot="programming-language-python"
1. Create a new directory for your project and navigate to it:
[Bash](#tab/bash)
mkdir MyDurableAgent cd MyDurableAgent
[PowerShell](#tab/powershell)
New-Item -ItemType Directory -Path MyDurableAgent Set-Location MyDurableAgent
---
1. Initialize the project from the template:
azd init --template durable-agents-quickstart-python
When prompted for an environment name, enter a name like `my-durable-agent`.
1. Create and activate a virtual environment:
[Bash](#tab/bash)
python3 -m venv .venv source .venv/bin/activate
[PowerShell](#tab/powershell)
python3 -m venv .venv .venv\Scripts\Activate.ps1
---
1. Install the required packages:
python -m pip install -r requirements.txt
This downloads the quickstart project with all necessary files, including the Azure Functions configuration, agent code, and infrastructure as code templates. It also prepares a virtual environment with the required dependencies.
::: zone-end
Provision Azure resources
Use Azure Developer CLI to create the required Azure resources for your durable agent.
1. Provision the infrastructure:
azd provision
This command creates:
- An Azure OpenAI service with a gpt-4o-mini deployment
- An Azure Functions app with Flex Consumption hosting plan
- An Azure Storage account for the Azure Functions runtime and durable storage
- A Durable Task Scheduler instance (Consumption plan) for managing agent state
- Necessary networking and identity configurations
1. When prompted, select your Azure subscription and choose a location for the resources.
The provisioning process takes a few minutes. Once complete, azd stores the created resource information in your environment.
Review the agent code
Now let's examine the code that defines your durable agent.
::: zone pivot="programming-language-csharp"
Open `Program.cs` to see the agent configuration:
using Azure.AI.OpenAI;
using Azure.Identity;
using Microsoft.Agents.AI;
using Microsoft.Agents.AI.Hosting.AzureFunctions;
using Microsoft.Azure.Functions.Worker.Builder;
using Microsoft.Extensions.AI;
using Microsoft.Extensions.Hosting;
using OpenAI;
var endpoint = Environment.GetEnvironmentVariable("AZURE_OPENAI_ENDPOINT")
?? throw new InvalidOperationException("AZURE_OPENAI_ENDPOINT environment variable is not set");
var deploymentName = Environment.GetEnvironmentVariaStop explaining .NET to your AI. Start building. We've all been there: asking Claude to use Entity Framework, only to get EF6 patterns in a .NET 8 project. Explaining to Copilot that Blazor Server and Blazor WebAssembly aren't the same thing.
Repo: managedcode/dotnet-skills
Other agents on dotnet-skills.
- AGENT
Specialist orchestration agent for .NET Aspire work. Use when the problem is clearly about AppHost design, ServiceDefaults, first-party versus CommunityToolkit/Aspire integrations, dashboard and testing, `DistributedApplicationTestingBuilder`, `WebApplicationFactory`
Open agent - agent-as-function-tool
Legacy tutorial alias retained locally; the live Learn URL now resolves into the broader Function Tools surface
Open agent - agent-as-mcp-tool
Learn how to expose an agent as a tool over the MCP protocol
Open agent - enable-observability
Enable OpenTelemetry for an agent so agent interactions are automatically logged
Open agent - function-tools-approvals
Learn how to use function tools with human in the loop approvals
Open agent - function-tools
Learn how to use function tools with an agent
Open agent

