@@ -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)
145146toolset.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
150151agent = agents_client.create_agent(
151152 model = os.environ[" MODEL_DEPLOYMENT_NAME" ],
@@ -293,10 +294,8 @@ Here is an example:
293294``` python
294295conn_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
302301with 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
353352messages = 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
382381functions = FunctionTool(user_functions)
383382toolset = ToolSet()
384383toolset.add(functions)
385- agents_client.enable_auto_function_calls(toolset = toolset )
384+ agents_client.enable_auto_function_calls(toolset)
386385
387386agent = agents_client.create_agent(
388387 model = os.environ[" MODEL_DEPLOYMENT_NAME" ],
@@ -407,7 +406,7 @@ functions = AsyncFunctionTool(user_async_functions)
407406
408407toolset = AsyncToolSet()
409408toolset.add(functions)
410- agents_client.enable_auto_function_calls(toolset = toolset )
409+ agents_client.enable_auto_function_calls(toolset)
411410
412411agent = 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
10461045messages = 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
10691065messages = agents_client.messages.list(thread_id = thread.id)
10701066print (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
11751173configure_azure_monitor(connection_string = application_insights_connection_string)
11761174
11771175# enable additional instrumentations
1176+ from azure.ai.agents.telemetry import enable_telemetry
1177+
11781178enable_telemetry()
11791179
11801180scenario = os.path.basename(__file__ )
0 commit comments