@@ -112,67 +112,68 @@ To enable your Agent to use a connected agent, you use `ConnectedAgentToolDefini
112
112
``` csharp
113
113
var projectEndpoint = configuration [" ProjectEndpoint" ];
114
114
var modelDeploymentName = configuration [" ModelDeploymentName" ];
115
-
115
+
116
116
PersistentAgentsClient client = new (projectEndpoint , new DefaultAzureCredential ());
117
117
```
118
118
119
119
2 . Next we will create the connected agent using the agent client . This agent will be used to initialize the `ConnectedAgentToolDefinition `.
120
120
121
121
```csharp
122
- PersistentAgent agent = client .Administration .CreateAgent (
123
- model : modelDeploymentName ,
124
- name : "stock_price_bot ",
125
- instructions : "Your job is to get the stock price of a company . If you don 't know the realtime stock price , return the last known stock price .");
126
-
127
- ConnectedAgentToolDefinition connectedAgentDefinition = new (new ConnectedAgentDetails (connectedAgent .Id , connectedAgent .Name , " Gets the stock price of a company" ));
128
- ```
122
+ PersistentAgent stockAgent = client .Administration .CreateAgent (
123
+ model : modelDeploymentName ,
124
+ name : "stock_price_bot ",
125
+ instructions : "Your job is to get the stock price of a company . If you don 't know the realtime stock price , return the last known stock price .",
126
+ // tools: [...] tools that would be used to get stock prices
127
+ );
128
+ ConnectedAgentToolDefinition connectedAgentDefinition = new (new ConnectedAgentDetails (stockAgent .Id , stockAgent .Name , " Gets the stock price of a company" ));
129
+
130
+ PersistentAgent mainAgent = client .Administration .CreateAgent (
131
+ model : modelDeploymentName ,
132
+ name : " stock_price_bot" ,
133
+ instructions : " Your job is to get the stock price of a company, using the available tools." ,
134
+ tools : [connectedAgentDefinition ]
135
+ );
129
136
130
- 3 . We will use the `ConnectedAgentToolDefinition ` during the agent initialization .
131
137
132
- ```csharp
133
- PersistentAgent agent = client .Administration .CreateAgent (
134
- model : modelDeploymentName ,
135
- name : " my-assistant" ,
136
- instructions : " You are a helpful assistant, and use the connected agent to get stock prices." ,
137
- tools : [ connectedAgentDefinition ]);
138
138
```
139
139
140
140
4 . Now we will create the thread , add the message , containing a question for agent and start the run.
141
141
142
142
```csharp
143
- AgentThread thread = agentClient .CreateThread();
144
-
143
+ PersistentAgentThread thread = client.Threads .CreateThread();
144
+
145
145
// Create message to thread
146
- ThreadMessage message = agentClient .CreateMessage (
146
+ PersistentThreadMessage message = client . Messages .CreateMessage (
147
147
thread .Id ,
148
148
MessageRole .User ,
149
149
" What is the stock price of Microsoft?" );
150
-
150
+
151
151
// Run the agent
152
- ThreadRun run = agentClient .CreateRun (thread , agent );
152
+ ThreadRun run = client . Runs .CreateRun (thread , agent );
153
153
do
154
154
{
155
155
Thread .Sleep (TimeSpan .FromMilliseconds (500 ));
156
- run = agentClient .GetRun (thread .Id , run .Id );
156
+ run = client . Runs .GetRun (thread .Id , run .Id );
157
157
}
158
158
while (run .Status == RunStatus .Queued
159
159
|| run .Status == RunStatus .InProgress );
160
-
161
- Assert .AreEqual (
162
- RunStatus .Completed ,
163
- run .Status ,
164
- run .LastError ? .Message );
160
+
161
+ // Confirm that the run completed successfully
162
+ if (run .Status != RunStatus .Completed )
163
+ {
164
+ throw new Exception (" Run did not complete successfully, error: " + run .LastError ? .Message );
165
+ }
165
166
```
166
167
167
168
5 . Print the agent messages to console in chronological order .
168
169
169
170
```csharp
170
- PageableList < ThreadMessage > messages = agentClient .GetMessages (
171
+ Pageable < PersistentThreadMessage > messages = client . Messages .GetMessages (
171
172
threadId : thread .Id ,
172
173
order : ListSortOrder .Ascending
173
174
);
174
-
175
- foreach (ThreadMessage threadMessage in messages )
175
+
176
+ foreach (PersistentThreadMessage threadMessage in messages )
176
177
{
177
178
Console .Write ($" {threadMessage .CreatedAt : yyyy - MM - dd HH : mm : ss } - {threadMessage .Role ,10 }: " );
178
179
foreach (MessageContent contentItem in threadMessage .ContentItems )
@@ -184,9 +185,9 @@ To enable your Agent to use a connected agent, you use `ConnectedAgentToolDefini
184
185
{
185
186
foreach (MessageTextAnnotation annotation in textItem .Annotations )
186
187
{
187
- if (annotation is MessageTextUrlCitationAnnotation urlAnnotation )
188
+ if (annotation is MessageTextUriCitationAnnotation urlAnnotation )
188
189
{
189
- response = response .Replace (urlAnnotation .Text , $" [{urlAnnotation .UrlCitation .Title }]({urlAnnotation .UrlCitation . Url })" );
190
+ response = response .Replace (urlAnnotation .Text , $" [{urlAnnotation .UriCitation .Title }]({urlAnnotation .UriCitation . Uri })" );
190
191
}
191
192
}
192
193
}
@@ -237,14 +238,11 @@ To create a multi-agent setup, follow these steps:
237
238
1 . Create an agent that will be connected to a " main" agent .
238
239
239
240
```python
240
- connected_agent_name = " stock_price_bot"
241
-
242
241
stock_price_agent = project_client .agents .create_agent (
243
242
model = os .environ [" MODEL_DEPLOYMENT_NAME" ],
244
- name = connected_agent_name ,
245
- instructions = (
246
- " Your job is to get the stock price of a company. If you don't know the realtime stock price, return the last known stock price."
247
- ),
243
+ name = " stock_price_bot" ,
244
+ instructions = " Your job is to get the stock price of a company. If you don't know the realtime stock price, return the last known stock price." ,
245
+ #tools=... # tools to help the agent get stock prices
248
246
)
249
247
```
250
248
@@ -262,7 +260,7 @@ To create a multi-agent setup, follow these steps:
262
260
agent = project_client .agents .create_agent (
263
261
model = os .environ [" MODEL_DEPLOYMENT_NAME" ],
264
262
name = " my-agent" ,
265
- instructions = " You are a helpful agent, and use the connected agent to get stock prices." ,
263
+ instructions = " You are a helpful agent, and use the available tools to get stock prices." ,
266
264
tools = connected_agent .definitions ,
267
265
)
268
266
0 commit comments