Skip to content

fix(a2a): keep same-turn task delegations to one remote agent apart - #8246

Open
burrows99 wants to merge 2 commits into
google:mainfrom
burrows99:fix/remote-task-sibling-calls
Open

burrows99 wants to merge 2 commits into
google:mainfrom
burrows99:fix/remote-task-sibling-calls

Conversation

@burrows99

Copy link
Copy Markdown

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):

Problem:

When one model turn delegates twice to the same RemoteA2aAgent(mode="task"):

  1. The first task's request carried both requests. _construct_message_parts_from_session renders the coordinator's event as quoted text (_present_other_agent_message) before its sibling-call filter runs, so by the time the filter looks at the parts there is no function_call left to skip.
  2. The second task was sent as a resume of the first. The function response that closed the first task is the last user event when the second task starts, so _create_a2a_request_for_user_function_response matched it to the coordinator's call and sent it to the peer, which has no such call and rejects it.

Solution:

  1. Drop the coordinator's calls for other tasks from the event before it is rendered (_without_sibling_calls, same shape as _without_credential_parts). The old per-part filter is removed, since it could no longer match anything.
  2. In task mode, _create_a2a_request_for_user_function_response returns None when the last user event answers a delegation to this agent (a function response named after the agent, the same test _is_remote_response uses for a completed delegation). The next delegation then starts a new task. A response to a pause the peer raised still resumes the task.

The existing test test_construct_message_parts_from_session_filters_sibling_fcs patched _present_other_agent_message to a no-op, which is why it passed. It now uses real events and the real presenter.

flowchart TD
    A[One turn delegates twice to one remote agent] --> B{Requests sent}
    B -->|Before| C[First asks for both and second is a bad resume]
    B -->|After| D[Each task asks only for its own request]
Loading

Narrated recording, before then after (sound on):

evidence.mp4

Testing Plan

Unit Tests:

  • I have added or updated unit tests for my change.

  • All unit tests pass locally.

  • test_construct_message_parts_from_session_filters_sibling_fcs (rewritten with real events): the task's request holds its own request and not the sibling's.

  • test_create_a2a_request_for_user_function_response_after_earlier_task (new): the response that closed an earlier task is not sent as a resume.

$ pytest tests/unittests/a2a/agent/test_remote_a2a_agent.py -k "filters_sibling_fcs or after_earlier_task"   # on main
2 failed

$ pytest tests/unittests/a2a tests/unittests/workflow   # this branch, after merging current main (c38ecdae6)
2507 passed, 57 skipped, 2 xfailed

pyink and isort with the repo config leave the changed files unchanged.

Manual End-to-End (E2E) Tests:

delegations.py builds the session the issue describes (no network, no API key) and asks RemoteA2aAgent what it would send for each task.

On main:

$ python delegations.py two
one model turn delegates twice to the same remote agent:
  task c-1: new task asking for ['Revenue Q1', 'Revenue Q2']
  task c-2: sent as a resume of a paused task

On this branch:

$ python delegations.py two
one model turn delegates twice to the same remote agent:
  task c-1: new task asking for ['Revenue Q1']
  task c-2: new task asking for ['Revenue Q2']

Edge cases and unchanged behaviour checked (in the recording, on this branch):

  • A delegation next to a call to another tool in the same turn: the other tool's call is left out of the task's request (on main it leaked in too).
  • A single delegation: unchanged.
  • The remote agent pauses for input and the user answers: still sent as a resume of that task.

Checklist

  • I have read the CONTRIBUTING.md document.
  • I have performed a self-review of my own code.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have added tests that prove my fix is effective or that my feature works.
  • New and existing unit tests pass locally with my changes.
  • I have manually tested my changes end-to-end. (the scripted runs above and in the recording were made by the AI assistant; not tested against a live served A2A agent)
  • Any dependent changes have been merged and published in downstream modules.

Additional context

This change was prepared with AI assistance (Claude Code), which also ran the tests and recorded the runs shown above.

🤖 Generated with Claude Code

When a coordinator delegated two tasks to the same RemoteA2aAgent in one
turn, the first task's request carried both requests, because the sibling
call filter ran after the coordinator's event had been rendered as text.
The second task was then sent as a resume of the first, because the
function response that closed the first task was taken for a reply to a
pause the peer raised.

Drop sibling calls from the event before it is rendered, and do not treat
a response to a delegation to this agent as a resume in task mode.

Fixes google#8242
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

RemoteA2aAgent(mode="task"): two calls to the same remote agent in one model turn send both requests to the first task and fail the second

1 participant