-
|
Could you provide a code sample showing how to integrate:
It also seems like app.MapAGUI("/", agent) from Microsoft.Agents.AI.Hosting.AGUI.AspNetCore is designed for a standard .NET API host - not for Azure Durable Functions. How should this be wired up correctly in a Durable Functions context? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
|
The behavior you are observing is by design. The good news is the architecture is already demonstrated in the repository — it is the Recommended architectureThree components in the Functions app: 1. HTTP-trigger function that starts the run and streamsA standard HTTP trigger (not AIAgent agentProxy = durableClient.AsDurableAgentProxy(context, "TravelPlanner");
AgentSession session = await agentProxy.CreateSessionAsync(ct);
string conversationId = session.GetService<AgentSessionId>().ToString();
// Fire-and-forget: the orchestration runs independently of the HTTP request lifetime.
await agentProxy.RunAsync(
prompt,
session,
new DurableAgentRunOptions { IsFireAndForget = true },
ct);
return await StreamToClientAsync(conversationId, cursor: null, httpContext: request.HttpContext, ct);
2.
|
| Layer | Responsibility |
|---|---|
IAgentResponseHandler |
Project each AgentResponseUpdate into one or more AG-UI events. Map update.Text → TEXT_MESSAGE_CONTENT, update.Contents.OfType<FunctionCallContent>() → TOOL_CALL_*, role boundaries → TEXT_MESSAGE_START / _END, and completion → RUN_FINISHED. Serialize as JSON and append to the durable log. |
| HTTP stream loop | Set Content-Type: text/event-stream, write each AG-UI JSON event as an SSE data: …\n\n frame, and emit the cursor as the SSE id: field so client reconnects resume correctly. |
CopilotKit's Angular runtime treats the endpoint as an opaque AG-UI-over-SSE source — the Durable Functions host is invisible to it.
Alternative: ASP.NET Core front door with Durable Task behind it
If Azure Functions is not a hard requirement, an alternative topology is to host the AG-UI endpoint on ASP.NET Core and use Microsoft.Agents.AI.DurableTask only for the orchestration tier. IDurableAgentClient and AsDurableAgentProxy are not Functions-specific. In that configuration:
app.MapAGUI("/", durableAgentProxy);remains the front door, and the Durable Task client invokes long-running work in the background. This is the simplest path when you need Durable Task's orchestration guarantees but do not have an organizational requirement to host on Functions specifically.
Summary
| Requirement | Recommended pattern |
|---|---|
| Multi-day orchestrations + AG-UI on Azure Functions | Manual SSE HTTP-trigger pattern from 08_ReliableStreaming, with the on-the-wire format replaced by AG-UI events. No MapAGUI. |
Durable Task + MapAGUI as-is |
Host on ASP.NET Core, wrap the agent with DurableAIAgentProxy. |
| Short-lived chat only | MapAGUI on ASP.NET Core; no Durable Task required. |
For your stated requirements (Angular + CopilotKit + multi-day operations on Functions), Option 1 is the correct path. An end-to-end sample combining Durable Functions, AG-UI, and CopilotKit does not exist in the repository today, but every building block is present and 08_ReliableStreaming is a substantial portion of the implementation.
Beta Was this translation helpful? Give feedback.
-
|
@jluocsa Thank you for the very detailed explanation. Durable Function is not a strict requirement. DurableAgentProxy is a very interesting solution. Is it going to work for a use case when more than one agent is involved (e.g., PlannerAgent and ExecutorAgent)? I also noticed there is a way to set up AllowBackgroundResponses. Is it the same as DurableAgentProxy? AgentRunOptions options = new() |
Beta Was this translation helpful? Give feedback.
-
|
@jluocsa The AsDurableAgentProxy solution is not working because of the error “streaming is not supported for durable agents,” which I get when trying to pass the proxy agent into the MapAGUI method. I tried to implement my own DurableStreamingBridge on top of the proxy agent, but faced a problem getting the conversationId and tools are not being passed to the AI model either. |
Beta Was this translation helpful? Give feedback.
The behavior you are observing is by design.
app.MapAGUI(...)ships inMicrosoft.Agents.AI.Hosting.AGUI.AspNetCoreand binds to ASP.NET Core endpoint routing, which is not available in the Azure Functions Worker host. There is noMapAGUIoverload for Azure Functions today, so for this scenario the integration is assembled from existing primitives.The good news is the architecture is already demonstrated in the repository — it is the
08_ReliableStreamingsample. The wire format in that sample is plain SSE; for CopilotKit you substitute the AG-UI event format. Below is the recommended architecture and the specific extension points.Recommended architecture