Skip to content

Commit 4231124

Browse files
Merge pull request #740 from MicrosoftDocs/main
Merge latest doc updates from main to live
2 parents 2442fe2 + 26a6691 commit 4231124

20 files changed

Lines changed: 539 additions & 252 deletions

agent-framework/migration-guide/from-autogen/index.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -974,9 +974,9 @@ async def join_any(msg: str, ctx: WorkflowContext[Never, str]) -> None:
974974

975975
@executor(id="join_all")
976976
async def join_all(msg: str, ctx: WorkflowContext[str, str]) -> None:
977-
state = await ctx.get_state() or {"items": []}
977+
state = await ctx.get_executor_state() or {"items": []}
978978
state["items"].append(msg)
979-
await ctx.set_state(state)
979+
await ctx.set_executor_state(state)
980980
if len(state["items"]) >= 2:
981981
await ctx.yield_output(" | ".join(state["items"])) # ALL join
982982

@@ -1404,7 +1404,7 @@ AutoGen's `Team` abstraction does not provide built-in checkpointing capabilitie
14041404

14051405
Agent Framework provides comprehensive checkpointing through `FileCheckpointStorage` and the `with_checkpointing()` method on `WorkflowBuilder`. Checkpoints capture:
14061406

1407-
- **Executor state**: Local state for each executor using `ctx.set_state()`
1407+
- **Executor state**: Local state for each executor using `ctx.set_executor_state()`
14081408
- **Shared state**: Cross-executor state using `ctx.set_shared_state()`
14091409
- **Message queues**: Pending messages between executors
14101410
- **Workflow position**: Current execution progress and next steps
@@ -1424,9 +1424,9 @@ class ProcessingExecutor(Executor):
14241424
print(f"Processing: '{data}' -> '{result}'")
14251425

