Skip to content

feat(plugins): add TRANSFER_A2A classification for TransferToAgentTool#5078

Draft
caohy1988 wants to merge 3 commits intogoogle:mainfrom
caohy1988:feat/transfer-a2a-classification
Draft

feat(plugins): add TRANSFER_A2A classification for TransferToAgentTool#5078
caohy1988 wants to merge 3 commits intogoogle:mainfrom
caohy1988:feat/transfer-a2a-classification

Conversation

@caohy1988
Copy link
Copy Markdown

@caohy1988 caohy1988 commented Mar 31, 2026

Summary

  • Adds target_origin_by_name metadata to TransferToAgentTool so analytics can distinguish remote A2A transfers from local agent transfers
  • Populates the origin map in agent_transfer.py using isinstance(agent, RemoteA2aAgent) at tool construction time
  • Adds _resolve_transfer_origin() helper in the BQ analytics plugin to refine TRANSFER_AGENTTRANSFER_A2A at call time using tool_args["agent_name"]

Fixes #5073

Test plan

  • 2 new tests in test_transfer_to_agent_tool.py — metadata storage (default empty, stored map)
  • 1 new test in test_agent_transfer_system_instructions.py — wiring produces correct origin map with mixed local + A2A sub-agents
  • 5 new tests in TestToolProvenance — all _resolve_transfer_origin branches (remote target, local target, no args, missing key, unknown name)
  • 2 new e2e callback tests — before_tool_callback and after_tool_callback emit tool_origin=TRANSFER_A2A in serialized BQ rows
  • All 195 existing BQ plugin tests pass (regression)
  • All existing transfer tool and agent transfer tests pass

End-to-end validation against real BigQuery

Validation script: contributing/samples/validate_transfer_a2a/validate.py

Architecture:

orchestrator_agent (gemini-2.0-flash)
    ├── local_weather_agent   (local sub-agent)
    └── remote_math_agent     (RemoteA2aAgent → in-process A2A server)

The script starts an in-process A2A server (ASGI transport), creates an orchestrator with both sub-agent types, wires BigQueryAgentAnalyticsPlugin to a real GCP project, sends two prompts (one math, one weather), then queries BQ to verify classification.

BQ query results (test-project-0728-467323.adk_logs.transfer_a2a_validation)

SELECT event_type, JSON_VALUE(content, '$.tool_origin') AS tool_origin, content
FROM `test-project-0728-467323.adk_logs.transfer_a2a_validation`
WHERE event_type IN ('TOOL_STARTING', 'TOOL_COMPLETED')
  AND JSON_VALUE(content, '$.tool') = 'transfer_to_agent'
ORDER BY timestamp ASC
event_type tool_origin content
TOOL_STARTING TRANSFER_A2A {"args":{"agent_name":"remote_math_agent"},"tool":"transfer_to_agent","tool_origin":"TRANSFER_A2A"}
TOOL_COMPLETED TRANSFER_A2A {"result":null,"tool":"transfer_to_agent","tool_origin":"TRANSFER_A2A"}
TOOL_STARTING TRANSFER_AGENT {"args":{"agent_name":"local_weather_agent"},"tool":"transfer_to_agent","tool_origin":"TRANSFER_AGENT"}
TOOL_COMPLETED TRANSFER_AGENT {"result":null,"tool":"transfer_to_agent","tool_origin":"TRANSFER_AGENT"}

Feature-level validation

# Feature BQ Evidence Status
1 target_origin_by_name metadata stored on tool TOOL_STARTING rows show different tool_origin per agent — impossible without the metadata map Validated
2 isinstance(RemoteA2aAgent) population at construction remote_math_agentTRANSFER_A2A, local_weather_agentTRANSFER_AGENT Validated
3 _resolve_transfer_origin() using tool_args["agent_name"] All 4 rows (both callbacks, both transfer types) carry correctly resolved tool_origin Validated

Note: TOOL_COMPLETED rows don't include args in the content JSON (by design — after_tool_callback serializes result, not args), but tool_origin is resolved from tool_args before serialization, so both TOOL_STARTING and TOOL_COMPLETED carry the correct classification.

🤖 Generated with Claude Code

When RemoteA2aAgent is used via sub_agents, the framework creates a
TransferToAgentTool that only stores agent names. The analytics plugin
returned TRANSFER_AGENT unconditionally for all transfer tools, losing
the A2A distinction. This preserves transfer-target origin metadata so
analytics can distinguish remote A2A transfers from local ones.

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

google-cla bot commented Mar 31, 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 Mar 31, 2026
@adk-bot
Copy link
Copy Markdown
Collaborator

adk-bot commented Mar 31, 2026

Response from ADK Triaging Agent

Hello @caohy1988, thank you for creating this PR!

Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). You can find more information in the "checks" section at the bottom of the pull request. Thanks!

caohy1988 and others added 2 commits March 31, 2026 00:13
Exercises before_tool_callback and after_tool_callback with a real
TransferToAgentTool and asserts that tool_origin="TRANSFER_A2A" appears
in the serialized BigQuery row content, closing the testing gap between
the unit-level _resolve_transfer_origin tests and the actual callback
wiring.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Spins up an in-process A2A server (ASGI transport), creates an
orchestrator with one local sub-agent and one RemoteA2aAgent,
runs transfers through BigQueryAgentAnalyticsPlugin with real GCP
credentials, and queries BQ to verify tool_origin correctly shows
TRANSFER_A2A for remote agents and TRANSFER_AGENT for local agents.

Validated against test-project-0728-467323.adk_logs.transfer_a2a_validation.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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