Skip to content

Commit bb5484c

Browse files
committed
standardized samples
1 parent f25b1e9 commit bb5484c

11 files changed

+956
-846
lines changed

articles/ai-services/agents/how-to/tools/azure-ai-search-samples.md

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ Complete the [Azure AI Search tool setup](../../how-to/tools/azure-ai-search.md?
3434

3535
:::zone pivot="python"
3636

37-
## Step 1: Create an Azure AI Client
37+
## Create an Azure AI Client
3838
First, create an Azure AI Client using the endpoint of your project.
3939

4040
```python
@@ -53,7 +53,7 @@ project_client = AIProjectClient(
5353
)
5454
```
5555

56-
## Step 2: Configure the Azure AI Search tool
56+
## Configure the Azure AI Search tool
5757
Using the connection ID of your Azure AI Search resource, configure the Azure AI Search tool to use your Azure AI Search index.
5858

5959
```python
@@ -73,7 +73,7 @@ ai_search = AzureAISearchTool(
7373
)
7474
```
7575

76-
## Step 3: Create an agent with the Azure AI Search tool enabled
76+
## Create an agent with the Azure AI Search tool enabled
7777
Create an agent with the Azure AI Search tool attached. Change the model to the one deployed in your project.
7878

7979
```python
@@ -91,7 +91,7 @@ agent = project_client.agents.create_agent(
9191
print(f"Created agent, ID: {agent.id}")
9292
```
9393

94-
## Step 4: Ask the agent questions about data in the index
94+
## Ask the agent questions about data in the index
9595
Now that the agent is created, ask it questions about the data in your Azure AI Search index.
9696

9797
```python
@@ -123,7 +123,7 @@ for message in messages.data:
123123
print(f"Role: {message.role}, Content: {message.content}")
124124
```
125125

126-
## Step 5: Clean up resources
126+
## Clean up resources
127127
After completing the operations, delete the agent to clean up resources.
128128

129129
```python
@@ -136,7 +136,7 @@ print("Deleted agent")
136136

137137
:::zone pivot="csharp"
138138

139-
## Step 1: Create a project client
139+
## Create a project client
140140
Create a client object, which will contain the project endpoint for connecting to your AI project and other resources.
141141

142142
```csharp
@@ -161,7 +161,7 @@ var azureAiSearchConnectionId = configuration["AzureAiSearchConnectionId"];
161161
PersistentAgentsClient agentClient = new(projectEndpoint, new DefaultAzureCredential());
162162
```
163163

164-
## Step 2: Configure the Azure AI Search tool
164+
## Configure the Azure AI Search tool
165165
Using the AI Search Connection ID, configure the Azure AI Search tool to use your Azure AI Search index.
166166

167167
```csharp
@@ -177,7 +177,7 @@ ToolResources toolResource = new() { AzureAISearch = searchResource };
177177

178178
```
179179

180-
## Step 3: Create an agent with the Azure AI Search tool enabled
180+
## Create an agent with the Azure AI Search tool enabled
181181
Change the model to the one deployed in your project. You can find the model name in the Azure AI Foundry under the **Models** tab. You can also change the name and instructions of the agent to suit your needs.
182182

183183
```csharp
@@ -191,7 +191,7 @@ PersistentAgent agent = agentClient.Administration.CreateAgent(
191191

192192
```
193193

194-
## Step 4: Ask the agent questions about data in the index
194+
## Ask the agent questions about data in the index
195195
Now that the agent is created, ask it questions about the data in your Azure AI Search index.
196196

197197
```csharp
@@ -207,7 +207,7 @@ ThreadRun run = agentClient.Runs.CreateRun(thread, agent);
207207

208208
```
209209

210-
## Step 4: Wait for the agent to complete and print the output
210+
## Wait for the agent to complete and print the output
211211

212212
Wait for the agent to complete the run and print output to console.
213213

@@ -271,7 +271,7 @@ foreach (ThreadMessage threadMessage in messages)
271271
}
272272
}
273273
```
274-
## Step 5: Clean up resources
274+
## Clean up resources
275275

276276
Clean up the resources from this sample.
277277

@@ -287,7 +287,7 @@ agentClient.Administration.DeleteAgent(agent.Id);
287287

288288
:::zone pivot="javascript"
289289

290-
## Step 1: Create an Azure AI Client
290+
## Create an Azure AI Client
291291
First, create an Azure AI Client using the connection string of your project.
292292

293293
```javascript
@@ -304,7 +304,7 @@ const client = AIProjectsClient.fromConnectionString(
304304
);
305305
```
306306

307-
## Step 2: Get the connection ID for the Azure AI Search resource
307+
## Get the connection ID for the Azure AI Search resource
308308
Get the connection ID of the Azure AI Search connection in the project.
309309

310310
```javascript
@@ -314,7 +314,7 @@ const cognitiveServicesConnection = await client.connections.getConnection(
314314
);
315315
```
316316

317-
## Step 3: Configure the Azure AI Search tool
317+
## Configure the Azure AI Search tool
318318
Using the connection ID you got in the previous step, you can now configure the Azure AI Search tool to use your Azure AI Search index.
319319

320320
```javascript
@@ -333,7 +333,7 @@ const agent = await client.agents.createAgent("gpt-4o-mini", {
333333
console.log(`Created agent, agent ID : ${agent.id}`);
334334
```
335335

336-
## Step 4: Create an agent with the Azure AI Search tool enabled
336+
## Create an agent with the Azure AI Search tool enabled
337337

338338
Change the model to the one deployed in your project. You can find the model name in the Azure AI Foundry under the **Models** tab. You can also change the name and instructions of the agent to suit your needs.
339339

@@ -348,7 +348,7 @@ console.log(`Created agent, agent ID : ${agent.id}`);
348348
```
349349

350350

351-
## Step 5: Ask the agent questions about data in the index
351+
## Ask the agent questions about data in the index
352352
Now that the agent is created, ask it questions about the data in your Azure AI Search index.
353353

354354
```javascript
@@ -413,10 +413,10 @@ for (let i = messages.data.length - 1; i >= 0; i--) {
413413
414414
:::zone pivot="rest"
415415
416-
## Step 1: Create an Azure AI Client
416+
## Create an Azure AI Client
417417
Follow the [REST API Quickstart](../../quickstart.md?pivots=rest-api) to set the right values for the environment variables `AZURE_AI_AGENTS_TOKEN` and `AZURE_AI_AGENTS_ENDPOINT`.
418418
419-
## Step 2: Get the connection ID for the Azure AI Search resource
419+
## Get the connection ID for the Azure AI Search resource
420420
Follow the next section on how to get the connection ID from the Azure AI Foundry.
421421
422422
The second way to get the connection ID is to navigate to the project in the Azure AI Foundry and click on the **Connected resources** tab and then select your Azure AI Search resource.
@@ -427,7 +427,7 @@ In the URL, you see the wsid=/subscription/your-subscription-id..., this is the
427427
428428
:::image type="content" source="../../media/tools/ai-search/connection-id.png" alt-text="A screenshot of an AI Search resource connection and how to copy the connection ID." lightbox="../../media/tools/ai-search/connection-id.png":::
429429
430-
## Step 3: Configure the Azure AI Search tool
430+
## Configure the Azure AI Search tool
431431
Using the connection ID you got in the previous step, you can now configure the Azure AI Search tool to use your Azure AI Search index.
432432
433433
```console
@@ -455,7 +455,7 @@ curl $AZURE_AI_AGENTS_ENDPOINT/assistants?api-version=2024-12-01-preview \
455455
}'
456456
```
457457
458-
### Step 4: Ask the agent questions about data in the index
458+
### Ask the agent questions about data in the index
459459
Now that the agent is created, ask it questions about the data in your Azure AI Search index.
460460
461461
#### Create a thread
@@ -478,7 +478,6 @@ curl $AZURE_AI_AGENTS_ENDPOINT/threads/thread_abc123/messages?api-version=2024-1
478478
"content": "what are my health insurance plan coverage types?"
479479
}'
480480
```
481-
482481
#### Run the thread
483482
484483
```console
@@ -504,4 +503,4 @@ curl $AZURE_AI_AGENTS_ENDPOINT/threads/thread_abc123/messages?api-version=2024-1
504503
-H "Authorization: Bearer $AZURE_AI_AGENTS_TOKEN"
505504
```
506505
507-
:::zone-end
506+
:::zone-end

articles/ai-services/agents/how-to/tools/azure-functions-samples.md

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -62,22 +62,16 @@ def process_queue_message(msg: func.QueueMessage) -> None:
6262
logging.info(f"Sent message to output queue with message {result_message}")
6363
```
6464

65-
## Create an AI project client and agent
65+
## Configure the Azure Function tool
6666

67-
In the sample below we create a client and an agent that has the tools definition for the Azure Function
67+
First, define the Azure Function tool, specifying its name, description, parameters, and storage queue configurations.
6868

6969
```python
7070
import os
7171
from azure.ai.projects import AIProjectClient
7272
from azure.identity import DefaultAzureCredential
7373
from azure.ai.agents.models import AzureFunctionStorageQueue, AzureFunctionTool
7474

75-
# Create a project client
76-
project_client = AIProjectClient.from_connection_string(
77-
credential=DefaultAzureCredential(),
78-
conn_str=os.environ["PROJECT_CONNECTION_STRING"]
79-
)
80-
8175
# Retrieve the storage service endpoint from environment variables
8276
storage_service_endpoint = os.environ["STORAGE_SERVICE_ENDPONT"]
8377

@@ -101,13 +95,20 @@ azure_function_tool = AzureFunctionTool(
10195
storage_service_endpoint=storage_service_endpoint,
10296
),
10397
)
98+
```
10499

100+
## Create an AI project client and agent
101+
102+
Next, create an AI project client and then create an agent, attaching the Azure Function tool defined previously.
103+
104+
```python
105105
# Initialize the AIProjectClient
106106
project_client = AIProjectClient(
107107
endpoint=os.environ["PROJECT_ENDPOINT"],
108108
credential=DefaultAzureCredential(),
109109
api_version="latest",
110-
)# Create an agent with the Azure Function tool
110+
)
111+
# Create an agent with the Azure Function tool
111112
agent = project_client.agents.create_agent(
112113
model=os.environ["MODEL_DEPLOYMENT_NAME"], # Model deployment name
113114
name="azure-function-agent-foo", # Name of the agent
@@ -119,6 +120,7 @@ agent = project_client.agents.create_agent(
119120
tools=azure_function_tool.definitions, # Attach the tool definitions to the agent
120121
)
121122
print(f"Created agent, agent ID: {agent.id}")
123+
122124
```
123125

124126
## Create a thread for the agent
@@ -136,7 +138,7 @@ print(f"Created thread, thread ID: {thread.id}")
136138
message = project_client.agents.messages.create(
137139
thread_id=thread.id,
138140
role="user",
139-
content="What is the most prevalent element in the universe? What would foo say?", # Message content
141+
content="What is the most prevalent element in the universe? What would foo say?",
140142
)
141143
print(f"Created message, message ID: {message['id']}")
142144

@@ -168,7 +170,7 @@ project_client.agents.delete_agent(agent.id)
168170
print(f"Deleted agent")
169171
```
170172

171-
For any issues with the Python code, create an issue on the [sample code repository](https://github.com/Azure-Samples/azure-functions-ai-services-agent-python/issues)
173+
For any issues with the Python code, create an issue on the [sample code repository](https://github.com/azure-ai-foundry/foundry-samples)
172174

173175
::: zone-end
174176

0 commit comments

Comments
 (0)