Skip to content

Commit d2fc9e2

Browse files
Merge pull request #6381 from dargilco/main
Update Python Agents code snippets
2 parents 2d2671c + 74515f3 commit d2fc9e2

9 files changed

+21
-21
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -275,11 +275,11 @@ To create a multi-agent setup, follow these steps:
275275
1. Create a thread and add a message to it.
276276

277277
```python
278-
thread = project_client.agents.create_thread()
278+
thread = project_client.agents.threads.create()
279279
print(f"Created thread, ID: {thread.id}")
280280

281281
# Create message to thread
282-
message = project_client.agents.create_message(
282+
message = project_client.agents.messages.create(
283283
thread_id=thread.id,
284284
role=MessageRole.USER,
285285
content="What is the stock price of Microsoft?",
@@ -293,7 +293,7 @@ To create a multi-agent setup, follow these steps:
293293
```python
294294

295295
# Create and process Agent run in thread with tools
296-
run = project_client.agents.create_and_process_run(thread_id=thread.id, agent_id=agent.id)
296+
run = project_client.agents.runs.create_and_process(thread_id=thread.id, agent_id=agent.id)
297297
print(f"Run finished with status: {run.status}")
298298

299299
if run.status == "failed":
@@ -312,7 +312,7 @@ To create a multi-agent setup, follow these steps:
312312

