Skip to content

fix: classify TransferToAgentTool transfers to RemoteA2aAgent as TRANSFER_A2A#5317

Closed
caohy1988 wants to merge 2 commits intogoogle:mainfrom
caohy1988:fix/transfer-a2a-tool-origin-classification
Closed

fix: classify TransferToAgentTool transfers to RemoteA2aAgent as TRANSFER_A2A#5317
caohy1988 wants to merge 2 commits intogoogle:mainfrom
caohy1988:fix/transfer-a2a-tool-origin-classification

Conversation

@caohy1988
Copy link
Copy Markdown

Summary

Fixes #5073

When a RemoteA2aAgent is registered via sub_agents=[], the BigQueryAgentAnalyticsPlugin now correctly classifies transfers to it as TRANSFER_A2A instead of the generic TRANSFER_AGENT.

Implementation Approach

Per the architectural decision in the issue thread, the fix is localized entirely to the BigQuery analytics plugin — no changes to TransferToAgentTool or the ADK core.

The plugin resolves the transfer origin at call-level in before_tool_callback / after_tool_callback:

  1. Detects TransferToAgentTool instances
  2. Extracts agent_name from tool_args
  3. Looks up the target in the agent tree via tool_context._invocation_context.agent
  4. Classifies as TRANSFER_A2A if the target is a RemoteA2aAgent, otherwise TRANSFER_AGENT

This means a single TransferToAgentTool with mixed local and A2A targets produces the correct label per invocation.

Changes

  • bigquery_agent_analytics_plugin.py: Added _find_transfer_target() helper and extended _get_tool_origin() with optional tool_args/tool_context parameters for call-level transfer classification
  • test_bigquery_agent_analytics_plugin.py: Added 5 new test cases covering A2A sub-agent, local sub-agent, A2A peer, mixed-target per-call classification, and fallback without args

Classification Table

Tool path Selected target Label
AgentTool(local agent) SUB_AGENT (unchanged)
AgentTool(RemoteA2aAgent) A2A (unchanged)
FunctionTool LOCAL (unchanged)
McpTool MCP (unchanged)
TransferToAgentTool local agent TRANSFER_AGENT (unchanged)
TransferToAgentTool RemoteA2aAgent TRANSFER_A2A (new)

Test plan

  • All 198 existing plugin tests pass
  • 5 new tests cover the new classification:
    • Transfer to RemoteA2aAgent sub-agent → TRANSFER_A2A
    • Transfer to local sub-agent → TRANSFER_AGENT
    • Transfer to RemoteA2aAgent peer → TRANSFER_A2A
    • Mixed targets classify correctly per call
    • Fallback to TRANSFER_AGENT when no tool_args/tool_context provided

🤖 Generated with Claude Code

…SFER_A2A

When a RemoteA2aAgent is registered via sub_agents, the BigQuery analytics
plugin now correctly classifies transfers to it as "TRANSFER_A2A" instead
of the generic "TRANSFER_AGENT". Classification is call-level: a single
TransferToAgentTool with mixed local and A2A targets produces the correct
label per invocation based on the selected agent_name.

The fix is localized to the plugin — no changes to TransferToAgentTool or
the ADK core. The plugin resolves the target agent at runtime via the
invocation context's agent tree.

Fixes google#5073

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@google-cla
Copy link
Copy Markdown

google-cla bot commented Apr 14, 2026

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@adk-bot adk-bot added the core [Component] This issue is related to the core interface and implementation label Apr 14, 2026
@adk-bot
Copy link
Copy Markdown
Collaborator

adk-bot commented Apr 14, 2026

Response from ADK Triaging Agent

Hello @caohy1988, thank you for creating this PR!

It looks like you haven't signed the Contributor License Agreement (CLA) yet. Before we can review your pull request, you'll need to sign the CLA.

This information will help reviewers to review your PR more efficiently. Thanks!

…_callback

The error callback path was still calling _get_tool_origin(tool) without
the tool_args and tool_context needed for call-level A2A classification,
leaving failed remote A2A transfers misclassified as TRANSFER_AGENT.

Adds a callback-level regression test that exercises on_tool_error_callback
with a TransferToAgentTool targeting a RemoteA2aAgent and asserts the
logged tool_origin is TRANSFER_A2A.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@caohy1988 caohy1988 closed this Apr 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core [Component] This issue is related to the core interface and implementation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BigQueryAgentAnalyticsPlugin: tool_origin not set to "A2A" when RemoteA2aAgent is used via sub_agents

2 participants