Skip to content

Commit e92be8c

Browse files
authored
Add fixes and improvements suggested in docs review to run-agent (#702)
* Add fixes and improvements suggested in docs review * Address pr comment
1 parent 26aa423 commit e92be8c

2 files changed

Lines changed: 70 additions & 9 deletions

File tree

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

Lines changed: 69 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@ Before you begin, ensure you have the following prerequisites:
2525
- [.NET 8.0 SDK](https://dotnet.microsoft.com/en-us/download/dotnet/8.0)
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)
28-
- [User has the `Cognitive Services OpenAI User` or `Cognitive Services OpenAI Contributor` roles, depending on need, for the Azure OpenAI resource.](/azure/ai-foundry/openai/how-to/role-based-access-control)
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)
2929

3030
> [!NOTE]
3131
> The Microsoft Agent Framework is supported with all actively supported versions of .net. For the purposes of this sample we are recommending the .NET 8.0 SDK or higher.
3232
> [!IMPORTANT]
33-
> For this tutorial we are using Azure OpenAI for the Chat Completion service, but you can use any inference service that is compatible with [Microsoft.Extensions.AI.IChatClient](/dotnet/api/microsoft.extensions.ai.ichatclient).
33+
> For this tutorial we are using Azure OpenAI for the Chat Completion service, but you can use any inference service that provides a [Microsoft.Extensions.AI.IChatClient](/dotnet/api/microsoft.extensions.ai.ichatclient) implementation.
3434
3535
## Installing Nuget packages
3636

@@ -45,7 +45,7 @@ dotnet add package Microsoft.Agents.AI.OpenAI
4545

4646
## Creating the agent
4747

