Skip to content

Commit c4f30f2

Browse files
authored
Add connected agent tool to python code. (#42395)
* Add comnnected agent tool to python code. * Fix * Fix * Fix
1 parent 92ae66c commit c4f30f2

File tree

10 files changed

+783
-235
lines changed

10 files changed

+783
-235
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77

88
- Add support for Browser Automation tool.
99

10+
### Bugs Fixed
11+
12+
- Added `RunStepConnectedAgentToolCall` and `RunStepDeltaConnectedAgentToolCall` for deserializing Connected Agent tool updates in non-streaming and streaming scenarios.
13+
1014
### Sample updates
1115

1216
- Add new samples `sample_agents_browser_automation.py` and `sample_agents_browser_automation_async.py`.
@@ -24,6 +28,7 @@
2428

2529
### Bugs Fixed
2630
- Fixed issues where the `runs.create_and_process` API call did not correctly handle the `AzureAISearchTool`, `FileSearchTool`, and `CodeInterpreterTool` when specified in the toolset parameter.
31+
- Added classes for deserialization of `RunStepDeltaAzureAISearchToolCall`, `RunStepDeltaOpenAPIToolCall` and `RunStepDeltaDeepResearchToolCall`, required to get the real time updates when Azure AI Search, OpenAPI or Deep Research tools are being used during streaming scenarios.
2732

2833
### Sample updates
2934
- Updated `sample_agents_deep_research.py` and `sample_agents_deep_research_async.py` for citations.

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1077,11 +1077,12 @@ To understand what calls were made by the main agent to the connected ones, we w
10771077
for run_step in agents_client.run_steps.list(thread_id=thread.id, run_id=run.id, order=ListSortOrder.ASCENDING):
10781078
if isinstance(run_step.step_details, RunStepToolCallDetails):
10791079
for tool_call in run_step.step_details.tool_calls:
1080-
print(
1081-
f"\tAgent: {tool_call._data['connected_agent']['name']} "
1082-
f"query: {tool_call._data['connected_agent']['arguments']} ",
1083-
f"output: {tool_call._data['connected_agent']['output']}",
1084-
)
1080+
if isinstance(tool_call, RunStepConnectedAgentToolCall):
1081+
print(
1082+
f"\tAgent: {tool_call.connected_agent.name} "
1083+
f"query: {tool_call.connected_agent.arguments} ",
1084+
f"output: {tool_call.connected_agent.output}",
1085+
)
10851086
```
10861087

10871088
<!-- END SNIPPET -->

sdk/ai/azure-ai-agents/apiview-properties.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,8 @@
115115
"azure.ai.agents.models.RunStepCodeInterpreterToolCall": "Azure.AI.Agents.RunStepCodeInterpreterToolCall",
116116
"azure.ai.agents.models.RunStepCodeInterpreterToolCallDetails": "Azure.AI.Agents.RunStepCodeInterpreterToolCallDetails",
117117
"azure.ai.agents.models.RunStepCompletionUsage": "Azure.AI.Agents.RunStepCompletionUsage",
118+
"azure.ai.agents.models.RunStepConnectedAgent": "Azure.AI.Agents.RunStepConnectedAgent",
119+
"azure.ai.agents.models.RunStepConnectedAgentToolCall": "Azure.AI.Agents.RunStepConnectedAgentToolCall",
118120
"azure.ai.agents.models.RunStepDeepResearchToolCall": "Azure.AI.Agents.RunStepDeepResearchToolCall",
119121
"azure.ai.agents.models.RunStepDeepResearchToolCallDetails": "Azure.AI.Agents.RunStepDeepResearchToolCallDetails",
120122
"azure.ai.agents.models.RunStepDelta": "Azure.AI.Agents.RunStepDelta",
@@ -128,6 +130,7 @@
128130
"azure.ai.agents.models.RunStepDeltaCodeInterpreterImageOutputObject": "Azure.AI.Agents.RunStepDeltaCodeInterpreterImageOutputObject",
129131
"azure.ai.agents.models.RunStepDeltaCodeInterpreterLogOutput": "Azure.AI.Agents.RunStepDeltaCodeInterpreterLogOutput",
130132
"azure.ai.agents.models.RunStepDeltaCodeInterpreterToolCall": "Azure.AI.Agents.RunStepDeltaCodeInterpreterToolCall",
133+
"azure.ai.agents.models.RunStepDeltaConnectedAgentToolCall": "Azure.AI.Agents.RunStepDeltaConnectedAgentToolCall",
131134
"azure.ai.agents.models.RunStepDeltaDeepResearchToolCall": "Azure.AI.Agents.RunStepDeltaDeepResearchToolCall",
132135
"azure.ai.agents.models.RunStepDeltaDetail": "Azure.AI.Agents.RunStepDeltaDetail",
133136
"azure.ai.agents.models.RunStepDeltaFileSearchToolCall": "Azure.AI.Agents.RunStepDeltaFileSearchToolCall",

sdk/ai/azure-ai-agents/assets.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
"AssetsRepo": "Azure/azure-sdk-assets",
33
"AssetsRepoPrefixPath": "python",
44
"TagPrefix": "python/ai/azure-ai-agents",
5-
"Tag": "python/ai/azure-ai-agents_522b449948"
5+
"Tag": "python/ai/azure-ai-agents_0a512f2bb3"
66
}

sdk/ai/azure-ai-agents/azure/ai/agents/models/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,8 @@
126126
RunStepCodeInterpreterToolCallDetails,
127127
RunStepCodeInterpreterToolCallOutput,
128128
RunStepCompletionUsage,
129+
RunStepConnectedAgent,
130+
RunStepConnectedAgentToolCall,
129131
RunStepDeepResearchToolCall,
130132
RunStepDeepResearchToolCallDetails,
131133
RunStepDelta,
@@ -138,6 +140,7 @@
138140
RunStepDeltaCodeInterpreterLogOutput,
139141
RunStepDeltaCodeInterpreterOutput,
140142
RunStepDeltaCodeInterpreterToolCall,
143+
RunStepDeltaConnectedAgentToolCall,
141144
RunStepDeltaDeepResearchToolCall,
142145
RunStepDeltaDetail,
143146
RunStepDeltaFileSearchToolCall,
@@ -355,6 +358,8 @@
355358
"RunStepCodeInterpreterToolCallDetails",
356359
"RunStepCodeInterpreterToolCallOutput",
357360
"RunStepCompletionUsage",
361+
"RunStepConnectedAgent",
362+
"RunStepConnectedAgentToolCall",
358363
"RunStepDeepResearchToolCall",
359364
"RunStepDeepResearchToolCallDetails",
360365
"RunStepDelta",
@@ -367,6 +372,7 @@
367372
"RunStepDeltaCodeInterpreterLogOutput",
368373
"RunStepDeltaCodeInterpreterOutput",
369374
"RunStepDeltaCodeInterpreterToolCall",
375+
"RunStepDeltaConnectedAgentToolCall",
370376
"RunStepDeltaDeepResearchToolCall",
371377
"RunStepDeltaDetail",
372378
"RunStepDeltaFileSearchToolCall",

sdk/ai/azure-ai-agents/azure/ai/agents/models/_models.py

Lines changed: 144 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4149,9 +4149,10 @@ class RunStepToolCall(_Model):
41494149
41504150
You probably want to use the sub-classes and not this class directly. Known sub-classes are:
41514151
RunStepAzureAISearchToolCall, RunStepBingCustomSearchToolCall, RunStepBingGroundingToolCall,
4152-
RunStepBrowserAutomationToolCall, RunStepCodeInterpreterToolCall, RunStepDeepResearchToolCall,
4153-
RunStepMicrosoftFabricToolCall, RunStepFileSearchToolCall, RunStepFunctionToolCall,
4154-
RunStepMcpToolCall, RunStepOpenAPIToolCall, RunStepSharepointToolCall
4152+
RunStepBrowserAutomationToolCall, RunStepCodeInterpreterToolCall,
4153+
RunStepConnectedAgentToolCall, RunStepDeepResearchToolCall, RunStepMicrosoftFabricToolCall,
4154+
RunStepFileSearchToolCall, RunStepFunctionToolCall, RunStepMcpToolCall, RunStepOpenAPIToolCall,
4155+
RunStepSharepointToolCall
41554156
41564157
:ivar type: The object type. Required. Default value is None.
41574158
:vartype type: str
@@ -4591,6 +4592,101 @@ def __init__(self, *args: Any, **kwargs: Any) -> None:
45914592
super().__init__(*args, **kwargs)
45924593

45934594

4595+
class RunStepConnectedAgent(_Model):
4596+
"""The detailed information about connected agent tool call.
4597+
4598+
:ivar name: The name of connected agent.
4599+
:vartype name: str
4600+
:ivar arguments: The JSON serialized query to the connected agent.
4601+
:vartype arguments: str
4602+
:ivar output: The tool output.
4603+
:vartype output: str
4604+
:ivar run_id: The run ID used by the connected agent.
4605+
:vartype run_id: str
4606+
:ivar thread_id: The thread ID used by the connected agent.
4607+
:vartype thread_id: str
4608+
:ivar agent_id: The ID of a connected agent.
4609+
:vartype agent_id: str
4610+
"""
4611+
4612+
name: Optional[str] = rest_field(visibility=["read", "create", "update", "delete", "query"])
4613+
"""The name of connected agent."""
4614+
arguments: Optional[str] = rest_field(visibility=["read", "create", "update", "delete", "query"])
4615+
"""The JSON serialized query to the connected agent."""
4616+
output: Optional[str] = rest_field(visibility=["read", "create", "update", "delete", "query"])
4617+
"""The tool output."""
4618+
run_id: Optional[str] = rest_field(visibility=["read", "create", "update", "delete", "query"])
4619+
"""The run ID used by the connected agent."""
4620+
thread_id: Optional[str] = rest_field(visibility=["read", "create", "update", "delete", "query"])
4621+
"""The thread ID used by the connected agent."""
4622+
agent_id: Optional[str] = rest_field(
4623+
name="assistant_id", visibility=["read", "create", "update", "delete", "query"]
4624+
)
4625+
"""The ID of a connected agent."""
4626+
4627+
@overload
4628+
def __init__(
4629+
self,
4630+
*,
4631+
name: Optional[str] = None,
4632+
arguments: Optional[str] = None,
4633+
output: Optional[str] = None,
4634+
run_id: Optional[str] = None,
4635+
thread_id: Optional[str] = None,
4636+
agent_id: Optional[str] = None,
4637+
) -> None: ...
4638+
4639+
@overload
4640+
def __init__(self, mapping: Mapping[str, Any]) -> None:
4641+
"""
4642+
:param mapping: raw JSON to initialize the model.
4643+
:type mapping: Mapping[str, Any]
4644+
"""
4645+
4646+
def __init__(self, *args: Any, **kwargs: Any) -> None:
4647+
super().__init__(*args, **kwargs)
4648+
4649+
4650+
class RunStepConnectedAgentToolCall(RunStepToolCall, discriminator="connected_agent"):
4651+
"""A record of a call to the connected agent.
4652+
4653+
:ivar id: The ID of the tool call. This ID must be referenced when you submit tool outputs.
4654+
Required.
4655+
:vartype id: str
4656+
:ivar type: The object type, which is always 'connected_agent'. Required. Default value is
4657+
"connected_agent".
4658+
:vartype type: str
4659+
:ivar connected_agent: The connected agent step information. Required.
4660+
:vartype connected_agent: ~azure.ai.agents.models.RunStepConnectedAgent
4661+
"""
4662+
4663+
type: Literal["connected_agent"] = rest_discriminator(name="type", visibility=["read", "create", "update", "delete", "query"]) # type: ignore
4664+
"""The object type, which is always 'connected_agent'. Required. Default value is
4665+
\"connected_agent\"."""
4666+
connected_agent: "_models.RunStepConnectedAgent" = rest_field(
4667+
visibility=["read", "create", "update", "delete", "query"]
4668+
)
4669+
"""The connected agent step information. Required."""
4670+
4671+
@overload
4672+
def __init__(
4673+
self,
4674+
*,
4675+
id: str, # pylint: disable=redefined-builtin
4676+
connected_agent: "_models.RunStepConnectedAgent",
4677+
) -> None: ...
4678+
4679+
@overload
4680+
def __init__(self, mapping: Mapping[str, Any]) -> None:
4681+
"""
4682+
:param mapping: raw JSON to initialize the model.
4683+
:type mapping: Mapping[str, Any]
4684+
"""
4685+
4686+
def __init__(self, *args: Any, **kwargs: Any) -> None:
4687+
super().__init__(*args, type="connected_agent", **kwargs)
4688+
4689+
45944690
class RunStepDeepResearchToolCall(RunStepToolCall, discriminator="deep_research"):
45954691
"""A record of a call to a Deep Research tool, issued by the model in evaluation of a defined
45964692
tool, that represents
@@ -4702,9 +4798,9 @@ class RunStepDeltaToolCall(_Model):
47024798
47034799
You probably want to use the sub-classes and not this class directly. Known sub-classes are:
47044800
RunStepDeltaAzureAISearchToolCall, RunStepDeltaBingGroundingToolCall,
4705-
RunStepDeltaCodeInterpreterToolCall, RunStepDeltaDeepResearchToolCall,
4706-
RunStepDeltaFileSearchToolCall, RunStepDeltaFunctionToolCall, RunStepDeltaMcpToolCall,
4707-
RunStepDeltaOpenAPIToolCall
4801+
RunStepDeltaCodeInterpreterToolCall, RunStepDeltaConnectedAgentToolCall,
4802+
RunStepDeltaDeepResearchToolCall, RunStepDeltaFileSearchToolCall, RunStepDeltaFunctionToolCall,
4803+
RunStepDeltaMcpToolCall, RunStepDeltaOpenAPIToolCall
47084804
47094805
:ivar index: The index of the tool call detail in the run step's tool_calls array. Required.
47104806
:vartype index: int
@@ -5092,6 +5188,48 @@ def __init__(self, *args: Any, **kwargs: Any) -> None:
50925188
super().__init__(*args, type="code_interpreter", **kwargs)
50935189

50945190

5191+
class RunStepDeltaConnectedAgentToolCall(RunStepDeltaToolCall, discriminator="connected_agent"):
5192+
"""Represents the invocation of connected agent as a part of a streaming run step.
5193+
5194+
:ivar index: The index of the tool call detail in the run step's tool_calls array. Required.
5195+
:vartype index: int
5196+
:ivar id: The ID of the tool call, used when submitting outputs to the run. Required.
5197+
:vartype id: str
5198+
:ivar type: The object type, which is always "connected_agent". Required. Default value is
5199+
"connected_agent".
5200+
:vartype type: str
5201+
:ivar connected_agent: The collection of tool calls for the tool call detail item. Required.
5202+
:vartype connected_agent: ~azure.ai.agents.models.RunStepConnectedAgent
5203+
"""
5204+
5205+
type: Literal["connected_agent"] = rest_discriminator(name="type", visibility=["read", "create", "update", "delete", "query"]) # type: ignore
5206+
"""The object type, which is always \"connected_agent\". Required. Default value is
5207+
\"connected_agent\"."""
5208+
connected_agent: "_models.RunStepConnectedAgent" = rest_field(
5209+
visibility=["read", "create", "update", "delete", "query"]
5210+
)
5211+
"""The collection of tool calls for the tool call detail item. Required."""
5212+
5213+
@overload
5214+
def __init__(
5215+
self,
5216+
*,
5217+
index: int,
5218+
id: str, # pylint: disable=redefined-builtin
5219+
connected_agent: "_models.RunStepConnectedAgent",
5220+
) -> None: ...
5221+
5222+
@overload
5223+
def __init__(self, mapping: Mapping[str, Any]) -> None:
5224+
"""
5225+
:param mapping: raw JSON to initialize the model.
5226+
:type mapping: Mapping[str, Any]
5227+
"""
5228+
5229+
def __init__(self, *args: Any, **kwargs: Any) -> None:
5230+
super().__init__(*args, type="connected_agent", **kwargs)
5231+
5232+
50955233
class RunStepDeltaDeepResearchToolCall(RunStepDeltaToolCall, discriminator="deep_research"):
50965234
"""Represents the Deep research in a streaming run step.
50975235

sdk/ai/azure-ai-agents/samples/agents_tools/sample_agents_multiple_connected_agents.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
# Copyright (c) Microsoft Corporation.
44
# Licensed under the MIT License.
55
# ------------------------------------
6+
from azure.ai.agents.models._models import RunStepConnectedAgentToolCall
67

78
"""
89
DESCRIPTION:
@@ -154,11 +155,12 @@
154155
for run_step in agents_client.run_steps.list(thread_id=thread.id, run_id=run.id, order=ListSortOrder.ASCENDING):
155156
if isinstance(run_step.step_details, RunStepToolCallDetails):
156157
for tool_call in run_step.step_details.tool_calls:
157-
print(
158-
f"\tAgent: {tool_call._data['connected_agent']['name']} "
159-
f"query: {tool_call._data['connected_agent']['arguments']} ",
160-
f"output: {tool_call._data['connected_agent']['output']}",
161-
)
158+
if isinstance(tool_call, RunStepConnectedAgentToolCall):
159+
print(
160+
f"\tAgent: {tool_call.connected_agent.name} "
161+
f"query: {tool_call.connected_agent.arguments} ",
162+
f"output: {tool_call.connected_agent.output}",
163+
)
162164
# [END list_tool_calls]
163165

164166
# [START list_messages]

0 commit comments

Comments
 (0)