14261426
# Persist executor-local state
1427-
prev_state = await ctx.get_state() or {}
1427+
prev_state = await ctx.get_executor_state() or {}
14281428
count = prev_state.get("count", 0) + 1
1429-
await ctx.set_state({
1429+
await ctx.set_executor_state({
14301430
"count": count,
14311431
"last_input": data,
14321432
"last_output": result

agent-framework/migration-guide/from-semantic-kernel/samples.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ ms.service: agent-framework
1313

1414
::: zone pivot="programming-language-csharp"
1515

16-
See the [Agent Framework repository](https://github.com/microsoft/agent-framework/tree/main/dotnet/samples/SemanticKernelMigration) for detailed per agent type code samples showing the the Agent Framework equivalent code for Semantic Kernel features.
16+
See the [Semantic Kernel repository](https://github.com/microsoft/semantic-kernel/tree/main/dotnet/samples/AgentFrameworkMigration) for detailed per agent type code samples showing the the Agent Framework equivalent code for Semantic Kernel features.
1717

1818
::: zone-end
1919
::: zone pivot="programming-language-python"

agent-framework/tutorials/agents/agent-as-mcp-tool.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,19 @@ This tutorial shows you how to expose an agent as a tool over the Model Context
1717

1818
## Prerequisites
1919

20-
For prerequisites see the [Create and run a simple agent](./run-agent.md) step in this tutorial.
20+
For prerequisites see the [Create and run a simple agent](./run-agent.md#prerequisites) step in this tutorial.
2121

2222
## Install NuGet packages
2323

2424
To use Microsoft Agent Framework with Azure OpenAI, you need to install the following NuGet packages:
2525

2626
```dotnetcli
27+
dotnet add package Azure.AI.OpenAI --prerelease
2728
dotnet add package Azure.Identity
28-
dotnet add package Azure.AI.OpenAI
2929
dotnet add package Microsoft.Agents.AI.OpenAI --prerelease
3030
```
3131

32-
To add support for hosting a tool over the Model Context Protocol (MCP), add the following NuGet packages
32+
To also add support for hosting a tool over the Model Context Protocol (MCP), add the following NuGet packages
3333

3434
```dotnetcli
3535
dotnet add package Microsoft.Extensions.Hosting --prerelease
@@ -69,6 +69,7 @@ Setup the MCP server to listen for incoming requests over standard input/output
6969
```csharp
7070
using Microsoft.Extensions.DependencyInjection;
7171
using Microsoft.Extensions.Hosting;
72+
using ModelContextProtocol.Server;
7273

7374
HostApplicationBuilder builder = Host.CreateEmptyApplicationBuilder(settings: null);
7475
builder.Services

agent-framework/tutorials/agents/enable-observability.md

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@ In this tutorial, output is written to the console using the OpenTelemetry conso
2121
2222
## Prerequisites
2323

24-
For prerequisites, see the [Create and run a simple agent](./run-agent.md) step in this tutorial.
24+
For prerequisites, see the [Create and run a simple agent](./run-agent.md#prerequisites) step in this tutorial.
2525

2626
## Install NuGet packages
2727

28-
To use Agent Framework with Azure OpenAI, you need to install the following NuGet packages:
28+
To use Microsoft Agent Framework with Azure OpenAI, you need to install the following NuGet packages:
2929

3030
```dotnetcli
31+
dotnet add package Azure.AI.OpenAI --prerelease
3132
dotnet add package Azure.Identity
32-
dotnet add package Azure.AI.OpenAI
3333
dotnet add package Microsoft.Agents.AI.OpenAI --prerelease
3434
```
3535

@@ -98,20 +98,24 @@ Activity.Kind: Client
9898
Activity.StartTime: 2025-09-18T11:00:48.6636883Z
9999
Activity.Duration: 00:00:08.6077009
100100
Activity.Tags:
101-
gen_ai.operation.name: invoke_agent
102-
gen_ai.system: openai
103-
gen_ai.agent.id: e1370f89-3ca8-4278-bce0-3a3a2b22f407
101+
gen_ai.operation.name: chat
102+
gen_ai.request.model: gpt-4o-mini
103+
gen_ai.provider.name: openai
104+
server.address: <myresource>.openai.azure.com
105+
server.port: 443
106+
gen_ai.agent.id: 19e310a72fba4cc0b257b4bb8921f0c7
104107
gen_ai.agent.name: Joker
105-
gen_ai.request.instructions: You are good at telling jokes.
108+
gen_ai.response.finish_reasons: ["stop"]
106109
gen_ai.response.id: chatcmpl-CH6fgKwMRGDtGNO3H88gA3AG2o7c5
110+
gen_ai.response.model: gpt-4o-mini-2024-07-18
107111
gen_ai.usage.input_tokens: 26
108112
gen_ai.usage.output_tokens: 29
109113
Instrumentation scope (ActivitySource):
110-
Name: c8aeb104-0ce7-49b3-bf45-d71e5bf782d1
114+
Name: agent-telemetry-source
111115
Resource associated with Activity:
112116
telemetry.sdk.name: opentelemetry
113117
telemetry.sdk.language: dotnet
114-
telemetry.sdk.version: 1.12.0
118+
telemetry.sdk.version: 1.13.1
115119
service.name: unknown_service:Agent_Step08_Telemetry
116120
117121
Why did the pirate go to school?

agent-framework/tutorials/agents/memory.md

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ For prerequisites and installing NuGet packages, see the [Create and run a simpl
2727
`AIContextProvider` is an abstract class that you can inherit from, and which can be associated with the `AgentThread` for a `ChatClientAgent`.
2828
It allows you to:
2929

30-
1. run custom logic before and after the agent invokes the underlying inference service
31-
1. provide additional context to the agent before it invokes the underlying inference service
32-
1. inspect all messages provided to and produced by the agent
30+
1. Run custom logic before and after the agent invokes the underlying inference service.
31+
1. Provide additional context to the agent before it invokes the underlying inference service.
32+
1. Inspect all messages provided to and produced by the agent.
3333

3434
### Pre and post invocation events
3535

@@ -63,12 +63,20 @@ internal sealed class UserInfo
6363
Then you can implement the `AIContextProvider` to manage the memories.
6464
The `UserInfoMemory` class below contains the following behavior:
6565

66-
1. It uses a `IChatClient` to look for the user's name and age in user messages when new messages are added to the thread at the end of each run.
66+
1. It uses an `IChatClient` to look for the user's name and age in user messages when new messages are added to the thread at the end of each run.
6767
1. It provides any current memories to the agent before each invocation.
68-
1. If not memories are available, it instructs the agent to ask the user for the missing information, and not to answer any questions until the information is provided.
68+
1. If no memories are available, it instructs the agent to ask the user for the missing information, and not to answer any questions until the information is provided.
6969
1. It also implements serialization to allow persisting the memories as part of the thread state.
7070

7171
```csharp
72+
using System.Linq;
73+
using System.Text;
74+
using System.Text.Json;
75+
using System.Threading;
76+
using System.Threading.Tasks;
77+
using Microsoft.Agents.AI;
78+
using Microsoft.Extensions.AI;
79+
7280
internal sealed class UserInfoMemory : AIContextProvider
7381
{
7482
private readonly IChatClient _chatClient;
@@ -140,6 +148,12 @@ To use the custom `AIContextProvider`, you need to provide an `AIContextProvider
140148
When creating a `ChatClientAgent` it is possible to provide a `ChatClientAgentOptions` object that allows providing the `AIContextProviderFactory` in addition to all other agent options.
141149

142150
```csharp
151+
using System;
152+
using Azure.AI.OpenAI;
153+
using Azure.Identity;
154+
using OpenAI.Chat;
155+
using OpenAI;
156+
143157
ChatClient chatClient = new AzureOpenAIClient(
144158
new Uri("https://<myresource>.openai.azure.com"),
145159
new AzureCliCredential())
@@ -189,9 +203,9 @@ For prerequisites and installing packages, see the [Create and run a simple agen
189203
`ContextProvider` is an abstract class that you can inherit from, and which can be associated with an `AgentThread` for a `ChatAgent`.
190204
It allows you to:
191205

192-
1. run custom logic before and after the agent invokes the underlying inference service
193-
1. provide additional context to the agent before it invokes the underlying inference service
194-
1. inspect all messages provided to and produced by the agent
206+
1. Run custom logic before and after the agent invokes the underlying inference service.
207+
1. Provide additional context to the agent before it invokes the underlying inference service.
208+
1. Inspect all messages provided to and produced by the agent.
195209

196210
### Pre and post invocation events
197211

agent-framework/tutorials/agents/middleware.md

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ First, create a basic agent with a function tool.
2525

2626
```csharp
2727
using System;
28+
using System.ComponentModel;
2829
using Azure.AI.OpenAI;
2930
using Azure.Identity;
3031
using Microsoft.Agents.AI;
@@ -56,16 +57,21 @@ This sample middleware just inspects the input and output from the agent run and
5657
outputs the number of messages passed into and out of the agent.
5758

5859
```csharp
60+
using System.Collections.Generic;
61+
using System.Linq;
62+
using System.Threading;
63+
using System.Threading.Tasks;
64+
5965
async Task<AgentRunResponse> CustomAgentRunMiddleware(
6066
IEnumerable<ChatMessage> messages,
6167
AgentThread? thread,
6268
AgentRunOptions? options,
6369
AIAgent innerAgent,
6470
CancellationToken cancellationToken)
6571
{
66-
Console.WriteLine(messages.Count());
72+
Console.WriteLine($"Input: {messages.Count()}");
6773
var response = await innerAgent.RunAsync(messages, thread, options, cancellationToken).ConfigureAwait(false);
68-
Console.WriteLine(response.Messages.Count);
74+
Console.WriteLine($"Output: {response.Messages.Count}");
6975
return response;
7076
}
7177
```
@@ -79,10 +85,17 @@ The original `baseAgent` is not modified.
7985
```csharp
8086
var middlewareEnabledAgent = baseAgent
8187
.AsBuilder()
82-
.Use(CustomAgentRunMiddleware)
88+
.Use(runFunc: CustomAgentRunMiddleware, runStreamingFunc: null)
8389
.Build();
8490
```
8591

92+
Now, when executing the agent with a query, the middleware should get invoked,
93+
outputting the number of input messages and the number of response messages.
94+
95+
```csharp
96+
Console.WriteLine(await middlewareEnabledAgent.RunAsync("What's the current time?"));
97+
```
98+
8699
## Step 4: Create Function calling Middleware
87100

88101
> [!NOTE]
@@ -94,6 +107,9 @@ Here's an example of function-calling middleware that can inspect and/or modify
94107
Unless the intention is to use the middleware to not execute the function tool, the middleware should call the provided `next` `Func`.
95108

96109
```csharp
110+
using System.Threading;
111+
using System.Threading.Tasks;
112+
97113
async ValueTask<object?> CustomFunctionCallingMiddleware(
98114
AIAgent agent,
99115
FunctionInvocationContext context,
@@ -123,7 +139,7 @@ Now, when executing the agent with a query that invokes a function, the middlewa
123139
outputting the function name and call result.
124140

125141
```csharp
126-
await middlewareEnabledAgent.RunAsync("What's the current time?");
142+
Console.WriteLine(await middlewareEnabledAgent.RunAsync("What's the current time?"));
127143
```
128144

129145
## Step 6: Create Chat Client Middleware
@@ -134,15 +150,20 @@ In this case, it's possible to use middleware for the `IChatClient`.
134150
Here is an example of chat client middleware that can inspect and/or modify the input and output for the request to the inference service that the chat client provides.
135151

136152
```csharp
153+
using System.Collections.Generic;
154+
using System.Linq;
155+
using System.Threading;
156+
using System.Threading.Tasks;
157+
137158
async Task<ChatResponse> CustomChatClientMiddleware(
138159
IEnumerable<ChatMessage> messages,
139160
ChatOptions? options,
140161
IChatClient innerChatClient,
141162
CancellationToken cancellationToken)
142163
{
143-
Console.WriteLine(messages.Count());
164+
Console.WriteLine($"Input: {messages.Count()}");
144165
var response = await innerChatClient.GetResponseAsync(messages, options, cancellationToken);
145-
Console.WriteLine(response.Messages.Count);
166+
Console.WriteLine($"Output: {response.Messages.Count}");
146167

147168
return response;
148169
}
@@ -158,7 +179,7 @@ After adding the middleware, you can use the `IChatClient` with your agent as us
158179

159180
```csharp
160181
var chatClient = new AzureOpenAIClient(new Uri("https://<myresource>.openai.azure.com"), new AzureCliCredential())
161-
.GetChatClient(deploymentName)
182+
.GetChatClient("gpt-4o-mini")
162183
.AsIChatClient();
163184

164185
var middlewareEnabledChatClient = chatClient
@@ -173,8 +194,8 @@ var agent = new ChatClientAgent(middlewareEnabledChatClient, instructions: "You
173194
an agent via one of the helper methods on SDK clients.
174195

175196
```csharp
176-
var agent = new AzureOpenAIClient(new Uri(endpoint), new AzureCliCredential())
177-
.GetChatClient(deploymentName)
197+
var agent = new AzureOpenAIClient(new Uri("https://<myresource>.openai.azure.com"), new AzureCliCredential())
198+
.GetChatClient("gpt-4o-mini")
178199
.CreateAIAgent("You are a helpful assistant.", clientFactory: (chatClient) => chatClient
179200
.AsBuilder()
180201
.Use(getResponseFunc: CustomChatClientMiddleware, getStreamingResponseFunc: null)

agent-framework/tutorials/agents/persisted-conversation.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,16 +48,15 @@ Run the agent, passing in the thread, so that the `AgentThread` includes this ex
4848
Console.WriteLine(await agent.RunAsync("Tell me a short pirate joke.", thread));
4949
```
5050

51-
Call the SerializeAsync method on the thread to serialize it to a JsonElement.
51+
Call the `Serialize` method on the thread to serialize it to a JsonElement.
5252
It can then be converted to a string for storage and saved to a database, blob storage, or file.
5353

5454
```csharp
5555
using System.IO;
5656
using System.Text.Json;
5757

5858
// Serialize the thread state
59-
JsonElement serializedThread = thread.Serialize();
60-
string serializedJson = JsonSerializer.Serialize(serializedThread, JsonSerializerOptions.Web);
59+
string serializedJson = thread.Serialize(JsonSerializerOptions.Web).GetRawText();
6160

6261
// Example: save to a local file (replace with DB or blob storage in production)
6362
string filePath = Path.Combine(Path.GetTempPath(), "agent_thread.json");
@@ -73,10 +72,10 @@ additional functionality that is specific to that agent type.
7372
```csharp
7473
// Read persisted JSON
7574
string loadedJson = await File.ReadAllTextAsync(filePath);
76-
JsonElement reloaded = JsonSerializer.Deserialize<JsonElement>(loadedJson);
75+
JsonElement reloaded = JsonSerializer.Deserialize<JsonElement>(loadedJson, JsonSerializerOptions.Web);
7776

7877
// Deserialize the thread into an AgentThread tied to the same agent type
79-
AgentThread resumedThread = agent.DeserializeThread(reloaded);
78+
AgentThread resumedThread = agent.DeserializeThread(reloaded, JsonSerializerOptions.Web);
8079
```
8180

8281
Use the resumed thread to continue the conversation.

agent-framework/tutorials/agents/run-agent.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ This tutorial shows you how to create and run an agent with Agent Framework, bas
2222

2323
Before you begin, ensure you have the following prerequisites:
2424

25-
- [.NET 8.0 SDK](https://dotnet.microsoft.com/en-us/download/dotnet/8.0)
25+
- [.NET 8.0 SDK or later](https://dotnet.microsoft.com/download)
2626
- [Azure OpenAI service endpoint and deployment configured](/azure/ai-foundry/openai/how-to/create-resource)
2727
- [Azure CLI installed](/cli/azure/install-azure-cli) and [authenticated (for Azure credential authentication)](/cli/azure/authenticate-azure-cli)
2828
- [User has the `Cognitive Services OpenAI User` or `Cognitive Services OpenAI Contributor` roles for the Azure OpenAI resource.](/azure/ai-foundry/openai/how-to/role-based-access-control)
@@ -38,8 +38,8 @@ Before you begin, ensure you have the following prerequisites:
3838
To use Microsoft Agent Framework with Azure OpenAI, you need to install the following NuGet packages:
3939

4040
```dotnetcli
41+
dotnet add package Azure.AI.OpenAI --prerelease
4142
dotnet add package Azure.Identity
42-
dotnet add package Azure.AI.OpenAI
4343
dotnet add package Microsoft.Agents.AI.OpenAI --prerelease
4444
```
4545

agent-framework/tutorials/agents/structured-output.md

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,15 @@ The `ChatClientAgent` uses the support for structured output that's provided by
3030
When creating the agent, you have the option to provide the default <xref:Microsoft.Extensions.AI.ChatOptions> instance to use for the underlying chat client.
3131
This `ChatOptions` instance allows you to pick a preferred <xref:Microsoft.Extensions.AI.ChatResponseFormat>.
3232

33-
Various options are supported:
33+
Various options for `ResponseFormat` are available:
3434

35-
- <xref:Microsoft.Extensions.AI.ChatResponseFormat.Text?displayProperty=nameWithType>: The response will be plain text.
36-
- <xref:Microsoft.Extensions.AI.ChatResponseFormat.Json?displayProperty=nameWithType>: The response will be a JSON object without any particular schema.
37-
- <xref:Microsoft.Extensions.AI.ChatResponseFormatJson>: The response will be a JSON object that conforms to the provided schema.
35+
- A built-in <xref:Microsoft.Extensions.AI.ChatResponseFormat.Text?displayProperty=nameWithType> property: The response will be plain text.
36+
- A built-in <xref:Microsoft.Extensions.AI.ChatResponseFormat.Json?displayProperty=nameWithType> property: The response will be a JSON object without any particular schema.
37+
- A custom <xref:Microsoft.Extensions.AI.ChatResponseFormatJson> instance: The response will be a JSON object that conforms to a specific schema.
3838

3939
This example creates an agent that produces structured output in the form of a JSON object that conforms to a specific schema.
4040

41-
The easiest way to produce the schema is to define a C# class that represents the structure of the output you want from the agent, and then use the `AIJsonUtilities.CreateJsonSchema` method to create a schema from the type.
41+
The easiest way to produce the schema is to define a type that represents the structure of the output you want from the agent, and then use the `AIJsonUtilities.CreateJsonSchema` method to create a schema from the type.
4242

4343
```csharp
4444
using System.Text.Json;
@@ -47,13 +47,8 @@ using Microsoft.Extensions.AI;
4747

4848
public class PersonInfo
4949
{
50-
[JsonPropertyName("name")]
5150
public string? Name { get; set; }
52-
53-
[JsonPropertyName("age")]
5451
public int? Age { get; set; }
55-
56-
[JsonPropertyName("occupation")]
5752
public string? Occupation { get; set; }
5853
}
5954

@@ -67,7 +62,7 @@ using Microsoft.Extensions.AI;
6762

6863
ChatOptions chatOptions = new()
6964
{
70-
ResponseFormat = ChatResponseFormatJson.ForJsonSchema(
65+
ResponseFormat = ChatResponseFormat.ForJsonSchema(
7166
schema: schema,
7267
schemaName: "PersonInfo",
7368
schemaDescription: "Information about a person including their name, age, and occupation")

0 commit comments

Comments
 (0)