Skip to content

Commit 5a0e068

Browse files
committed
try get green pipeline
1 parent 3b8b72d commit 5a0e068

4 files changed

Lines changed: 36 additions & 33 deletions

File tree

sdk/ai/azure-ai-agents/README.md

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -122,11 +122,12 @@ Here is an example of how to create an Agent:
122122
<!-- SNIPPET:sample_agents_basics.create_agent -->
123123

124124
```python
125-
agent = agents_client.create_agent(
126-
model=os.environ["MODEL_DEPLOYMENT_NAME"],
127-
name="my-agent",
128-
instructions="You are helpful agent",
129-
)
125+
126+
agent = agents_client.create_agent(
127+
model=os.environ["MODEL_DEPLOYMENT_NAME"],
128+
name="my-agent",
129+
instructions="You are helpful agent",
130+
)
130131
```
131132

132133
<!-- END SNIPPET -->
@@ -145,7 +146,7 @@ toolset.add(functions)
145146
toolset.add(code_interpreter)
146147

147148
# To enable tool calls executed automatically
148-
agents_client.enable_auto_function_calls(toolset=toolset)
149+
agents_client.enable_auto_function_calls(toolset)
149150

150151
agent = agents_client.create_agent(
151152
model=os.environ["MODEL_DEPLOYMENT_NAME"],
@@ -293,10 +294,8 @@ Here is an example:
293294
```python
294295
conn_id = os.environ["AZURE_BING_CONNECTION_ID"]
295296

296-
print(conn_id)
297-
298297
# Initialize agent bing tool and add the connection id
299-
bing = BingGroundingTool(connection_id==conn_id)
298+
bing = BingGroundingTool(connection_id=conn_id)
300299

301300
# Create agent with the bing tool and process agent run
302301
with agents_client:
@@ -351,7 +350,7 @@ get sensible result, the index needs to have "embedding", "token", "category" an
351350
```python
352351
# Fetch and log all messages
353352
messages = agents_client.messages.list(thread_id=thread.id, order=ListSortOrder.ASCENDING)
354-
for message in messages.data:
353+
for message in messages:
355354
if message.role == MessageRole.AGENT and message.url_citation_annotations:
356355
placeholder_annotations = {
357356
annotation.text: f" [see {annotation.url_citation.title}] ({annotation.url_citation.url})"
@@ -382,7 +381,7 @@ Here is an example to use [user functions](https://github.com/Azure/azure-sdk-fo
382381
functions = FunctionTool(user_functions)
383382
toolset = ToolSet()
384383
toolset.add(functions)
385-
agents_client.enable_auto_function_calls(toolset=toolset)
384+
agents_client.enable_auto_function_calls(toolset)
386385

387386
agent = agents_client.create_agent(
388387
model=os.environ["MODEL_DEPLOYMENT_NAME"],
@@ -407,7 +406,7 @@ functions = AsyncFunctionTool(user_async_functions)
407406

408407
toolset = AsyncToolSet()
409408
toolset.add(functions)
410-
agents_client.enable_auto_function_calls(toolset=toolset)
409+
agents_client.enable_auto_function_calls(toolset)
411410

412411
agent = await agents_client.create_agent(
413412
model=os.environ["MODEL_DEPLOYMENT_NAME"],
@@ -1044,13 +1043,10 @@ To retrieve messages from agents, use the following example:
10441043

10451044
```python
10461045
messages = agents_client.messages.list(thread_id=thread.id, order=ListSortOrder.ASCENDING)
1047-
1048-
# The messages are following in the reverse order,
1049-
# we will iterate them and output only text contents.
1050-
for data_point in messages.data:
1051-
last_message_content = data_point.content[-1]
1052-
if isinstance(last_message_content, MessageTextContent):
1053-
print(f"{data_point.role}: {last_message_content.text.value}")
1046+
for msg in messages:
1047+
if msg.text_messages:
1048+
last_text = msg.text_messages[-1]
1049+
print(f"{msg.role}: {last_text.text.value}")
10541050
```
10551051

10561052
<!-- END SNIPPET -->
@@ -1069,20 +1065,22 @@ Here is an example retrieving file ids from messages and save to the local drive
10691065
messages = agents_client.messages.list(thread_id=thread.id)
10701066
print(f"Messages: {messages}")
10711067

1072-
for image_content in messages.image_contents:
1073-
file_id = image_content.image_file.file_id
1074-
print(f"Image File ID: {file_id}")
1075-
file_name = f"{file_id}_image_file.png"
1076-
agents_client.files.save(file_id=file_id, file_name=file_name)
1077-
print(f"Saved image file to: {Path.cwd() / file_name}")
1078-
1079-
for file_path_annotation in messages.file_path_annotations:
1080-
print(f"File Paths:")
1081-
print(f"Type: {file_path_annotation.type}")
1082-
print(f"Text: {file_path_annotation.text}")
1083-
print(f"File ID: {file_path_annotation.file_path.file_id}")
1084-
print(f"Start Index: {file_path_annotation.start_index}")
1085-
print(f"End Index: {file_path_annotation.end_index}")
1068+
for msg in messages:
1069+
# Save every image file in the message
1070+
for img in msg.image_contents:
1071+
file_id = img.image_file.file_id
1072+
file_name = f"{file_id}_image_file.png"
1073+
agents_client.files.save(file_id=file_id, file_name=file_name)
1074+
print(f"Saved image file to: {Path.cwd() / file_name}")
1075+
1076+
# Print details of every file-path annotation
1077+
for ann in msg.file_path_annotations:
1078+
print("File Paths:")
1079+
print(f" Type: {ann.type}")
1080+
print(f" Text: {ann.text}")
1081+
print(f" File ID: {ann.file_path.file_id}")
1082+
print(f" Start Index: {ann.start_index}")
1083+
print(f" End Index: {ann.end_index}")
10861084
```
10871085

10881086
<!-- END SNIPPET -->
@@ -1175,6 +1173,8 @@ application_insights_connection_string = os.environ["AI_APPINSIGHTS_CONNECTION_S
11751173
configure_azure_monitor(connection_string=application_insights_connection_string)
11761174

11771175
# enable additional instrumentations
1176+
from azure.ai.agents.telemetry import enable_telemetry
1177+
11781178
enable_telemetry()
11791179

11801180
scenario = os.path.basename(__file__)

sdk/ai/azure-ai-agents/samples/agents_telemetry/sample_agents_basics_async_with_azure_monitor_tracing.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ async def main() -> None:
5454

5555
# enable additional instrumentations
5656
from azure.ai.agents.telemetry import enable_telemetry
57+
5758
enable_telemetry()
5859

5960
with tracer.start_as_current_span(scenario):

sdk/ai/azure-ai-agents/samples/agents_telemetry/sample_agents_basics_with_azure_monitor_tracing.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848

4949
# enable additional instrumentations
5050
from azure.ai.agents.telemetry import enable_telemetry
51+
5152
enable_telemetry()
5253

5354
scenario = os.path.basename(__file__)

sdk/ai/azure-ai-agents/samples/agents_telemetry/sample_agents_stream_eventhandler_with_azure_monitor_tracing.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ def on_unhandled_event(self, event_type: str, event_data: Any) -> None:
8787

8888
# enable additional instrumentations
8989
from azure.ai.agents.telemetry import enable_telemetry
90+
9091
enable_telemetry()
9192

9293
with tracer.start_as_current_span(scenario):

0 commit comments

Comments
 (0)