Skip to content

A2A with agent engine session service in api_server runtime #3458

@guillaumeblaquiere

Description

@guillaumeblaquiere

Describe the bug
It's not possible to use agent-engine session service with A2A

To Reproduce
Run your ADK agent like this
adk api_server --a2a --host 0.0.0.0 --port 8080 --session_service_uri "agentengine://${AGENT_ENGINE_ID}" --memory_service_uri "agentengine://${AGENT_ENGINE_ID}"

You get this error when you use the A2A Endpoint (I use it with Agent Space (a.k.a Gemini Enterprise))

Traceback (most recent call last):
  File "/usr/local/lib/python3.12/site-packages/google/adk/a2a/executor/a2a_agent_executor.py", line 167, in execute
    await self._handle_request(context, event_queue)
  File "/usr/local/lib/python3.12/site-packages/google/adk/a2a/executor/a2a_agent_executor.py", line 208, in _handle_request
    session = await self._prepare_session(context, run_request, runner)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/google/adk/a2a/executor/a2a_agent_executor.py", line 303, in _prepare_session
    session = await runner.session_service.get_session(
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/google/adk/sessions/vertex_ai_session_service.py", line 162, in get_session
    get_session_response, events_iterator = await asyncio.gather(
                                            ^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/vertexai/_genai/sessions.py", line 882, in get
    response = await self._api_client.async_request(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/google/genai/_api_client.py", line 1365, in async_request
    result = await self._async_request(
             ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/google/genai/_api_client.py", line 1310, in _async_request
    return await self._async_retry(  # type: ignore[no-any-return]
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/tenacity/asyncio/__init__.py", line 111, in __call__
    do = await self.iter(retry_state=retry_state)
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/tenacity/asyncio/__init__.py", line 153, in iter
    result = await action(retry_state)
             ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/tenacity/_utils.py", line 99, in inner
    return call(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/tenacity/__init__.py", line 420, in exc_check
    raise retry_exc.reraise()
          ^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/tenacity/__init__.py", line 187, in reraise
    raise self.last_attempt.result()
          ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/concurrent/futures/_base.py", line 449, in result
    return self.__get_result()
           ^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/concurrent/futures/_base.py", line 401, in __get_result
    raise self._exception
  File "/usr/local/lib/python3.12/site-packages/tenacity/asyncio/__init__.py", line 114, in __call__
    result = await fn(*args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/google/genai/_api_client.py", line 1290, in _async_request_once
    await errors.APIError.raise_for_async_response(client_response)
  File "/usr/local/lib/python3.12/site-packages/google/genai/errors.py", line 166, in raise_for_async_response
    raise ClientError(status_code, response_json, response)
google.genai.errors.ClientError: 400 INVALID_ARGUMENT. {'error': {'code': 400, 'message': 'List of found errors:\t1.Field: name; Message: Invalid Session resource name.\t', 'status': 'INVALID_ARGUMENT', 'details': [{'@type': 'type.googleapis.com/google.rpc.BadRequest', 'fieldViolations': [{'field': 'name', 'description': 'Invalid Session resource name.'}]}]}}

If you start the agent without the session and memory service
adk api_server --a2a --host 0.0.0.0 --port 8080

You will use the InMemoryService and it works well

Expected behavior
I expect no error when I use AgentEngine memory service and A2A.

A2A invocation belonging to an external process/flow/session management, I would assume that the A2A request do not need persistent session service. So, having InMemory session service only for the A2A endpoint is fine in my opinion

Desktop (please complete the following information):

  • Python version(python -V): 3.12.11
  • ADK version(pip show google-adk): 1.18.0

Model Information:

  • Are you using LiteLLM: No
  • Which model is being used(e.g. gemini-2.5-pro): gemini-2.5-flash

Additional context
I would imagine solving the issue here

And I imagine a runner update like this.

      async def _get_a2a_runner_async() -> Runner:
          original_runner = await adk_web_server.get_runner_async(captured_app_name)
          runner = copy.copy(original_runner)  # Create a shallow copy
          runner.memory_service = InMemoryMemoryService()
          runner.session_service = InMemorySessionService()
          runner.artifact_service = InMemoryArtifactService()
          runner.credential_service = InMemoryCredentialService()
          return runner

        return _get_a2a_runner_async

What do you think?

Metadata

Metadata

Labels

a2a[Component] This issue is related a2a support inside ADK.needs review[Status] The PR/issue is awaiting review from the maintainer

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions