Skip to content

fix: RemoteA2aAgent fails to send taskId in multi-turn scenarios#4944

Open
shriramThakare3 wants to merge 1 commit intogoogle:mainfrom
shriramThakare3:main
Open

fix: RemoteA2aAgent fails to send taskId in multi-turn scenarios#4944
shriramThakare3 wants to merge 1 commit intogoogle:mainfrom
shriramThakare3:main

Conversation

@shriramThakare3
Copy link

Link to Issue or Description of Change

1. Link to an existing issue (if applicable):

Problem:
RemoteA2aAgent only sends context_id on subsequent turns, never task_id, causing the remote server to spawn a new task every turn instead of resuming the paused one. A multi-turn flow (e.g. input-required → user replies) always creates stale orphaned tasks on the remote agent.

Solution:
In _construct_message_parts_from_session, after reading context_id from custom_metadata, also read the stored task state from the previous response metadata. Forward task_id only when the task is still open (input-required or auth-required). For terminal states (completed, failed, cancelled) task_id stays None so the server correctly starts a fresh task under the same context_id.

Testing Plan

Unit Tests:

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

  • All unit tests pass locally.

  • test_multiturn_sends_task_id_when_input_required — verifies task_id is included in the second-turn request when task state is input-required

  • test_multiturn_sends_task_id_when_auth_required — same for auth-required

  • test_first_turn_omits_task_id — verifies task_id is None on the first turn

  • test_completed_task_omits_task_id — verifies task_id is not forwarded when previous task state is completed

Manual End-to-End (E2E) Tests:

  1. Set up a RemoteA2aAgent pointing at the currency agent from a2a-samples
  2. Launch adk web and send How much is 10 USD?
  3. Agent responds with Provide the currency to convert to and task.status=input-required
  4. Send CAD as the second turn
  5. Verify the outgoing A2A request contains both contextId and taskId matching the first turn's task
  6. Verify the remote agent returns the conversion result without creating a new 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.
  • Any dependent changes have been merged and published in downstream modules.

Additional context

The same root cause was previously reported in #3765. That issue proposed a fix but it was not fully applied — task_id was still never populated because the state check was missing.

@adk-bot adk-bot added the core [Component] This issue is related to the core interface and implementation label Mar 21, 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.

RemoteA2AAgent fails to send taskId in multi-turn scenarios

2 participants