Skip to content

Task id not respected while sending a2a send message request #3765

Closed

Description

@AneshkaGoyal

** Please make sure you read the contribution guide and file the issues in the right place. **
Contribution guide.

Describe the bug
When making call to a2a remote agent, the first send message request does not contain any context id or task id which is relevant. When the remote agent responds with a task that has task id and context id and task state as Input required, the subsequent send message request sends the context id but not the task id back even though it has it.

To Reproduce
Steps to reproduce the behavior:
the first send message request does not contain any context id or task id which is relevant. When the remote agent responds with a task that has task id and context id and task state as Input required, the subsequent send message request sends the context id but not the task id back even though it has it.

Expected behavior
A clear and concise description of what you expected to happen.
Expected behaviour is to have task id sent along with context id.

Proposed code changes are as below

def _construct_message_parts_from_session(
      self, ctx: InvocationContext
  ) -> tuple[list[A2APart], dict[str, Any], str]:
    """Construct A2A message parts from session events.

    Args:
      ctx: The invocation context

    Returns:
      List of A2A parts extracted from session events, context ID, task ID
    """
    message_parts: list[A2APart] = []
    context_id = None
    task_id = None
    for event in reversed(ctx.session.events):
      if _is_other_agent_reply(self.name, event):
        event = _present_other_agent_message(event)
      elif event.author == self.name:
        # stop on content generated by current a2a agent given it should already
        # be in remote session
        if event.custom_metadata:
          context_id = (
              event.custom_metadata.get(A2A_METADATA_PREFIX + "context_id")
              if event.custom_metadata
              else None
          )
          task_id = (
              event.custom_metadata.get(A2A_METADATA_PREFIX + "task_id")
              if event.custom_metadata
              else None
          )
        break

      if not event.content or not event.content.parts:
        continue

      for part in event.content.parts:

        converted_part = self._genai_part_converter(part)
        if converted_part:
          message_parts.append(converted_part)
        else:
          logger.warning("Failed to convert part to A2A format: %s", part)

    return message_parts[::-1], context_id, task_id
async def _run_async_impl(
      self, ctx: InvocationContext
  ) -> AsyncGenerator[Event, None]:
    """Core implementation for async agent execution."""
    try:
      await self._ensure_resolved()
    except Exception as e:
      yield Event(
          author=self.name,
          error_message=f"Failed to initialize remote A2A agent: {e}",
          invocation_id=ctx.invocation_id,
          branch=ctx.branch,
      )
      return

    # Create A2A request for function response or regular message
    a2a_request = self._create_a2a_request_for_user_function_response(ctx)
    if not a2a_request:
      message_parts, context_id, task_id = self._construct_message_parts_from_session(
          ctx
      )

      if not message_parts:
        logger.warning(
            "No parts to send to remote A2A agent. Emitting empty event."
        )
        yield Event(
            author=self.name,
            content=genai_types.Content(),
            invocation_id=ctx.invocation_id,
            branch=ctx.branch,
        )
        return

      a2a_request = A2AMessage(
          message_id=str(uuid.uuid4()),
          parts=message_parts,
          role="user",
          context_id=context_id,
          task_id=task_id,
      )

    logger.debug(build_a2a_request_log(a2a_request))

    try:
      async for a2a_response in self._a2a_client.send_message(
          request=a2a_request
      ):
        logger.debug(build_a2a_response_log(a2a_response))

        event = await self._handle_a2a_response(a2a_response, ctx)

        # Add metadata about the request and response
        event.custom_metadata = event.custom_metadata or {}
        event.custom_metadata[A2A_METADATA_PREFIX + "request"] = (
            a2a_request.model_dump(exclude_none=True, by_alias=True)
        )
        # If the response is a ClientEvent, record the task state, otherwise
        # record the message object.
        if isinstance(a2a_response, tuple):
          event.custom_metadata[A2A_METADATA_PREFIX + "response"] = (
              a2a_response[0].model_dump(exclude_none=True, by_alias=True)
          )
        else:
          event.custom_metadata[A2A_METADATA_PREFIX + "response"] = (
              a2a_response.model_dump(exclude_none=True, by_alias=True)
          )

        yield event

Screenshots

Desktop (please complete the following information):

  • OS: [e.g. macOS, Linux, Windows]
  • Python version(python -V):
  • ADK version(pip show google-adk):

Model Information:
Happening with all models

