Skip to content

Commit 5757545

Browse files
committed
updates
1 parent 5887138 commit 5757545

File tree

1 file changed

+36
-38
lines changed

1 file changed

+36
-38
lines changed

articles/ai-services/agents/how-to/connected-agents.md

Lines changed: 36 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -112,67 +112,68 @@ To enable your Agent to use a connected agent, you use `ConnectedAgentToolDefini
112112
```csharp
113113
var projectEndpoint = configuration["ProjectEndpoint"];
114114
var modelDeploymentName = configuration["ModelDeploymentName"];
115-
115+
116116
PersistentAgentsClient client = new(projectEndpoint, new DefaultAzureCredential());
117117
```
118118

119119
2. Next we will create the connected agent using the agent client. This agent will be used to initialize the `ConnectedAgentToolDefinition`.
120120

121121
```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+
);
129136

130-
3. We will use the `ConnectedAgentToolDefinition` during the agent initialization.
131137

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 ]);
138138
```
139139

140140
4. Now we will create the thread, add the message, containing a question for agent and start the run.
141141

142142
```csharp
143-
AgentThread thread = agentClient.CreateThread();
144-
143+
PersistentAgentThread thread = client.Threads.CreateThread();
144+
145145
// Create message to thread
146-
ThreadMessage message = agentClient.CreateMessage(
146+
PersistentThreadMessage message = client.Messages.CreateMessage(
147147
thread.Id,
148148
MessageRole.User,
149149
"What is the stock price of Microsoft?");
150-
150+
151151
// Run the agent
152-
ThreadRun run = agentClient.CreateRun(thread, agent);
152+
ThreadRun run = client.Runs.CreateRun(thread, agent);
153153
do
154154
{
155155
Thread.Sleep(TimeSpan.FromMilliseconds(500));
156-
run = agentClient.GetRun(thread.Id, run.Id);
156+
run = client.Runs.GetRun(thread.Id, run.Id);
157157
}
158158
while (run.Status == RunStatus.Queued
159159
|| 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+
}
165166
```
166167

167168
5. Print the agent messages to console in chronological order.
168169

169170
```csharp
170-
PageableList<ThreadMessage> messages = agentClient.GetMessages(
171+
Pageable<PersistentThreadMessage> messages = client.Messages.GetMessages(
171172
threadId: thread.Id,
172173
order: ListSortOrder.Ascending
173174
);
174-
175-
foreach (ThreadMessage threadMessage in messages)
175+
176+
foreach (PersistentThreadMessage threadMessage in messages)
176177
{
177178
Console.Write($"{threadMessage.CreatedAt:yyyy-MM-dd HH:mm:ss} - {threadMessage.Role,10}: ");
178179
foreach (MessageContent contentItem in threadMessage.ContentItems)
@@ -184,9 +185,9 @@ To enable your Agent to use a connected agent, you use `ConnectedAgentToolDefini
184185
{
185186
foreach (MessageTextAnnotation annotation in textItem.Annotations)
186187
{
187-
if (annotation is MessageTextUrlCitationAnnotation urlAnnotation)
188+
if (annotation is MessageTextUriCitationAnnotation urlAnnotation)
188189
{
189-
response = response.Replace(urlAnnotation.Text, $" [{urlAnnotation.UrlCitation.Title}]({urlAnnotation.UrlCitation.Url})");
190+
response = response.Replace(urlAnnotation.Text, $" [{urlAnnotation.UriCitation.Title}]({urlAnnotation.UriCitation.Uri})");
190191
}
191192
}
192193
}
@@ -237,14 +238,11 @@ To create a multi-agent setup, follow these steps:
237238
1. Create an agent that will be connected to a "main" agent.
238239

239240
```python
240-
connected_agent_name = "stock_price_bot"
241-
242241
stock_price_agent = project_client.agents.create_agent(
243242
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
248246
)
249247
```
250248

@@ -262,7 +260,7 @@ To create a multi-agent setup, follow these steps:
262260
agent = project_client.agents.create_agent(
263261
model=os.environ["MODEL_DEPLOYMENT_NAME"],
264262
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.",
266264
tools=connected_agent.definitions,
267265
)
268266

0 commit comments

Comments
 (0)