313313
```python
314314
# Print the Agent's response message with optional citation
315-
response_message = project_client.agents.list_messages(thread_id=thread.id).get_last_message_by_role(
315+
response_message = project_client.agents.messages.list(thread_id=thread.id).get_last_message_by_role(
316316
MessageRole.AGENT
317317
)
318318
if response_message:

articles/ai-foundry/agents/how-to/tools/bing-grounding.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ When you add the Grounding with Bing Search tool to your agent, you can pass the
8989
According to Grounding with Bing's [terms of use and use and display requirements](https://www.microsoft.com/en-us/bing/apis/grounding-legal#use-and-display-requirements), you need to display both website URLs and Bing search query URLs in your custom interface. You can find website URLs through `annotations` parameter in API response and Bing search query URLs through `runstep` details. To render the webpage, we recommend you replace the endpoint of Bing search query URLs with `www.bing.com` and your Bing search query URL would look like "https://www.bing.com/search?q={search query}"
9090

9191
```python
92-
run_steps = project_client.agents.list_run_steps(run_id=run.id, thread_id=thread.id)
92+
run_steps = project_client.agents.runs_steps.list(run_id=run.id, thread_id=thread.id)
9393
run_steps_data = run_steps['data']
9494
print(f"Last run step detail: {run_steps_data}")
9595
```

articles/ai-foundry/agents/how-to/tools/code-interpreter-samples.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ project_client = AIProjectClient(
6666
The sample uploads a data file for analysis:
6767

6868
```python
69-
file = project_client.agents.upload_file_and_poll(
69+
file = project_client.agents.files.upload_and_poll(
7070
file_path="nifty_500_quarterly_results.csv",
7171
purpose=FilePurpose.AGENTS
7272
)
@@ -122,7 +122,7 @@ messages = project_client.agents.messages.list(thread_id=thread.id)
122122
for image_content in messages.image_contents:
123123
file_id = image_content.image_file.file_id
124124
file_name = f"{file_id}_image_file.png"
125-
project_client.agents.save_file(file_id=file_id, file_name=file_name)
125+
project_client.agents.files.save(file_id=file_id, file_name=file_name)
126126

127127
# Process file path annotations
128128
for file_path_annotation in messages.file_path_annotations:
@@ -136,7 +136,7 @@ for file_path_annotation in messages.file_path_annotations:
136136
After completing the interaction, the code properly cleans up resources:
137137

138138
```python
139-
project_client.agents.delete_file(file.id)
139+
project_client.agents.files.delete(file.id)
140140
project_client.agents.delete_agent(agent.id)
141141
```
142142

articles/ai-foundry/agents/how-to/tools/file-search-upload-files.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ if run.status == "failed":
136136
project_client.agents.vector_stores.delete(vector_store.id)
137137
print("Deleted vector store")
138138

139-
project_client.agents.delete_file(file_id=file.id)
139+
project_client.agents.files.delete(file_id=file.id)
140140
print("Deleted file")
141141

142142
project_client.agents.delete_agent(agent.id)

articles/ai-foundry/agents/how-to/tools/file-search.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,11 @@ Files can also be added to a vector store after it's created by creating vector
9898
```python
9999

100100
# create a vector store with no file and wait for it to be processed
101-
vector_store = project_client.agents.create_vector_store_and_poll(data_sources=[], name="sample_vector_store")
101+
vector_store = project_client.agents.vector_stores.create_and_poll(data_sources=[], name="sample_vector_store")
102102
print(f"Created vector store, vector store ID: {vector_store.id}")
103103

104104
# add the file to the vector store or you can supply file ids in the vector store creation
105-
vector_store_file_batch = project_client.agents.create_vector_store_file_batch_and_poll(
105+
vector_store_file_batch = project_client.agents.vector_store_file_batches.create_and_poll(
106106
vector_store_id=vector_store.id, file_ids=[file.id]
107107
)
108108
print(f"Created vector store file batch, vector store file batch ID: {vector_store_file_batch.id}")
@@ -112,7 +112,7 @@ print(f"Created vector store file batch, vector store file batch ID: {vector_sto
112112
Alternatively, you can add several files to a vector store by creating batches of up to 500 files.
113113

114114
```python
115-
batch = project_client.agents.create_vector_store_file_batch_and_poll(
115+
batch = project_client.agents.vector_store_file_batches.create_and_poll(
116116
vector_store_id=vector_store.id,
117117
file_ids=[file_1.id, file_2.id, file_3.id, file_4.id, file_5.id]
118118
)
@@ -144,7 +144,7 @@ print(f"Updated agent, agent ID: {agent.id}")
144144

145145
## Deleting vector stores
146146
```python
147-
project_client.agents.delete_vector_store(vector_store.id)
147+
project_client.agents.vector_stores.delete(vector_store.id)
148148
print("Deleted vector store")
149149
```
150150

@@ -155,7 +155,7 @@ For basic agent setup, the `file_search` tool uses the `vector_stores` object a
155155
To help you manage the costs associated with these vector_store objects, we added support for expiration policies in the `vector_store` object. You can set these policies when creating or updating the `vector_store` object.
156156

157157
```python
158-
vector_store = project_client.agents.create_vector_store_and_poll(
158+
vector_store = project_client.agents.vector_stores.create_and_poll(
159159
name="Product Documentation",
160160
file_ids=[file_1.id],
161161
expires_after={

articles/ai-foundry/agents/how-to/tools/model-context-protocol-samples.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ Create the run, check the output, and examine what tools were called during the
139139

140140
## Perform cleanup
141141

142-
After the interaction is complete, the script performs cleanup by deleting the created agent resource via `agents_client.delete_agent()` to avoid leaving unused resources. It also fetches and prints the entire message history from the thread by using `agents_client.list_messages()` for review or logging.
142+
After the interaction is complete, the script performs cleanup by deleting the created agent resource via `agents_client.delete_agent()` to avoid leaving unused resources. It also fetches and prints the entire message history from the thread by using `agents_client.messages.list()` for review or logging.
143143

144144
```python
145145
# Delete the agent resource to clean up

articles/ai-foundry/agents/how-to/tools/openapi-spec-samples.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ Create the run, check the output, and examine what tools were called during the
155155

156156

157157
## Cleanup
158-
After the interaction is complete, the script performs cleanup by deleting the created agent resource using `agents_client.delete_agent()` to avoid leaving unused resources. It also fetches and prints the entire message history from the thread using `agents_client.list_messages()` for review or logging.
158+
After the interaction is complete, the script performs cleanup by deleting the created agent resource using `agents_client.delete_agent()` to avoid leaving unused resources. It also fetches and prints the entire message history from the thread using `agents_client.messages.list()` for review or logging.
159159

160160
```python
161161
# Delete the agent resource to clean up

articles/ai-foundry/how-to/continuous-evaluation-agents.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,16 +58,16 @@ agent = project_client.agents.create_agent(
5858
)
5959

6060
# Create thread and process user message
61-
thread = project_client.agents.create_thread()
62-
project_client.agents.create_message(thread_id=thread.id, role="user", content="Hello, what Contoso products do you know?")
63-
run = project_client.agents.create_and_process_run(thread_id=thread.id, agent_id=agent.id)
61+
thread = project_client.agents.threads.create()
62+
project_client.agents.messages.create(thread_id=thread.id, role="user", content="Hello, what Contoso products do you know?")
63+
run = project_client.agents.runs.create_and_process(thread_id=thread.id, agent_id=agent.id)
6464

6565
# Handle run status
6666
if run.status == "failed":
6767
print(f"Run failed: {run.last_error}")
6868

6969
# Print thread messages
70-
for message in project_client.agents.list_messages(thread_id=thread.id).text_messages:
70+
for message in project_client.agents.messages.list(thread_id=thread.id).text_messages:
7171
print(message)
7272

7373
```

articles/search/search-agentic-retrieval-how-to-pipeline.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ def agentic_retrieval() -> str:
203203
Be sure to use the same format in your agent's response
204204
"""
205205
# Take the last 5 messages in the conversation
206-
messages = project_client.agents.list_messages(thread.id, limit=5, order=ListSortOrder.DESCENDING)
206+
messages = project_client.agents.messages.list(thread.id, limit=5, order=ListSortOrder.DESCENDING)
207207
# Reverse the order so the most recent message is last
208208
messages.data.reverse()
209209
retrieval_result = retrieval_result = agent_client.retrieve(

0 commit comments

Comments
 (0)