fix: RemoteA2aAgent fails to send taskId in multi-turn scenarios#4944
fix: RemoteA2aAgent fails to send taskId in multi-turn scenarios#4944shriramThakare3 wants to merge 7 commits intogoogle:mainfrom
Conversation
|
Hi @shriramThakare3 , Thank you for your contribution! We appreciate you taking the time to submit this pull request. Can you please fix the failing unit tests , mypy-diff tests and formatting errors |
94 passed, 0 failed Files changed: 2 - src/google/adk/agents/remote_a2a_agent.py - tests/unittests/agents/test_remote_a2a_agent.py ``` **Changes:** - `_construct_message_parts_from_session` now reads task state from response metadata and forwards `task_id` when state is `input-required` or `auth-required` - Return type updated from 2-tuple to 3-tuple `(parts, context_id, task_id)` - `_run_async_impl` unpacks 3 values and passes `task_id` to `A2AMessage` - 9 test unpacking calls updated to 3-tuple - 6 mock return values updated from 2-tuple to 3-tuple
|
hello, @rohityan |
| response_meta = metadata.get(A2A_METADATA_PREFIX + "response", {}) | ||
| task_state = None | ||
| if isinstance(response_meta, dict): | ||
| status = response_meta.get("status", {}) | ||
| if isinstance(status, dict): | ||
| task_state = status.get("state") | ||
| if task_state in ("input-required", "auth-required"): | ||
| task_id = metadata.get(A2A_METADATA_PREFIX + "task_id") |
There was a problem hiding this comment.
The issue with this implementation is that it is not possible to define if the new user message is a follow up to the input-required event, or a request for a new task -> in this case the task_id should not be set
There was a problem hiding this comment.
The remote agent owns the task,it knows if the task_id is still valid or not. If the user starts a new request, the remote agent can handle it. Forwarding task_id on input-required is the right default behavior. If more control is needed, that can be a separate improvement.
Link to Issue or Description of Change
1. Link to an existing issue (if applicable):
Problem:
RemoteA2aAgentonly sendscontext_idon subsequent turns, nevertask_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 readingcontext_idfromcustom_metadata, also read the stored task state from the previous response metadata. Forwardtask_idonly when the task is still open (input-requiredorauth-required). For terminal states (completed,failed,cancelled)task_idstaysNoneso the server correctly starts a fresh task under the samecontext_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— verifiestask_idis included in the second-turn request when task state isinput-requiredtest_multiturn_sends_task_id_when_auth_required— same forauth-requiredtest_first_turn_omits_task_id— verifiestask_idisNoneon the first turntest_completed_task_omits_task_id— verifiestask_idis not forwarded when previous task state iscompletedManual End-to-End (E2E) Tests:
RemoteA2aAgentpointing at the currency agent froma2a-samplesadk weband sendHow much is 10 USD?Provide the currency to convert toandtask.status=input-requiredCADas the second turncontextIdandtaskIdmatching the first turn's taskChecklist
Additional context
The same root cause was previously reported in #3765. That issue proposed a fix but it was not fully applied —
task_idwas still never populated because the state check was missing.