diff --git a/dotnet/samples/01-get-started/06_host_your_agent/DurableTriggerDiscovery.cs b/dotnet/samples/01-get-started/06_host_your_agent/DurableTriggerDiscovery.cs new file mode 100644 index 0000000000..e90245fceb --- /dev/null +++ b/dotnet/samples/01-get-started/06_host_your_agent/DurableTriggerDiscovery.cs @@ -0,0 +1,17 @@ +// Copyright (c) Microsoft. All rights reserved. + +using Microsoft.Azure.Functions.Worker; +using Microsoft.DurableTask; + +namespace HostedAgent; + +public static class DurableTriggerDiscovery +{ + [Function(nameof(DurableTriggerDiscovery))] + public static Task RunAsync([OrchestrationTrigger] TaskOrchestrationContext context) + { + // The isolated worker SDK indexes Durable triggers from the app assembly. + // Hosting-only apps still need one local orchestrator for discovery. + return Task.CompletedTask; + } +} diff --git a/dotnet/samples/04-hosting/DurableAgents/AzureFunctions/README.md b/dotnet/samples/04-hosting/DurableAgents/AzureFunctions/README.md index 2839c67587..fd46184651 100644 --- a/dotnet/samples/04-hosting/DurableAgents/AzureFunctions/README.md +++ b/dotnet/samples/04-hosting/DurableAgents/AzureFunctions/README.md @@ -141,6 +141,8 @@ func start The Azure Functions app will be available at `http://localhost:7071`. +If the hosted agent routes are not listed when the app starts, make sure the app defines at least one local `[OrchestrationTrigger]` function. In .NET isolated worker apps, the Durable extension is indexed from triggers discovered in the app assembly. + ### Test the Azure Functions app The README.md file in each sample directory contains instructions for testing the sample. Each sample also includes a `demo.http` file that can be used to test the sample from the command line. These files can be opened in VS Code with the [REST Client](https://marketplace.visualstudio.com/items?itemName=humao.rest-client) extension or in the Visual Studio IDE. diff --git a/dotnet/src/Microsoft.Agents.AI.Hosting.AzureFunctions/README.md b/dotnet/src/Microsoft.Agents.AI.Hosting.AzureFunctions/README.md index 6cacc5adff..099b46fdb0 100644 --- a/dotnet/src/Microsoft.Agents.AI.Hosting.AzureFunctions/README.md +++ b/dotnet/src/Microsoft.Agents.AI.Hosting.AzureFunctions/README.md @@ -61,6 +61,18 @@ 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`. +> [!NOTE] +> In .NET isolated Azure Functions apps, the worker SDK discovers Durable Functions triggers from the app assembly. If your app only hosts agents through `ConfigureDurableAgents(...)` and does not define any Durable orchestrator functions, add a small `[OrchestrationTrigger]` function in your app assembly so the Durable extension is indexed. + +```csharp +public static class DurableTriggerDiscovery +{ + [Function(nameof(DurableTriggerDiscovery))] + public static Task RunAsync([OrchestrationTrigger] TaskOrchestrationContext context) + => Task.CompletedTask; +} +``` + ### Orchestrating hosted agents This package also provides a set of extension methods such as `GetAgent` on the [`TaskOrchestrationContext`](https://learn.microsoft.com/dotnet/api/microsoft.durabletask.taskorchestrationcontext) class for interacting with hosted agents within orchestrations.