* Initial plan * Update code for Microsoft.Extensions.AI.Abstractions 10.4.0 breaking changes - Rename FunctionApprovalRequestContent → ToolApprovalRequestContent - Rename FunctionApprovalResponseContent → ToolApprovalResponseContent - Rename UserInputRequestContent → ToolApprovalRequestContent - Rename UserInputResponseContent → ToolApprovalResponseContent - Update .FunctionCall property → .ToolCall with FunctionCallContent casts where needed - Update .Id property → .RequestId on the renamed types - Rename FunctionApprovalRequestEventGenerator → ToolApprovalRequestEventGenerator - Rename FunctionApprovalResponseEventGenerator → ToolApprovalResponseEventGenerator Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Update OpenAI 2.9.1, ME.AI 10.4.0, fix breaking API changes Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com> * Fix remaining ME.AI 10.4.0 breaking changes: MCP approval types, .Output→.Outputs Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com> * Use pattern matching with `when` for ToolApprovalRequestContent/FunctionCallContent Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com> * Update Azure.AI.OpenAI to 2.9.0-beta.1 Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com> * Fix remaining GetResponsesClient(model) build failures for Azure.AI.OpenAI 2.9.0-beta.1 Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com> * Address review feedback: remove redundant type checks in TestRequestAgent.cs and fix error message in AIAgentHostExecutor.cs Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com> * Update Azure.AI.Projects to 2.0.0-beta.2 with namespace migration - Azure.AI.Projects 2.0.0-beta.1 → 2.0.0-beta.2 - Azure.AI.Projects.OpenAI → Azure.AI.Extensions.OpenAI (transitive) - Agent types moved to Azure.AI.Projects.Agents namespace - AgentRecord.Versions.Latest → AgentRecord.GetLatestVersion() - OpenAPIFunctionDefinition → OpenApiFunctionDefinition - BingCustomSearchToolParameters → BingCustomSearchToolOptions - MemorySearchPreviewTool.UpdateDelay → UpdateDelayInSecs - Azure.Identity 1.17.1 → 1.19.0 - Microsoft.Identity.Client.Extensions.Msal 4.78.0 → 4.83.1 Co-authored-by: rogerbarreto <19890735+rogerbarreto@users.noreply.github.com> * Fix remaining type renames for Azure.AI.Projects 2.0.0-beta.2 - BrowserAutomationToolParameters → BrowserAutomationToolOptions - MemoryUpdateOptions.UpdateDelay stays as UpdateDelay (not renamed) - WaitForMemoriesUpdateAsync parameter order: pollingInterval before options - AIProjectAgentsOperations → AgentsClient Co-authored-by: rogerbarreto <19890735+rogerbarreto@users.noreply.github.com> * Fix format errors and OpenTelemetry test for ME.AI 10.4.0 - Remove unused 'using Azure.AI.Extensions.OpenAI' and fix import ordering in Agent_With_AzureAIProject/Program.cs - Update OpenTelemetryAgentTests: gen_ai.tool.definitions is now always emitted regardless of EnableSensitiveData per ME.AI 10.4.0 change (dotnet/extensions#7346). Tool definitions are not considered sensitive. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Fix GetRepoFolder() to work in git worktrees Use 'workflow-samples' directory as repo root marker instead of '.git', which fails in worktrees (.git is a file) and also matches too early when a '.github' folder exists in subdirectories. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Fix formatting: remove unused usings and fix import ordering dotnet format applied across 59 impacted projects. Primarily removes unnecessary 'using Azure.AI.Projects' where Azure.AI.Projects.Agents provides all needed types, and fixes import ordering per editorconfig. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Disable AzureAIAgentsPersistent integration tests (#4769) Azure.AI.Agents.Persistent 1.2.0-beta.9 references McpServerToolApprovalResponseContent which was removed in ME.AI 10.4.0 (renamed to ToolApprovalResponseContent), causing TypeLoadException at runtime. Mark all 6 test classes with IntegrationDisabled trait until Persistent ships a version targeting ME.AI 10.4.0+. Upstream fix: https://github.com/Azure/azure-sdk-for-net/pull/56929 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Add README with compatibility note for AzureAI.Persistent (#4769) Documents that Azure.AI.Agents.Persistent 1.2.0-beta.9 is only compatible with ME.AI ≤10.3.0 and OpenAI ≤2.8.0 due to type renames in ME.AI 10.4.0. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Fix file encoding: restore UTF-8 BOM on Persistent test files Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Mark AzureAI.Persistent as IsPackable=false (#4769) Prevent shipping until Azure.AI.Agents.Persistent targets ME.AI 10.4.0+. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Moving IsPackable after import --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com> Co-authored-by: rogerbarreto <19890735+rogerbarreto@users.noreply.github.com>
AG-UI Getting Started Samples
This directory contains samples that demonstrate how to build AG-UI (Agent UI Protocol) servers and clients using the Microsoft Agent Framework.
Prerequisites
- .NET 9.0 or later
- Azure OpenAI service endpoint and deployment configured
- Azure CLI installed and authenticated (
az login) - User has the
Cognitive Services OpenAI Contributorrole for the Azure OpenAI resource
Environment Variables
All samples require the following environment variables:
export AZURE_OPENAI_ENDPOINT="https://your-resource.openai.azure.com/"
export AZURE_OPENAI_DEPLOYMENT_NAME="gpt-4o-mini"
For the client samples, you can optionally set:
export AGUI_SERVER_URL="http://localhost:8888"
Samples
Step01_GettingStarted
A basic AG-UI server and client that demonstrate the foundational concepts.
Server (Step01_GettingStarted/Server)
A basic AG-UI server that hosts an AI agent accessible via HTTP. Demonstrates:
- Creating an ASP.NET Core web application
- Setting up an AG-UI server endpoint with
MapAGUI - Creating an AI agent from an Azure OpenAI chat client
- Streaming responses via Server-Sent Events (SSE)
Run the server:
cd Step01_GettingStarted/Server
dotnet run --urls http://localhost:8888
Client (Step01_GettingStarted/Client)
An interactive console client that connects to an AG-UI server. Demonstrates:
- Creating an AG-UI client with
AGUIChatClient - Managing conversation threads
- Streaming responses with
RunStreamingAsync - Displaying colored console output for different content types
- Supporting both interactive and automated modes
Prerequisites: The Step01_GettingStarted server (or any AG-UI server) must be running.
Run the client:
cd Step01_GettingStarted/Client
dotnet run
Type messages and press Enter to interact with the agent. Type :q or quit to exit.
Step02_BackendTools
An AG-UI server with function tools that execute on the backend.
Server (Step02_BackendTools/Server)
Demonstrates:
- Creating function tools using
AIFunctionFactory.Create - Using
[Description]attributes for tool documentation - Defining explicit request/response types for type safety
- Setting up JSON serialization contexts for source generation
- Backend tool rendering (tools execute on the server)
Run the server:
cd Step02_BackendTools/Server
dotnet run --urls http://localhost:8888
Client (Step02_BackendTools/Client)
A client that works with the backend tools server. Try asking: "Find Italian restaurants in Seattle" or "Search for Mexican food in Portland".
Run the client:
cd Step02_BackendTools/Client
dotnet run
Step03_FrontendTools
Demonstrates frontend tool rendering (tools defined on client, executed on server).
Server (Step03_FrontendTools/Server)
A basic AG-UI server that accepts tool definitions from the client.
Run the server:
cd Step03_FrontendTools/Server
dotnet run --urls http://localhost:8888
Client (Step03_FrontendTools/Client)
A client that defines and sends tools to the server for execution.
Run the client:
cd Step03_FrontendTools/Client
dotnet run
Step04_HumanInLoop
Demonstrates human-in-the-loop approval workflows for sensitive operations. This sample includes both a server and client component.
Server (Step04_HumanInLoop/Server)
An AG-UI server that implements approval workflows. Demonstrates:
- Wrapping tools with
ApprovalRequiredAIFunction - Converting
FunctionApprovalRequestContentto approval requests - Middleware pattern with
ServerFunctionApprovalServerAgent - Complete function call capture and restoration
Run the server:
cd Step04_HumanInLoop/Server
dotnet run --urls http://localhost:8888
Client (Step04_HumanInLoop/Client)
An interactive client that handles approval requests from the server. Demonstrates:
- Using
ServerFunctionApprovalClientAgentmiddleware - Detecting
FunctionApprovalRequestContent - Displaying approval details to users
- Prompting for approval/rejection
- Sending approval responses with
FunctionApprovalResponseContent - Resuming conversation after approval
Run the client:
cd Step04_HumanInLoop/Client
dotnet run
Try asking the agent to perform sensitive operations like "Approve expense report EXP-12345".
Step05_StateManagement
An AG-UI server and client that demonstrate state management with predictive updates.
Server (Step05_StateManagement/Server)
Demonstrates:
- Defining state schemas using C# records
- Using
SharedStateAgentmiddleware for state management - Streaming predictive state updates with
AgentStatecontent - Managing shared state between client and server
- Using JSON serialization contexts for state types
Run the server:
cd Step05_StateManagement/Server
dotnet run
The server runs on port 8888 by default.
Client (Step05_StateManagement/Client)
A client that displays and updates shared state from the server. Try asking: "Create a recipe for chocolate chip cookies" or "Suggest a pasta dish".
Run the client:
cd Step05_StateManagement/Client
dotnet run
How AG-UI Works
Server-Side
- Client sends HTTP POST request with messages
- ASP.NET Core endpoint receives the request via
MapAGUI - Agent processes messages using Agent Framework
- Responses are streamed back as Server-Sent Events (SSE)
Client-Side
AGUIAgentsends HTTP POST request to server- Server responds with SSE stream
- Client parses events into
AgentResponseUpdateobjects - Updates are displayed based on content type
ConversationIdmaintains conversation context
Protocol Features
- HTTP POST for requests
- Server-Sent Events (SSE) for streaming responses
- JSON for event serialization
- Thread IDs (as
ConversationId) for conversation context - Run IDs (as
ResponseId) for tracking individual executions
Troubleshooting
Connection Refused
Ensure the server is running before starting the client:
# Terminal 1
cd AGUI_Step01_ServerBasic
dotnet run --urls http://localhost:8888
# Terminal 2 (after server starts)
cd AGUI_Step02_ClientBasic
dotnet run
Port Already in Use
If port 8888 is already in use, choose a different port:
# Server
dotnet run --urls http://localhost:8889
# Client (set environment variable)
export AGUI_SERVER_URL="http://localhost:8889"
dotnet run
Authentication Errors
Make sure you're authenticated with Azure:
az login
Verify you have the Cognitive Services OpenAI Contributor role on the Azure OpenAI resource.
Missing Environment Variables
If you see "AZURE_OPENAI_ENDPOINT is not set" errors, ensure environment variables are set in your current shell session before running the samples.
Streaming Not Working
Check that the client timeout is sufficient (default is 60 seconds). For long-running operations, you may need to increase the timeout in the client code.
Next Steps
After completing these samples, explore more AG-UI capabilities:
Currently Available in C#
The samples above demonstrate the AG-UI features currently available in C#:
- ✅ Basic Server and Client: Setting up AG-UI communication
- ✅ Backend Tool Rendering: Function tools that execute on the server
- ✅ Streaming Responses: Real-time Server-Sent Events
- ✅ State Management: State schemas with predictive updates
- ✅ Human-in-the-Loop: Approval workflows for sensitive operations
Coming Soon to C#
The following advanced AG-UI features are available in the Python implementation and are planned for future C# releases:
- ⏳ Generative UI: Custom UI component generation
- ⏳ Advanced State Patterns: Complex state synchronization scenarios
For the most up-to-date AG-UI features, see the Python samples for working examples.
Related Documentation
- AG-UI Overview - Complete AG-UI documentation
- Getting Started Tutorial - Step-by-step walkthrough
- Backend Tool Rendering - Function tools tutorial
- Human-in-the-Loop - Approval workflows tutorial
- State Management - State management tutorial
- Agent Framework Overview - Core framework concepts