fix(a2a): Use card descriptions for initial routing - #6694
Open
ftnext wants to merge 2 commits into
Open
Conversation
Resolve remote agent-card descriptions before the parent LLM builds its first transfer prompt. Keep authenticated card metadata invocation-scoped, preserve explicitly configured descriptions, and fall back without blocking routing when card discovery fails. Fixes google#4064
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Please ensure you have read the contribution guide before creating a pull request.
Link to Issue or Description of Change
1. Link to an existing issue (if applicable):
2. Or, if no issue exists, describe the change:
N/A
Problem:
When a
RemoteA2aAgentis configured with an agent-card URL or file path and without an explicit description, its card is currently resolved only after the remote agent has been selected and invoked.The parent LLM therefore builds its initial transfer prompt with an empty description.
This prevents the card description from contributing to the first delegation decision and requires applications to duplicate the description in both the agent card and the local
RemoteA2aAgentconfiguration.A previous proposal in #6234 addressed the same cold-start problem, but it predated invocation-scoped authenticated agent-card resolution.
Resolving a card without the current
InvocationContext, or copying authenticated card metadata into shared agent state, could leak session-specific metadata between invocations.Solution:
Add an internal, invocation-aware transfer-description hook to
BaseAgent.Regular agents return their configured description, while
RemoteA2aAgentuses the following precedence:InvocationContextand return its description.The transfer request processor resolves descriptions for all transfer targets concurrently before constructing the parent LLM's transfer prompt.
If card discovery fails, the processor logs a warning and falls back to the locally configured description instead of preventing the parent LLM request.
This change intentionally does not add agent-card skills, tags, or examples to the transfer prompt and does not introduce a new card refresh policy.
Those concerns can be handled separately.
Testing Plan
Unit Tests:
The tests cover:
Command:
Result:
The existing warnings are primarily experimental A2A warnings and existing test warnings.
The changed files also pass the repository pre-commit hooks:
Relevant strict type checking also passes:
Manual End-to-End (E2E) Tests:
Planned verification using the existing
a2a_basicsample:Start the remote A2A server:
Configure the remote client without a local description and give it a neutral name such as
remote_agent.Remove explicit prime-agent routing instructions from the parent agent, so the agent-card description is the only capability information available for selecting the remote agent.
Start ADK Web:
In a fresh session, send:
Verify that:
remote_agenton the first turndebug.log (agent-card.json was fetched!)
Checklist
Additional context
The transfer prompt uses invocation-scoped metadata objects rather than mutating the shared
RemoteA2aAgent.description.This is important for authenticated or extended agent cards whose descriptions may differ between sessions.
Public and file-based cards may still be cached using the existing shared-card lifecycle.
When the remote agent itself initializes, it retains the existing behavior of adopting the resolved public card description.