โš ๏ธ This blog post was created with the help of AI tools. Yes, I used a bit of magic from language models to organize my thoughts and automate the boring parts, but the geeky fun and the ๐Ÿค– in C# are 100% mine.

๐Ÿ“บ VIDEO COMING SOON โ€” stay tuned!
(Iโ€™ll embed the YouTube player here as soon as the video goes live.)

Hola friends! Bruno here ๐Ÿ™‹โ€โ™‚๏ธ โ€” Cloud Advocate at Microsoft, lover of .NET, AI, Blazor, and the occasional dog-walk debugging session with ACE ๐Ÿถ.

Today weโ€™re diving into something very cool for .NET AI developers:
๐Ÿ‘‰ How to expose your Agent Framework agents to the web using AG-UI
๐Ÿ‘‰ How Aspire orchestrates everything for you
๐Ÿ‘‰ And how this makes building multi-client, AI-powered experiences ridiculously easier

This post accompanies my 5-minute videoโ€ฆ which is coming in hot ๐Ÿ”ฅ
Until then, letโ€™s go step-by-step and explore what AG-UI brings to your .NET AI apps.


๐ŸŽฏ What Weโ€™re Building

A Web Server hosting an Agent Framework agent, orchestrated by Aspire, and consumed by two different websites via AG-UI.

Hereโ€™s the diagram that I also use in the video:

           โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
           โ”‚     Aspire App       โ”‚
           โ”‚    (Orchestrator)    โ”‚
           โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–ฒโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                       โ”‚
           โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
           โ”‚    Web Server         โ”‚
           โ”‚ (Agent Hosted Here)   โ”‚
           โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–ฒโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–ฒโ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                   โ”‚       โ”‚
          AG-UI     โ”‚       โ”‚     AG-UI
                   โ”‚       โ”‚
      โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜       โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
      โ”‚                                     โ”‚
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”                 โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  Website A     โ”‚                 โ”‚   Website B    โ”‚
โ”‚  AG-UI Client  โ”‚                 โ”‚  AG-UI Client  โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜                 โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜


๐Ÿง  What is AG-UI?

AG-UI is the Agent-User Interaction protocol used by Agent Framework apps to:

  • Stream messages (via SSE)
  • Sync agent โ†’ UI state
  • Trigger human-in-the-loop workflows
  • Connect multiple frontends to the same agent

If you’re building AI-powered web apps with .NET โ€” AG-UI is your new best friend.

๐Ÿงช Demo โ€“ Web Server Agent + Web Client + Aspire Orchestration

Weโ€™ll use the sample repo structure:

samples/
  AgentFx-AIWebChatApp-AG-UI/
    Agents/
    Web/
    AppHost/

1. Create & Publish Agent (Agents/Program.cs)

In the Agents project youโ€™ll find Program.cs like this (trimmed):

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddAGUI();
builder.Services.AddHttpClient();

var app = builder.Build();

// create the agent
var azureOpenAiEndpoint = builder.Configuration["AZURE_OPENAI_ENDPOINT"];
var openAiKey = builder.Configuration["AZURE_OPENAI_KEY"];
var client = new AzureOpenAIClient(new Uri(azureOpenAiEndpoint), new AzureKeyCredential(openAiKey)).GetChatClient();

var agent = client.AsIChatClient().CreateAIAgent(
    name: "aiwebagent",
    instructions: "You are an AI assistant..." );

app.MapAGUI("/", agent);

await app.RunAsync();

Key points

  • The AddAGUI() call wires up the AG-UI protocol endpoint.
  • MapAGUI("/") exposes the agent at the root.
  • The agent is built from Azure OpenAI client (could be swapped).

2. Web Front-end (Web/Program.cs)

In the Web projectโ€™s Program.cs we have:

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddRazorPages();
builder.Services.AddServerSideBlazor();

var aguiServerUrl = builder.Configuration["AGUI_SERVER_URL"];

builder.Services.AddHttpClient<AGUIChatClient>(client =>
    client.BaseAddress = new Uri(aguiServerUrl));

builder.Services.AddScoped(sp => {
    var chatClient = sp.GetRequiredService<AGUIChatClient>();
    return chatClient.CreateAIAgent(
        name: "web-client-agent",
        description: "Talks to remote AG-UI server");
});

var app = builder.Build();
app.UseStaticFiles();
app.UseRouting();
app.MapBlazorHub();
app.MapFallbackToPage("/_Host");
await app.RunAsync();

Key points

  • AGUI_SERVER_URL from config points to the agent host.
  • AGUIChatClient wraps HTTP + SSE to communicate with the agent.
  • The front-end is a Blazor app (could be any web tech) that uses the agent via DI.

3. Aspire Orchestration (AppHost/AppHost.cs)

In the AppHost project:

var builder = DistributedApplication.CreateBuilder(args);

var agents = builder.AddProject<Projects.Agents>("agents")
    .WithEndpoint("http", e => e.Port = 8888);

var web = builder.AddProject<Projects.Web>("web")
    .WithReference(agents)
    .WithEnvironment("AGUI_SERVER_URL", agents.GetEndpoint("http")!.Uri);

web.WithExternalHttpEndpoints();

await builder.Build().RunAsync();

Key points

  • AddProject defines the components (Agents, Web).
  • WithReference(agents) ensures Web knows about the agent project.
  • WithEnvironment("AGUI_SERVER_URL", โ€ฆ) injects the correct URL dynamically.
  • WithExternalHttpEndpoints() exposes the web front-end externally (for QA/dev).

๐Ÿ Final Thoughts

AG-UI + Agent Framework + Aspire is what I call the modern stack for .NET AI applications:

  • Agents with memory, tools, streaming, context
  • Web UI with state sync and rich interactivity
  • Full orchestration with Aspire
  • Easy deployment to Azure Container Apps or Azure App Service

Itโ€™s everything we wished we had when trying to build AI-powered web apps without reinventing the streaming / workflow / UI plumbing.


๐Ÿ“บ VIDEO COMING SOON

Stay tuned โ€” Iโ€™ll embed the YouTube video right here as soon as itโ€™s uploaded.


๐Ÿ”— Useful References

Happy coding!

Greetings

El Bruno

More posts in my blog ElBruno.com.

More info in https://beacons.ai/elbruno


2 responses to “๐Ÿš€ AG-UI + Agent Framework + .NET + Aspire: Web-Enabling Your Intelligent Agents (Blog + Demo + Code!)”

  1. […] ๐Ÿš€ AG-UI + Agent Framework + .NET + Aspire: Web-Enabling Your Intelligent Agents (Blog + Demo + Co… (Bruno Capuano) […]

    Like

  2. […] ๐Ÿš€ AGโบUI + Agent Framework + .NETย Aspire โ€“ Web-enabling your Intelligent Agents (18 Nov 2025) โ€“ Shows how to integrate Agent Framework agents into web applications (using .NET Aspire and a web UI dubbed AG UI). This includes a demo of exposing agents through web endpoints and live web chat. Link: https://elbruno.com/2025/11/18/%F0%9F%9A%80-ag-ui-agent-framework-net-aspire-web-enabling-your-intel&#8230; […]

    Like

Leave a comment

Discover more from El Bruno

Subscribe now to keep reading and get access to the full archive.

Continue reading