Skip to content

Commit 8ac0ce5

Browse files
caohy1988claude
andcommitted
feat(bq-plugin): Add A2A tool_origin detection for RemoteA2aAgent
Extends _get_tool_origin() to detect AgentTool wrapping a RemoteA2aAgent and return "A2A" origin. Fixes existing test that used private _agent attribute instead of public agent attribute, and adds test for the new A2A origin path. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 98326eb commit 8ac0ce5

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

src/google/adk/plugins/bigquery_agent_analytics_plugin.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ def _get_tool_origin(tool: "BaseTool") -> str:
158158
tool: The tool instance.
159159
160160
Returns:
161-
One of LOCAL, MCP, SUB_AGENT, TRANSFER_AGENT, or UNKNOWN.
161+
One of LOCAL, MCP, A2A, SUB_AGENT, TRANSFER_AGENT, or UNKNOWN.
162162
"""
163163
# Import lazily to avoid circular dependencies.
164164
# pylint: disable=g-import-not-at-top
@@ -171,12 +171,19 @@ def _get_tool_origin(tool: "BaseTool") -> str:
171171
except ImportError:
172172
McpTool = None
173173

174+
try:
175+
from ..agents.remote_a2a_agent import RemoteA2aAgent # pytype: disable=import-error
176+
except ImportError:
177+
RemoteA2aAgent = None
178+
174179
# Order matters: TransferToAgentTool is a subclass of FunctionTool.
175180
if McpTool is not None and isinstance(tool, McpTool):
176181
return "MCP"
177182
if isinstance(tool, TransferToAgentTool):
178183
return "TRANSFER_AGENT"
179184
if isinstance(tool, AgentTool):
185+
if RemoteA2aAgent is not None and isinstance(tool.agent, RemoteA2aAgent):
186+
return "A2A"
180187
return "SUB_AGENT"
181188
if isinstance(tool, FunctionTool):
182189
return "LOCAL"

tests/unittests/plugins/test_bigquery_agent_analytics_plugin.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4064,7 +4064,7 @@ def test_agent_tool_returns_sub_agent(self):
40644064
agent = mock.MagicMock()
40654065
agent.name = "sub"
40664066
tool = AgentTool.__new__(AgentTool)
4067-
tool._agent = agent
4067+
tool.agent = agent
40684068
tool._name = "sub"
40694069
result = bigquery_agent_analytics_plugin._get_tool_origin(tool)
40704070
assert result == "SUB_AGENT"
@@ -4085,6 +4085,23 @@ def test_mcp_tool_returns_mcp(self):
40854085
result = bigquery_agent_analytics_plugin._get_tool_origin(tool)
40864086
assert result == "MCP"
40874087

4088+
def test_a2a_agent_tool_returns_a2a(self):
4089+
from google.adk.tools.agent_tool import AgentTool
4090+
4091+
try:
4092+
from google.adk.agents.remote_a2a_agent import RemoteA2aAgent
4093+
except ImportError:
4094+
pytest.skip("A2A agent not available")
4095+
4096+
remote_agent = mock.MagicMock(spec=RemoteA2aAgent)
4097+
remote_agent.name = "remote"
4098+
remote_agent.description = "remote a2a agent"
4099+
tool = AgentTool.__new__(AgentTool)
4100+
tool.agent = remote_agent
4101+
tool._name = "remote"
4102+
result = bigquery_agent_analytics_plugin._get_tool_origin(tool)
4103+
assert result == "A2A"
4104+
40884105
def test_unknown_tool_returns_unknown(self):
40894106
tool = mock.MagicMock(spec=base_tool_lib.BaseTool)
40904107
tool.name = "mystery"

0 commit comments

Comments
 (0)