48-
- First we create create a client for Azure OpenAI, by providing the Azure OpenAI endpoint and using the same login as was used when authenticating with the Azure CLI in the [Prerequisites](#prerequisites) step.
48+
- First we create a client for Azure OpenAI, by providing the Azure OpenAI endpoint and using the same login as was used when authenticating with the Azure CLI in the [Prerequisites](#prerequisites) step.
4949
- Then we get a chat client for communicating with the chat completion service, where we also specify the specific model deployment to use. Use one of the deployments that you created in the [Prerequisites](#prerequisites) step.
5050
- Finally we create the agent, providing instructions and a name for the agent.
5151

@@ -67,16 +67,24 @@ AIAgent agent = new AzureOpenAIClient(
6767
## Running the agent
6868

6969
To run the agent, call the `RunAsync` method on the agent instance, providing the user input.
70-
The agent will return a response object, and calling `.ToString()` or `.Text` on this response object, provides the text result from the agent.
70+
The agent will return an `AgentRunResponse` object, and calling `.ToString()` or `.Text` on this response object, provides the text result from the agent.
7171

7272
```csharp
7373
Console.WriteLine(await agent.RunAsync("Tell me a joke about a pirate."));
7474
```
7575

76+
Sample output:
77+
78+
```text
79+
Why did the pirate go to school?
80+
81+
Because he wanted to improve his "arrr-ticulation"! 🏴‍☠️
82+
```
83+
7684
## Running the agent with streaming
7785

7886
To run the agent with streaming, call the `RunStreamingAsync` method on the agent instance, providing the user input.
79-
The agent will stream a list of update objects, and calling `.ToString()` or `.Text` on each update object provides the part of the text result contained in that update.
87+
The agent will return a stream `AgentRunResponseUpdate` objects, and calling `.ToString()` or `.Text` on each update object provides the part of the text result contained in that update.
8088

8189
```csharp
8290
await foreach (var update in agent.RunStreamingAsync("Tell me a joke about a pirate."))
@@ -85,19 +93,72 @@ await foreach (var update in agent.RunStreamingAsync("Tell me a joke about a pir
8593
}
8694
```
8795

88-
## Running the agent with a ChatMessage
96+
Sample output:
97+
98+
```text
99+
Why
100+
did
101+
the
102+
pirate
103+
go
104+
to
105+
school
106+
?
107+
108+
109+
To
110+
improve
111+
his
112+
"
113+
ar
114+
rrrr
115+
rr
116+
tic
117+
ulation
118+
!"
119+
```
120+
121+
## Running the agent with ChatMessages
89122

90123
Instead of a simple string, you can also provide one or more `ChatMessage` objects to the `RunAsync` and `RunStreamingAsync` methods.
91124

125+
Here is an example with a single user message:
126+
92127
```csharp
93128
ChatMessage message = new(ChatRole.User, [
94129
new TextContent("Tell me a joke about this image?"),
95-
new UriContent("https://samplesite.org/clown.jpg", "image/jpeg")
130+
new UriContent("https://upload.wikimedia.org/wikipedia/commons/1/11/Joseph_Grimaldi.jpg", "image/jpeg")
96131
]);
97132

98133
Console.WriteLine(await agent.RunAsync(message));
99134
```
100135

136+
Sample output:
137+
138+
```text
139+
Why did the clown bring a bottle of sparkling water to the show?
140+
141+
Because he wanted to make a splash!
142+
```
143+
144+
Here is an example with a system and user message:
145+
146+
```csharp
147+
ChatMessage systemMessage = new(
148+
ChatRole.System,
149+
"""If the user asks you to tell a joke, refuse to do so, explaining that you are not a clown.
150+
Offer the user an interesting fact instead.""");
151+
ChatMessage userMessage = new(ChatRole.User, "Tell me a joke about a pirate.");
152+
153+
Console.WriteLine(await agent.RunAsync([systemMessage, userMessage]));
154+
```
155+
156+
Sample output:
157+
158+
```text
159+
I’m not a clown, but I can share an interesting fact! Did you know that pirates often revised the Jolly Roger flag? Depending on the pirate captain, it could feature different symbols like skulls, bones, or hourglasses, each representing their unique approach to piracy.
160+
```
161+
101162
::: zone-end
102163
::: zone pivot="programming-language-python"
103164

@@ -113,7 +174,7 @@ Before you begin, ensure you have the following prerequisites:
113174
- [Python 3.10 or later](https://www.python.org/downloads/)
114175
- [Azure OpenAI service endpoint and deployment configured](/azure/ai-foundry/openai/how-to/create-resource)
115176
- [Azure CLI installed](/cli/azure/install-azure-cli) and [authenticated (for Azure credential authentication)](/cli/azure/authenticate-azure-cli)
116-
- [User has the `Cognitive Services OpenAI User` or `Cognitive Services OpenAI Contributor` roles, depending on need, for the Azure OpenAI resource.](/azure/ai-foundry/openai/how-to/role-based-access-control)
177+
- [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)
117178

118179
> [!IMPORTANT]
119180
> For this tutorial we are using Azure OpenAI for the Chat Completion service, but you can use any inference service that is compatible with the Agent Framework's chat client protocol.

agent-framework/tutorials/quick-start.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Before you begin, ensure you have the following:
2323
- [.NET 8.0 SDK or later](https://dotnet.microsoft.com/download)
2424
- [Azure OpenAI resource](/azure/ai-foundry/openai/how-to/create-resource) with a deployed model (e.g., `gpt-4o-mini`)
2525
- [Azure CLI installed](/cli/azure/install-azure-cli) and [authenticated](/cli/azure/authenticate-azure-cli) (`az login`)
26-
- [User has the `Cognitive Services OpenAI User` or `Cognitive Services OpenAI Contributor` roles, depending on need, for the Azure OpenAI resource.](/azure/ai-foundry/openai/how-to/role-based-access-control)
26+
- [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)
2727

2828
**Note**: The Microsoft Agent Framework is supported with all actively supported versions of .Net. For the purposes of this sample we are recommending the .NET 8.0 SDK or higher.
2929

0 commit comments

Comments
 (0)