Skip to content

Commit 67a8147

Browse files
dmytrostruklarohracgillumCopilotanirudhgarg
authored
.NET: Python: Azure Functions feature branch (#1916)
* Python: Add Scaffolding for Durable AzureFunctions package to Agent Framework (#1823) * Add scafolding * update readme * add code owners and label * update owners * .NET: Durable extension: initial src and unit tests (#1900) * Python: Add Durable Agent Wrapper code (#1913) * add initial changes * Move code and add single sample * Update logger * Remove unused code * address PR comments * cleanup code and address comments --------- Co-authored-by: Dmytro Struk <13853051+dmytrostruk@users.noreply.github.com> * Azure Functions .NET samples (#1939) * Python: Add Unit tests for Azurefunctions package (#1976) * Add Unit tests for Azurefunctions * remove duplicate import * .NET: [Feature Branch] Migrate state schema updates and support for agents as MCP tools (#1979) * Python: Add more samples for Azure Functions (#1980) * Move all samples * fix comments * remove dead lines * Make samples simpler * .NET: [Feature Branch] Durable Task extension integration tests (#2017) * .NET: [Feature Branch] Update OpenAI config for integration tests (#2063) * Python: Add Integration tests for AzureFunctions (#2020) * Add Integration tests * Remove DTS extension * Apply suggestions from code review Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Apply suggestions from code review Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Add pyi file for type safety * Add samples in readme * Updated all readme instructions * Address comments * Update readmes * Fix requirements * Address comments --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * .NET: [Feature Branch] Update dotnet-build-and-test.yml to support integration tests (#2070) Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Fix DTS startup issue and improve logging (#2103) * .NET: [Feature Branch] Introduce Azure OpenAI config for .NET pipeline (#2106) Also fixes an issue where we were trying to start docker containers for integration tests on Windows, which doesn't work. Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Fix uv.lock after merge * Python: Add README for Azure Functions samples setup (#2100) * Add README for Azure Functions samples setup Added setup instructions for Azure Functions samples, including environment setup, virtual environment creation, and running samples. * Update python/samples/getting_started/azure_functions/README.md Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Apply suggestions from code review Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Apply suggestion from @Copilot Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Apply suggestions from code review Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: Laveesh Rohra <larohra@microsoft.com> * Fix or remove broken markdown file links (#2115) * .NET: [Feature Branch] Update HTTP API to be consistent across languages (#2118) * Python: Fix AzureFunctions Integration Tests (#2116) * Add Identity Auth to samples * Update python/samples/getting_started/azure_functions/README.md Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update python/samples/getting_started/azure_functions/01_single_agent/function_app.py Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update python/samples/getting_started/azure_functions/02_multi_agent/function_app.py Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update python/samples/getting_started/azure_functions/06_multi_agent_orchestration_conditionals/README.md Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Python: Fix Http Schema (#2112) * Rename to threadid * Respond in plain text * Make snake-case * Add http prefix * rename to wait-for-response * Add query param check * address comments * .NET: Remove IsPackable=false in preparation for nuget release (#2142) * Python: Move `azurefunctions` to `azure` for import (#2141) * Move import to Azure * fix mypy * Update python/packages/azurefunctions/README.md Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Add missing types * Address comments --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update python/packages/azurefunctions/pyproject.toml Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update python/packages/azurefunctions/agent_framework_azurefunctions/__init__.py Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Fix imports * Address PR feedback from westey-m (#2150) - Adds a link from the /dotnet/samples/README.md to /dotnet/samples/AzureFunctions - Make DurableAgentThread deserialization internal for future-proofing - Update JSON serialization logic to address recently discovered issues with source generator serialization * Address comments (#2160) --------- Co-authored-by: Laveesh Rohra <larohra@microsoft.com> Co-authored-by: Chris Gillum <cgillum@microsoft.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: Anirudh Garg <anirudhg@microsoft.com>
1 parent 5537b1d commit 67a8147

File tree

216 files changed

+18178
-2
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

216 files changed

+18178
-2
lines changed

.github/CODEOWNERS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Code ownership assignments
2+
# https://docs.github.com/repositories/managing-your-repositorys-settings-and-features/customizing-your-repository/about-code-owners
3+
4+
python/packages/azurefunctions/ @microsoft/agentframework-durabletask-developers
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: Azure Functions Integration Test Setup
2+
description: Prepare local emulators and tools for Azure Functions integration tests
3+
4+
runs:
5+
using: "composite"
6+
steps:
7+
- name: Start Durable Task Scheduler Emulator
8+
shell: bash
9+
run: |
10+
if [ "$(docker ps -aq -f name=dts-emulator)" ]; then
11+
echo "Stopping and removing existing Durable Task Scheduler Emulator"
12+
docker rm -f dts-emulator
13+
fi
14+
echo "Starting Durable Task Scheduler Emulator"
15+
docker run -d --name dts-emulator -p 8080:8080 -p 8082:8082 mcr.microsoft.com/dts/dts-emulator:latest
16+
echo "Waiting for Durable Task Scheduler Emulator to be ready"
17+
timeout 30 bash -c 'until curl --silent http://localhost:8080/healthz; do sleep 1; done'
18+
echo "Durable Task Scheduler Emulator is ready"
19+
- name: Start Azurite (Azure Storage emulator)
20+
shell: bash
21+
run: |
22+
if [ "$(docker ps -aq -f name=azurite)" ]; then
23+
echo "Stopping and removing existing Azurite (Azure Storage emulator)"
24+
docker rm -f azurite
25+
fi
26+
echo "Starting Azurite (Azure Storage emulator)"
27+
docker run -d --name azurite -p 10000:10000 -p 10001:10001 -p 10002:10002 mcr.microsoft.com/azure-storage/azurite
28+
echo "Waiting for Azurite (Azure Storage emulator) to be ready"
29+
timeout 30 bash -c 'until curl --silent http://localhost:10000/devstoreaccount1; do sleep 1; done'
30+
echo "Azurite (Azure Storage emulator) is ready"
31+
- name: Install Azure Functions Core Tools
32+
shell: bash
33+
run: |
34+
echo "Installing Azure Functions Core Tools"
35+
npm install -g azure-functions-core-tools@4 --unsafe-perm true
36+
func --version

.github/workflows/dotnet-build-and-test.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,14 @@ jobs:
151151
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
152152
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
153153

154+
# This setup action is required for both Durable Task and Azure Functions integration tests.
155+
# We only run it on Ubuntu since the Durable Task and Azure Functions features are not available
156+
# on .NET Framework (net472) which is what we use the Windows runner for.
157+
- name: Set up Durable Task and Azure Functions Integration Test Emulators
158+
if: github.event_name != 'pull_request' && matrix.integration-tests && matrix.os == 'ubuntu-latest'
159+
uses: ./.github/actions/azure-functions-integration-setup
160+
id: azure-functions-setup
161+
154162
- name: Run Integration Tests
155163
shell: bash
156164
if: github.event_name != 'pull_request' && matrix.integration-tests
@@ -172,6 +180,9 @@ jobs:
172180
OpenAI__ApiKey: ${{ secrets.OPENAI__APIKEY }}
173181
OpenAI__ChatModelId: ${{ vars.OPENAI__CHATMODELID }}
174182
OpenAI__ChatReasoningModelId: ${{ vars.OPENAI__CHATREASONINGMODELID }}
183+
# Azure OpenAI Models
184+
AZURE_OPENAI_CHAT_DEPLOYMENT_NAME: ${{ vars.AZUREOPENAI__CHATDEPLOYMENTNAME }}
185+
AZURE_OPENAI_ENDPOINT: ${{ vars.AZUREOPENAI__ENDPOINT }}
175186
# Azure AI Foundry
176187
AzureAI__Endpoint: ${{ secrets.AZUREAI__ENDPOINT }}
177188
AzureAI__DeploymentName: ${{ vars.AZUREAI__DEPLOYMENTNAME }}

.github/workflows/python-merge-tests.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,11 @@ jobs:
6666
AZURE_OPENAI_RESPONSES_DEPLOYMENT_NAME: ${{ vars.AZUREOPENAI__RESPONSESDEPLOYMENTNAME }}
6767
AZURE_OPENAI_ENDPOINT: ${{ vars.AZUREOPENAI__ENDPOINT }}
6868
LOCAL_MCP_URL: ${{ vars.LOCAL_MCP__URL }}
69+
# For Azure Functions integration tests
70+
FUNCTIONS_WORKER_RUNTIME: "python"
71+
DURABLE_TASK_SCHEDULER_CONNECTION_STRING: "Endpoint=http://localhost:8080;TaskHub=default;Authentication=None"
72+
AzureWebJobsStorage: "UseDevelopmentStorage=true"
73+
6974
defaults:
7075
run:
7176
working-directory: python
@@ -87,6 +92,9 @@ jobs:
8792
client-id: ${{ secrets.AZURE_CLIENT_ID }}
8893
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
8994
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
95+
- name: Set up Azure Functions Integration Test Emulators
96+
uses: ./.github/actions/azure-functions-integration-setup
97+
id: azure-functions-setup
9098
- name: Test with pytest
9199
timeout-minutes: 10
92100
run: uv run poe all-tests -n logical --dist loadfile --dist worksteal --timeout 300 --retries 3 --retry-delay 10

.gitignore

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,10 +205,22 @@ agents.md
205205
.claude/
206206
WARP.md
207207

208+
# Azurite storage emulator files
209+
*/__azurite_db_blob__.json
210+
*/__azurite_db_blob_extent__.json
211+
*/__azurite_db_queue__.json
212+
*/__azurite_db_queue_extent__.json
213+
*/__azurite_db_table__.json
214+
*/__blobstorage__/
215+
*/__queuestorage__/
216+
217+
# Azure Functions local settings
218+
local.settings.json
219+
208220
# Frontend
209221
**/frontend/node_modules/
210222
**/frontend/.vite/
211223
**/frontend/dist/
212224

213225
# Database files
214-
*.db
226+
*.db

dotnet/Directory.Packages.props

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,20 @@
9797
<PackageVersion Include="Microsoft.Bot.ObjectModel.Json" Version="1.2025.1003.2" />
9898
<PackageVersion Include="Microsoft.Bot.ObjectModel.PowerFx" Version="1.2025.1003.2" />
9999
<PackageVersion Include="Microsoft.PowerFx.Interpreter" Version="1.4.0" />
100+
<!-- Durable Task -->
101+
<PackageVersion Include="Microsoft.DurableTask.Client" Version="1.16.2" />
102+
<PackageVersion Include="Microsoft.DurableTask.Client.AzureManaged" Version="1.16.2-preview.1" />
103+
<PackageVersion Include="Microsoft.DurableTask.Worker" Version="1.16.2" />
104+
<PackageVersion Include="Microsoft.DurableTask.Worker.AzureManaged" Version="1.16.2-preview.1" />
105+
<!-- Azure Functions -->
106+
<PackageVersion Include="Microsoft.Azure.Functions.Worker" Version="2.2.0" />
107+
<PackageVersion Include="Microsoft.Azure.Functions.Worker.ApplicationInsights" Version="2.0.0" />
108+
<PackageVersion Include="Microsoft.Azure.Functions.Worker.Extensions.DurableTask" Version="1.9.0" />
109+
<PackageVersion Include="Microsoft.Azure.Functions.Worker.Extensions.DurableTask.AzureManaged" Version="1.0.0" />
110+
<PackageVersion Include="Microsoft.Azure.Functions.Worker.Extensions.Http" Version="3.3.0" />
111+
<PackageVersion Include="Microsoft.Azure.Functions.Worker.Extensions.Http.AspNetCore" Version="2.1.0" />
112+
<PackageVersion Include="Microsoft.Azure.Functions.Worker.Extensions.Mcp" Version="1.0.0" />
113+
<PackageVersion Include="Microsoft.Azure.Functions.Worker.Sdk" Version="2.0.5" />
100114
<!-- Community -->
101115
<PackageVersion Include="System.Linq.Async" Version="6.0.3" />
102116
<!-- Test -->

dotnet/agent-framework-dotnet.slnx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,17 @@
2323
<Project Path="samples/AGUIClientServer/AGUIDojoServer/AGUIDojoServer.csproj" />
2424
<Project Path="samples/AGUIClientServer/AGUIServer/AGUIServer.csproj" />
2525
</Folder>
26+
<Folder Name="/Samples/AzureFunctions/">
27+
<File Path="samples/AzureFunctions/.editorconfig" />
28+
<File Path="samples/AzureFunctions/README.md" />
29+
<Project Path="samples/AzureFunctions/01_SingleAgent/01_SingleAgent.csproj" />
30+
<Project Path="samples/AzureFunctions/02_AgentOrchestration_Chaining/02_AgentOrchestration_Chaining.csproj" />
31+
<Project Path="samples/AzureFunctions/03_AgentOrchestration_Concurrency/03_AgentOrchestration_Concurrency.csproj" />
32+
<Project Path="samples/AzureFunctions/04_AgentOrchestration_Conditionals/04_AgentOrchestration_Conditionals.csproj" />
33+
<Project Path="samples/AzureFunctions/05_AgentOrchestration_HITL/05_AgentOrchestration_HITL.csproj" />
34+
<Project Path="samples/AzureFunctions/06_LongRunningTools/06_LongRunningTools.csproj" />
35+
<Project Path="samples/AzureFunctions/07_AgentAsMcpTool/07_AgentAsMcpTool.csproj" />
36+
</Folder>
2637
<Folder Name="/Samples/GettingStarted/">
2738
<File Path="samples/GettingStarted/README.md" />
2839
</Folder>
@@ -290,9 +301,11 @@
290301
<Project Path="src/Microsoft.Agents.AI.AzureAI.Persistent/Microsoft.Agents.AI.AzureAI.Persistent.csproj" />
291302
<Project Path="src/Microsoft.Agents.AI.CopilotStudio/Microsoft.Agents.AI.CopilotStudio.csproj" />
292303
<Project Path="src/Microsoft.Agents.AI.DevUI/Microsoft.Agents.AI.DevUI.csproj" />
304+
<Project Path="src/Microsoft.Agents.AI.DurableTask/Microsoft.Agents.AI.DurableTask.csproj" />
293305
<Project Path="src/Microsoft.Agents.AI.Hosting.A2A.AspNetCore/Microsoft.Agents.AI.Hosting.A2A.AspNetCore.csproj" />
294306
<Project Path="src/Microsoft.Agents.AI.Hosting.A2A/Microsoft.Agents.AI.Hosting.A2A.csproj" />
295307
<Project Path="src/Microsoft.Agents.AI.Hosting.AGUI.AspNetCore/Microsoft.Agents.AI.Hosting.AGUI.AspNetCore.csproj" />
308+
<Project Path="src/Microsoft.Agents.AI.Hosting.AzureFunctions/Microsoft.Agents.AI.Hosting.AzureFunctions.csproj" />
296309
<Project Path="src/Microsoft.Agents.AI.Hosting.OpenAI/Microsoft.Agents.AI.Hosting.OpenAI.csproj" />
297310
<Project Path="src/Microsoft.Agents.AI.Hosting/Microsoft.Agents.AI.Hosting.csproj" />
298311
<Project Path="src/Microsoft.Agents.AI.Mem0/Microsoft.Agents.AI.Mem0.csproj" />
@@ -306,7 +319,9 @@
306319
<Project Path="tests/AgentConformance.IntegrationTests/AgentConformance.IntegrationTests.csproj" />
307320
<Project Path="tests/AzureAIAgentsPersistent.IntegrationTests/AzureAIAgentsPersistent.IntegrationTests.csproj" />
308321
<Project Path="tests/CopilotStudio.IntegrationTests/CopilotStudio.IntegrationTests.csproj" />
322+
<Project Path="tests/Microsoft.Agents.AI.DurableTask.IntegrationTests/Microsoft.Agents.AI.DurableTask.IntegrationTests.csproj" />
309323
<Project Path="tests/Microsoft.Agents.AI.Hosting.AGUI.AspNetCore.IntegrationTests/Microsoft.Agents.AI.Hosting.AGUI.AspNetCore.IntegrationTests.csproj" />
324+
<Project Path="tests/Microsoft.Agents.AI.Hosting.AzureFunctions.IntegrationTests/Microsoft.Agents.AI.Hosting.AzureFunctions.IntegrationTests.csproj" />
310325
<Project Path="tests/Microsoft.Agents.AI.Mem0.IntegrationTests/Microsoft.Agents.AI.Mem0.IntegrationTests.csproj" />
311326
<Project Path="tests/Microsoft.Agents.AI.Workflows.Declarative.IntegrationTests/Microsoft.Agents.AI.Workflows.Declarative.IntegrationTests.csproj" />
312327
<Project Path="tests/OpenAIAssistant.IntegrationTests/OpenAIAssistant.IntegrationTests.csproj" />
@@ -318,8 +333,10 @@
318333
<Project Path="tests/Microsoft.Agents.AI.Abstractions.UnitTests/Microsoft.Agents.AI.Abstractions.UnitTests.csproj" />
319334
<Project Path="tests/Microsoft.Agents.AI.AGUI.UnitTests/Microsoft.Agents.AI.AGUI.UnitTests.csproj" />
320335
<Project Path="tests/Microsoft.Agents.AI.AzureAI.Persistent.UnitTests/Microsoft.Agents.AI.AzureAI.Persistent.UnitTests.csproj" />
336+
<Project Path="tests/Microsoft.Agents.AI.DurableTask.UnitTests/Microsoft.Agents.AI.DurableTask.UnitTests.csproj" />
321337
<Project Path="tests/Microsoft.Agents.AI.Hosting.A2A.UnitTests/Microsoft.Agents.AI.Hosting.A2A.UnitTests.csproj" />
322338
<Project Path="tests/Microsoft.Agents.AI.Hosting.AGUI.AspNetCore.UnitTests/Microsoft.Agents.AI.Hosting.AGUI.AspNetCore.UnitTests.csproj" />
339+
<Project Path="tests/Microsoft.Agents.AI.Hosting.AzureFunctions.UnitTests/Microsoft.Agents.AI.Hosting.AzureFunctions.UnitTests.csproj" />
323340
<Project Path="tests/Microsoft.Agents.AI.Hosting.OpenAI.UnitTests/Microsoft.Agents.AI.Hosting.OpenAI.UnitTests.csproj" />
324341
<Project Path="tests/Microsoft.Agents.AI.Hosting.UnitTests/Microsoft.Agents.AI.Hosting.UnitTests.csproj" />
325342
<Project Path="tests/Microsoft.Agents.AI.Mem0.UnitTests/Microsoft.Agents.AI.Mem0.UnitTests.csproj" />
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# .editorconfig
2+
[*.cs]
3+
4+
# See https://github.com/Azure/azure-functions-durable-extension/issues/3173
5+
dotnet_diagnostic.DURABLE0001.severity = none
6+
dotnet_diagnostic.DURABLE0002.severity = none
7+
dotnet_diagnostic.DURABLE0003.severity = none
8+
dotnet_diagnostic.DURABLE0004.severity = none
9+
dotnet_diagnostic.DURABLE0005.severity = none
10+
dotnet_diagnostic.DURABLE0006.severity = none
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<TargetFramework>net9.0</TargetFramework>
4+
<AzureFunctionsVersion>v4</AzureFunctionsVersion>
5+
<OutputType>Exe</OutputType>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
<Nullable>enable</Nullable>
8+
<!-- The Functions build tools don't like namespaces that start with a number -->
9+
<AssemblyName>SingleAgent</AssemblyName>
10+
<RootNamespace>SingleAgent</RootNamespace>
11+
</PropertyGroup>
12+
13+
<ItemGroup>
14+
<FrameworkReference Include="Microsoft.AspNetCore.App" />
15+
</ItemGroup>
16+
17+
<!-- Azure Functions packages -->
18+
<ItemGroup>
19+
<PackageReference Include="Microsoft.Azure.Functions.Worker" />
20+
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.DurableTask" />
21+
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.DurableTask.AzureManaged" />
22+
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http.AspNetCore" />
23+
<PackageReference Include="Microsoft.Azure.Functions.Worker.Sdk" />
24+
</ItemGroup>
25+
26+
<ItemGroup>
27+
<PackageReference Include="Azure.AI.OpenAI" />
28+
<PackageReference Include="Azure.Identity" />
29+
</ItemGroup>
30+
31+
<!-- Local projects that should be switched to package references when using the sample outside of this MAF repo -->
32+
<!--
33+
<ItemGroup>
34+
<PackageReference Include="Microsoft.Agents.AI.Hosting.AzureFunctions" />
35+
<PackageReference Include="Microsoft.Agents.AI.OpenAI" />
36+
</ItemGroup>
37+
-->
38+
<ItemGroup>
39+
<ProjectReference Include="..\..\..\src\Microsoft.Agents.AI.Hosting.AzureFunctions\Microsoft.Agents.AI.Hosting.AzureFunctions.csproj" />
40+
<ProjectReference Include="..\..\..\src\Microsoft.Agents.AI.OpenAI\Microsoft.Agents.AI.OpenAI.csproj" />
41+
</ItemGroup>
42+
</Project>
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// Copyright (c) Microsoft. All rights reserved.
2+
3+
using Azure;
4+
using Azure.AI.OpenAI;
5+
using Azure.Identity;
6+
using Microsoft.Agents.AI;
7+
using Microsoft.Agents.AI.Hosting.AzureFunctions;
8+
using Microsoft.Azure.Functions.Worker.Builder;
9+
using Microsoft.Extensions.Hosting;
10+
using OpenAI;
11+
12+
// Get the Azure OpenAI endpoint and deployment name from environment variables.
13+
string endpoint = Environment.GetEnvironmentVariable("AZURE_OPENAI_ENDPOINT")
14+
?? throw new InvalidOperationException("AZURE_OPENAI_ENDPOINT is not set.");
15+
string deploymentName = Environment.GetEnvironmentVariable("AZURE_OPENAI_DEPLOYMENT")
16+
?? throw new InvalidOperationException("AZURE_OPENAI_DEPLOYMENT is not set.");
17+
18+
// Use Azure Key Credential if provided, otherwise use Azure CLI Credential.
19+
string? azureOpenAiKey = System.Environment.GetEnvironmentVariable("AZURE_OPENAI_KEY");
20+
AzureOpenAIClient client = !string.IsNullOrEmpty(azureOpenAiKey)
21+
? new AzureOpenAIClient(new Uri(endpoint), new AzureKeyCredential(azureOpenAiKey))
22+
: new AzureOpenAIClient(new Uri(endpoint), new AzureCliCredential());
23+
24+
// Set up an AI agent following the standard Microsoft Agent Framework pattern.
25+
const string JokerName = "Joker";
26+
const string JokerInstructions = "You are good at telling jokes.";
27+
28+
AIAgent agent = client.GetChatClient(deploymentName).CreateAIAgent(JokerInstructions, JokerName);
29+
30+
// Configure the function app to host the AI agent.
31+
// This will automatically generate HTTP API endpoints for the agent.
32+
using IHost app = FunctionsApplication
33+
.CreateBuilder(args)
34+
.ConfigureFunctionsWebApplication()
35+
.ConfigureDurableAgents(options => options.AddAIAgent(agent))
36+
.Build();
37+
app.Run();

0 commit comments

Comments
 (0)