You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: agent-framework/tutorials/agents/memory.md
+22-8Lines changed: 22 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -27,9 +27,9 @@ For prerequisites and installing NuGet packages, see the [Create and run a simpl
27
27
`AIContextProvider` is an abstract class that you can inherit from, and which can be associated with the `AgentThread` for a `ChatClientAgent`.
28
28
It allows you to:
29
29
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.
33
33
34
34
### Pre and post invocation events
35
35
@@ -63,12 +63,20 @@ internal sealed class UserInfo
63
63
Then you can implement the `AIContextProvider` to manage the memories.
64
64
The `UserInfoMemory` class below contains the following behavior:
65
65
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.
67
67
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.
69
69
1. It also implements serialization to allow persisting the memories as part of the thread state.
@@ -140,6 +148,12 @@ To use the custom `AIContextProvider`, you need to provide an `AIContextProvider
140
148
When creating a `ChatClientAgent` it is possible to provide a `ChatClientAgentOptions` object that allows providing the `AIContextProviderFactory` in addition to all other agent options.
141
149
142
150
```csharp
151
+
usingSystem;
152
+
usingAzure.AI.OpenAI;
153
+
usingAzure.Identity;
154
+
usingOpenAI.Chat;
155
+
usingOpenAI;
156
+
143
157
ChatClientchatClient=newAzureOpenAIClient(
144
158
newUri("https://<myresource>.openai.azure.com"),
145
159
newAzureCliCredential())
@@ -189,9 +203,9 @@ For prerequisites and installing packages, see the [Create and run a simple agen
189
203
`ContextProvider` is an abstract class that you can inherit from, and which can be associated with an `AgentThread` for a `ChatAgent`.
190
204
It allows you to:
191
205
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.
@@ -123,7 +139,7 @@ Now, when executing the agent with a query that invokes a function, the middlewa
123
139
outputting the function name and call result.
124
140
125
141
```csharp
126
-
awaitmiddlewareEnabledAgent.RunAsync("What's the current time?");
142
+
Console.WriteLine(awaitmiddlewareEnabledAgent.RunAsync("What's the current time?"));
127
143
```
128
144
129
145
## Step 6: Create Chat Client Middleware
@@ -134,15 +150,20 @@ In this case, it's possible to use middleware for the `IChatClient`.
134
150
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.
-[.NET 8.0 SDK or later](https://dotnet.microsoft.com/download)
26
26
-[Azure OpenAI service endpoint and deployment configured](/azure/ai-foundry/openai/how-to/create-resource)
27
27
-[Azure CLI installed](/cli/azure/install-azure-cli) and [authenticated (for Azure credential authentication)](/cli/azure/authenticate-azure-cli)
28
28
-[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)
@@ -165,6 +170,10 @@ To use the custom `ChatMessageStore`, you need to provide a `ChatMessageStoreFac
165
170
When creating a `ChatClientAgent` it is possible to provide a `ChatClientAgentOptions` object that allows providing the `ChatMessageStoreFactory` in addition to all other agent options.
0 commit comments