Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
a4a6cfd
docs: remove comma splice in tool-approval.md
lokitoth Mar 31, 2026
77b5a13
docs: Remove duplicate codeblock in tool-approval.md
lokitoth Mar 31, 2026
c59cb85
Merge pull request #945 from MicrosoftDocs/docs/agents/tool-approval
lokitoth Mar 31, 2026
ca2816a
docs: Remove duplicate code block
lokitoth Mar 31, 2026
9eaaec9
fix header language
lokitoth Mar 31, 2026
8762bbe
Merge pull request #946 from MicrosoftDocs/docs/agents/file-search
lokitoth Mar 31, 2026
e56d69b
docs: Link to topic-specific .NET sample project
lokitoth Mar 31, 2026
cd9b6a2
Merge pull request #947 from MicrosoftDocs/docs/agents/hosted-mcp
lokitoth Mar 31, 2026
f0d2846
docs: move full sample link to tip
lokitoth Mar 31, 2026
3cfcbaf
Add fixes for overview page (#949)
westey-m Mar 31, 2026
22fe11e
Add C# runtime-context samples and migrate middleware docs to AIProje…
rogerbarreto Mar 31, 2026
377eb7d
Merge pull request #948 from MicrosoftDocs/docs/agents/local-mcp
lokitoth Mar 31, 2026
dee0b1a
Merge pull request #951 from MicrosoftDocs/fix-middleware-docs-002
rogerbarreto Mar 31, 2026
0314de6
fix: correct critical provider documentation issues
giles17 Mar 31, 2026
470661f
fix: replace geopolitical term in copilot-studio example
giles17 Mar 31, 2026
75beb14
Fix doc inaccuracies in various places (#954)
TaoChenOSU Mar 31, 2026
fb180ec
Merge pull request #953 from giles17/fix/critical-provider-docs
giles17 Apr 1, 2026
169c486
Fixes for RAG docs (#952)
westey-m Apr 1, 2026
dc2bad0
Adds sample documentation for two separate Neo4j context providers fo…
westey-m Apr 1, 2026
ac568d7
Fix for csharp declarative agent docs (#955)
westey-m Apr 1, 2026
7b460a7
Merge latest changes to live (#956)
westey-m Apr 1, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 42 additions & 14 deletions agent-framework/agents/declarative.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,53 @@ Declarative agents allow you to define agent configuration using YAML or JSON fi
The following example shows how to create a declarative agent from a YAML configuration:

```csharp
using System;
using System.IO;
using Azure.AI.OpenAI;
using Azure.Identity;
using Microsoft.Agents.AI;
using Microsoft.Extensions.AI;

// Load agent configuration from a YAML file
var yamlContent = File.ReadAllText("agent-config.yaml");

// Create the agent from the YAML definition
AIAgent agent = AgentFactory.CreateFromYaml(
yamlContent,
new AzureOpenAIClient(
new Uri("https://<myresource>.openai.azure.com"),
new AzureCliCredential()));

// Run the declarative agent
Console.WriteLine(await agent.RunAsync("Why is the sky blue?"));
// Create the chat client
IChatClient chatClient = new AzureOpenAIClient(
new Uri("https://<myresource>.openai.azure.com"),
new DefaultAzureCredential())
.GetChatClient("gpt-4o-mini")
.AsIChatClient();

// Define the agent using a YAML definition.
var yamlDefinition =
"""
kind: Prompt
name: Assistant
description: Helpful assistant
instructions: You are a helpful assistant. You answer questions in the language specified by the user. You return your answers in a JSON format.
model:
options:
temperature: 0.9
topP: 0.95
outputSchema:
properties:
language:
type: string
required: true
description: The language of the answer.
answer:
type: string
required: true
description: The answer text.
""";

// Create the agent from the YAML definition.
var agentFactory = new ChatClientPromptAgentFactory(chatClient);
var agent = await agentFactory.CreateFromYamlAsync(yamlDefinition);

// Invoke the agent and output the text result.
Console.WriteLine(await agent!.RunAsync("Tell me a joke about a pirate in English."));

// Invoke the agent with streaming support.
await foreach (var update in agent!.RunStreamingAsync("Tell me a joke about a pirate in French."))
{
Console.WriteLine(update);
}
```

:::zone-end
Expand Down
5 changes: 2 additions & 3 deletions agent-framework/agents/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ The Microsoft Agent Framework provides support for several types of agents to ac
::: zone pivot="programming-language-csharp"
All agents are derived from a common base class, `AIAgent`, which provides a consistent interface for all agent types. This allows for building common, agent agnostic, higher level functionality such as multi-agent orchestrations.
::: zone-end

::: zone pivot="programming-language-python"
All agents are derived from a common base class, `Agent`, which provides a consistent interface for all agent types. This allows for building common, agent agnostic, higher level functionality such as multi-agent orchestrations.
::: zone-end
Expand All @@ -28,7 +29,7 @@ All agents in the Microsoft Agent Framework execute using a structured runtime m

![AI Agent Diagram](../media/agent.svg)

> [!IMPORTANT]
> [!WARNING]
> If you use Microsoft Agent Framework to build applications that operate with third-party servers or agents, you do so at your own risk. We recommend reviewing all data being shared with third-party servers or agents and being cognizant of third-party practices for retention and location of data. It is your responsibility to manage whether your data will flow outside of your organization's Azure compliance and geographic boundaries and any related implications.

::: zone pivot="programming-language-csharp"
Expand Down Expand Up @@ -66,7 +67,6 @@ To make creating these agents even easier, Agent Framework provides helpers for
|[Anthropic](./providers/anthropic.md)|An agent that uses a Claude model via the Anthropic Service as its backend.|No|Yes|
|[OpenAI ChatCompletion](./providers/openai.md)|An agent that uses the OpenAI ChatCompletion service.|No|Yes|
|[OpenAI Responses](./providers/openai.md)|An agent that uses the OpenAI Responses service.|Yes|Yes|
|[OpenAI Assistants](./providers/openai.md)|An agent that uses the OpenAI Assistants service.|Yes|No|
|[Any other `IChatClient`](./providers/custom.md)|You can also use any other [`Microsoft.Extensions.AI.IChatClient`](/dotnet/ai/microsoft-extensions-ai#the-ichatclient-interface) implementation to create an agent.|Varies|Varies|

## Complex custom agents
Expand Down Expand Up @@ -261,7 +261,6 @@ For detailed examples, see the agent-specific documentation sections below.
|[Azure OpenAI Assistants](./providers/azure-openai.md)|An agent that uses the Azure OpenAI Assistants service.|Yes|
|[OpenAI Chat Completion](./providers/openai.md)|An agent that uses the OpenAI Chat Completion service.|No|
|[OpenAI Responses](./providers/openai.md)|An agent that uses the OpenAI Responses service.|Yes|
|[OpenAI Assistants](./providers/openai.md)|An agent that uses the OpenAI Assistants service.|Yes|
|[Anthropic Claude](./providers/anthropic.md)|An agent that uses Anthropic Claude models.|No|
|[Amazon Bedrock](https://github.com/microsoft/agent-framework/tree/main/python/packages/bedrock)|An agent that uses Amazon Bedrock models through the Agent Framework Bedrock chat client.|No|
|[GitHub Copilot](./providers/github-copilot.md)|An agent that uses the GitHub Copilot SDK backend.|No|
Expand Down
16 changes: 10 additions & 6 deletions agent-framework/agents/middleware/agent-vs-run-scope.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ using System.Linq;
using System.Runtime.CompilerServices;
using System.Threading;
using System.Threading.Tasks;
using Azure.AI.OpenAI;
using Azure.AI.Projects;
using Azure.Identity;
using Microsoft.Agents.AI;
using Microsoft.Extensions.AI;
Expand Down Expand Up @@ -65,11 +65,12 @@ async IAsyncEnumerable<AgentResponseUpdate> SecurityStreamingMiddleware(
}
}

AIAgent baseAgent = new AzureOpenAIClient(
new Uri("https://<myresource>.openai.azure.com"),
new AzureCliCredential())
.GetChatClient("gpt-4o-mini")
.AsAIAgent(instructions: "You are a helpful assistant.");
AIAgent baseAgent = new AIProjectClient(
new Uri("<your-foundry-project-endpoint>"),
new DefaultAzureCredential())
.AsAIAgent(
model: "gpt-4o-mini",
instructions: "You are a helpful assistant.");

// Register middleware at the agent level
var agentWithMiddleware = baseAgent
Expand All @@ -80,6 +81,9 @@ var agentWithMiddleware = baseAgent
Console.WriteLine(await agentWithMiddleware.RunAsync("What's the weather in Paris?"));
```

> [!WARNING]
> `DefaultAzureCredential` is convenient for development but requires careful consideration in production. In production, consider using a specific credential (e.g., `ManagedIdentityCredential`) to avoid latency issues, unintended credential probing, and potential security risks from fallback mechanisms.

### Run-level middleware

Run-level middleware uses the same builder pattern, applied inline for a specific invocation:
Expand Down
23 changes: 14 additions & 9 deletions agent-framework/agents/middleware/chat-middleware.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Azure.AI.OpenAI;
using Azure.AI.Projects;
using Azure.Identity;
using Microsoft.Agents.AI;
using Microsoft.Extensions.AI;
Expand All @@ -48,18 +48,23 @@ async Task<ChatResponse> LoggingChatMiddleware(
}

// Register IChatClient middleware using the client factory
var agent = new AzureOpenAIClient(
new Uri("https://<myresource>.openai.azure.com"),
new AzureCliCredential())
.GetChatClient("gpt-4o-mini")
.AsAIAgent("You are a helpful assistant.", clientFactory: (chatClient) => chatClient
.AsBuilder()
.Use(getResponseFunc: LoggingChatMiddleware, getStreamingResponseFunc: null)
.Build());
var agent = new AIProjectClient(
new Uri("<your-foundry-project-endpoint>"),
new DefaultAzureCredential())
.AsAIAgent(
model: "gpt-4o-mini",
instructions: "You are a helpful assistant.",
clientFactory: (chatClient) => chatClient
.AsBuilder()
.Use(getResponseFunc: LoggingChatMiddleware, getStreamingResponseFunc: null)
.Build());

Console.WriteLine(await agent.RunAsync("Hello, how are you?"));
```

> [!WARNING]
> `DefaultAzureCredential` is convenient for development but requires careful consideration in production. In production, consider using a specific credential (e.g., `ManagedIdentityCredential`) to avoid latency issues, unintended credential probing, and potential security risks from fallback mechanisms.

> [!NOTE]
> For more information about `IChatClient` middleware, see [Custom IChatClient middleware](/dotnet/ai/microsoft-extensions-ai#custom-ichatclient-middleware).

Expand Down
39 changes: 24 additions & 15 deletions agent-framework/agents/middleware/defining-middleware.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,25 +26,27 @@ First, create a basic agent with a function tool.
```csharp
using System;
using System.ComponentModel;
using Azure.AI.OpenAI;
using Azure.AI.Projects;
using Azure.Identity;
using Microsoft.Agents.AI;
using Microsoft.Extensions.AI;
using OpenAI;

[Description("The current datetime offset.")]
static string GetDateTime()
=> DateTimeOffset.Now.ToString();

AIAgent baseAgent = new AzureOpenAIClient(
new Uri("https://<myresource>.openai.azure.com"),
new AzureCliCredential())
.GetChatClient("gpt-4o-mini")
AIAgent baseAgent = new AIProjectClient(
new Uri("<your-foundry-project-endpoint>"),
new DefaultAzureCredential())
.AsAIAgent(
model: "gpt-4o-mini",
instructions: "You are an AI assistant that helps people find information.",
tools: [AIFunctionFactory.Create(GetDateTime, name: nameof(GetDateTime))]);
```

> [!WARNING]
> `DefaultAzureCredential` is convenient for development but requires careful consideration in production. In production, consider using a specific credential (e.g., `ManagedIdentityCredential`) to avoid latency issues, unintended credential probing, and potential security risks from fallback mechanisms.

## Step 2: Create Your Agent Run Middleware

Next, create a function that will get invoked for each agent run.
Expand Down Expand Up @@ -178,9 +180,12 @@ To add middleware to your <xref:Microsoft.Extensions.AI.IChatClient>, you can us
After adding the middleware, you can use the `IChatClient` with your agent as usual.

```csharp
var chatClient = new AzureOpenAIClient(new Uri("https://<myresource>.openai.azure.com"), new AzureCliCredential())
.GetChatClient("gpt-4o-mini")
.AsIChatClient();
var chatClient = new AIProjectClient(
new Uri("<your-foundry-project-endpoint>"),
new DefaultAzureCredential())
.GetProjectOpenAIClient()
.GetResponsesClient()
.AsIChatClient("gpt-4o-mini");

var middlewareEnabledChatClient = chatClient
.AsBuilder()
Expand All @@ -194,12 +199,16 @@ var agent = new ChatClientAgent(middlewareEnabledChatClient, instructions: "You
an agent via one of the helper methods on SDK clients.

```csharp
var agent = new AzureOpenAIClient(new Uri("https://<myresource>.openai.azure.com"), new AzureCliCredential())
.GetChatClient("gpt-4o-mini")
.AsAIAgent("You are a helpful assistant.", clientFactory: (chatClient) => chatClient
.AsBuilder()
.Use(getResponseFunc: CustomChatClientMiddleware, getStreamingResponseFunc: null)
.Build());
var agent = new AIProjectClient(
new Uri("<your-foundry-project-endpoint>"),
new DefaultAzureCredential())
.AsAIAgent(
model: "gpt-4o-mini",
instructions: "You are a helpful assistant.",
clientFactory: (chatClient) => chatClient
.AsBuilder()
.Use(getResponseFunc: CustomChatClientMiddleware, getStreamingResponseFunc: null)
.Build());
```

::: zone-end
Expand Down
16 changes: 10 additions & 6 deletions agent-framework/agents/middleware/exception-handling.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using Azure.AI.OpenAI;
using Azure.AI.Projects;
using Azure.Identity;
using Microsoft.Agents.AI;
using Microsoft.Extensions.AI;
Expand Down Expand Up @@ -54,11 +54,12 @@ async Task<AgentResponse> ExceptionHandlingMiddleware(
}
}

AIAgent agent = new AzureOpenAIClient(
new Uri("https://<myresource>.openai.azure.com"),
new AzureCliCredential())
.GetChatClient("gpt-4o-mini")
.AsAIAgent(instructions: "You are a helpful assistant.");
AIAgent agent = new AIProjectClient(
new Uri("<your-foundry-project-endpoint>"),
new DefaultAzureCredential())
.AsAIAgent(
model: "gpt-4o-mini",
instructions: "You are a helpful assistant.");

var safeAgent = agent
.AsBuilder()
Expand All @@ -68,6 +69,9 @@ var safeAgent = agent
Console.WriteLine(await safeAgent.RunAsync("Get user statistics"));
```

> [!WARNING]
> `DefaultAzureCredential` is convenient for development but requires careful consideration in production. In production, consider using a specific credential (e.g., `ManagedIdentityCredential`) to avoid latency issues, unintended credential probing, and potential security risks from fallback mechanisms.

:::zone-end

:::zone pivot="programming-language-python"
Expand Down
25 changes: 16 additions & 9 deletions agent-framework/agents/middleware/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,12 @@ var middlewareEnabledAgent = originalAgent
`IChatClient` middleware can be registered on an `IChatClient` before it is used with a `ChatClientAgent`, by using the chat client builder pattern.

```csharp
var chatClient = new AzureOpenAIClient(new Uri("https://<myresource>.openai.azure.com"), new DefaultAzureCredential())
.GetChatClient(deploymentName)
.AsIChatClient();
var chatClient = new AIProjectClient(
new Uri("<your-foundry-project-endpoint>"),
new DefaultAzureCredential())
.GetProjectOpenAIClient()
.GetResponsesClient()
.AsIChatClient(deploymentName);

var middlewareEnabledChatClient = chatClient
.AsBuilder()
Expand All @@ -62,12 +65,16 @@ var agent = new ChatClientAgent(middlewareEnabledChatClient, instructions: "You
an agent via one of the helper methods on SDK clients.

```csharp
var agent = new AzureOpenAIClient(new Uri(endpoint), new DefaultAzureCredential())
.GetChatClient(deploymentName)
.AsAIAgent("You are a helpful assistant.", clientFactory: (chatClient) => chatClient
.AsBuilder()
.Use(getResponseFunc: CustomChatClientMiddleware, getStreamingResponseFunc: null)
.Build());
var agent = new AIProjectClient(
new Uri("<your-foundry-project-endpoint>"),
new DefaultAzureCredential())
.AsAIAgent(
model: deploymentName,
instructions: "You are a helpful assistant.",
clientFactory: (chatClient) => chatClient
.AsBuilder()
.Use(getResponseFunc: CustomChatClientMiddleware, getStreamingResponseFunc: null)
.Build());
```

## Agent Run Middleware
Expand Down
16 changes: 10 additions & 6 deletions agent-framework/agents/middleware/result-overrides.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Azure.AI.OpenAI;
using Azure.AI.Projects;
using Azure.Identity;
using Microsoft.Agents.AI;
using Microsoft.Extensions.AI;
Expand Down Expand Up @@ -52,11 +52,12 @@ async Task<AgentResponse> ResultOverrideMiddleware(
return new AgentResponse(modifiedMessages);
}

AIAgent agent = new AzureOpenAIClient(
new Uri("https://<myresource>.openai.azure.com"),
new AzureCliCredential())
.GetChatClient("gpt-4o-mini")
.AsAIAgent(instructions: "You are a helpful weather assistant.");
AIAgent agent = new AIProjectClient(
new Uri("<your-foundry-project-endpoint>"),
new DefaultAzureCredential())
.AsAIAgent(
model: "gpt-4o-mini",
instructions: "You are a helpful weather assistant.");

var agentWithOverride = agent
.AsBuilder()
Expand All @@ -66,6 +67,9 @@ var agentWithOverride = agent
Console.WriteLine(await agentWithOverride.RunAsync("What's the weather in Seattle?"));
```

> [!WARNING]
> `DefaultAzureCredential` is convenient for development but requires careful consideration in production. In production, consider using a specific credential (e.g., `ManagedIdentityCredential`) to avoid latency issues, unintended credential probing, and potential security risks from fallback mechanisms.

:::zone-end

:::zone pivot="programming-language-python"
Expand Down
Loading