Additional context
NA

Activity

  1. self-assigned this
    on Dec 1, 2025
  2. added
    a2a
    on Dec 2, 2025
  3. added theissue type on Dec 2, 2025
  4. added a commit that references this issue on Dec 4, 2025
    82bd4f3
  5. reopened this on Dec 4, 2025
  6. AneshkaGoyal commented on Dec 20, 2025

    @AneshkaGoyal
    Author

    I can see the changes made to close this are not in line with what I recommended and hence does not fix the issue while 1.21.0 marks it as a bug fix @GWeale could you please help me understand.

  7. llalitkumarrr commented on Feb 3, 2026

    @llalitkumarrr
    Collaborator

    Hello @AneshkaGoyal ,

    Apologies for the delayed response, we recommend trying our latest version i.e. google-adk==1.23.0. If this issue is not fixed in this version, kindly share your observations and some reproduction steps along with minimal reproducible code to help us reproduce this and assist you better.

  8. added
    answered
    on Feb 3, 2026
  9. adk-bot commented on Feb 10, 2026

    @adk-bot
    Collaborator

    This issue has been automatically marked as stale because it has not had recent activity for 7 days after a maintainer requested clarification. It will be closed if no further activity occurs within 7 days.

  10. added
    stale
    request clarification
    on Feb 10, 2026
  11. AneshkaGoyal commented on Feb 15, 2026

    @AneshkaGoyal
    Author

    This issue has been automatically marked as stale because it has not had recent activity for 7 days after a maintainer requested clarification. It will be closed if no further activity occurs within 7 days.

    Hello @AneshkaGoyal ,

    Apologies for the delayed response, we recommend trying our latest version i.e. google-adk==1.23.0. If this issue is not fixed in this version, kindly share your observations and some reproduction steps along with minimal reproducible code to help us reproduce this and assist you better.

    @llalitkumarrr I tired latest version but still only context id is passed for an A2A request, please check the correct fix is not implemented - The same repro steps as mentioned above
    I had reported this issue and a fix was pushed but thats not the correct fix.

    1. Make a request to an agent with insufficient information such that agent responds with a task id in input required state
    2. Send more information - You will see the agent (remote) only gets called with context id since task id sent by the agent was never retrieved and stored along with context id.
      I have supplied the correct fix in the issue above.

    This fix is not upto the mark - 82bd4f3

  12. removed
    stale
    on Feb 16, 2026
  13. removed
    answered
    request clarification
    on Feb 24, 2026
  14. llalitkumarrr commented on Feb 24, 2026

    @llalitkumarrr
    Collaborator

    Hello @AneshkaGoyal ,

    Could you please share minimal reproducible code to help us reproduce this to get to the bottom of this issue?

  15. AneshkaGoyal commented on Mar 1, 2026

    @AneshkaGoyal
    Author

    Hello @AneshkaGoyal ,

    Could you please share minimal reproducible code to help us reproduce this to get to the bottom of this issue?

    Sure, Just make a call to any A2A compliant Agent from google adk(remote agent), the remote agent sends input required as task state, returns task identifier and asks for additional information, when google ADK sends the reply to the remote agent - It just respects the context id and does not send the task id with the message sent

    Please return this from remote agent for a Task thats being processed.

    ` // Create Input required status
    TaskStatus completedStatus = new TaskStatus(
    SELECT == agentResponse.getCurrentStep()
    ? TaskState.COMPLETED
    : TaskState.INPUT_REQUIRED,
    null, // No status message currently
    OffsetDateTime.now()
    );
    List<Part<?>> parts = ResponseBuilderUtils.buildResponseParts(agentResponse, finalResponseList);
    Artifact responseArtifact = new Artifact.Builder()
    .artifactId(UUID.randomUUID().toString())
    .name("artifact-" + taskId)
    .parts(parts)
    .build();

            return new Task.Builder()
                    .id(taskId)
                    .contextId(initialTask.getContextId())
                    .status(completedStatus)
                    .artifacts(List.of(responseArtifact))
                    .history(initialTask.getHistory())
                    .metadata(metadata)
                    .build();`
    
  16. sasha-gitg commented on Mar 2, 2026

    @sasha-gitg
    Collaborator

    Resolved by 82bd4f38

  17. added 2 commits that reference this issue on Aug 11, 2026
    eca75e0
    4a474e5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

a2a

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions