Skip to content

list_session of VertexAiSessionService doesn't return user_id in the ListSessionsResponse #3154

@simo-cava

Description

@simo-cava

Describe the bug
The list_sessions method within the VertexAiSessionService class does not correctly extract the user_id from the API response. Consequently, it is currently impossible to retrieve the end user's ID for each session when listing sessions for a specific application.

To Reproduce

import logging

from google.adk.sessions import VertexAiSessionService
from google.adk.sessions.base_session_service import ListSessionsResponse
from google.adk.sessions import Session

from typing import Optional

async def list_sessions(
    project_id: str,
    location: str,
    app_name: str,
    agent_engine_id: str,
    user_id: str = ""
) -> Optional[list[Session]]:
    session_service = VertexAiSessionService(
        project=project_id, location=location
    )

    try:
        # List sessions
        response: ListSessionsResponse = await session_service.list_sessions(
            app_name=app_name, user_id=user_id
        )

        logger.info("Sessions for agent engine %s", {agent_engine_id})

        for session in response.sessions:
            logger.info(f"  - {session.id} - {session.app_name} - {session.user_id}  ")
        return response.sessions

    except Exception as e:
        logger.error("Error listing sessions: %s", e)
        raise

Actual behavior
Output:
2025-10-13 12:50:52,105 - sessions - INFO - - Session_id: 1794064845704890880 - App Name: projects/pippo/locations/europe-west1/reasoningEngines/6628419555187149312 - User_id: 2025-10-13 12:50:52,105 - sessions - INFO - - Session_id: 6459799090660724736 - App Name: projects/pippo/locations/europe-west1/reasoningEngines/6628419555187149312 - User_id:

Expected behavior
Output:
2025-10-13 12:50:52,105 - sessions - INFO - - Session_id: 1794064845704890880 - App Name: projects/pippo/locations/europe-west1/reasoningEngines/6628419555187149312 - User_id: f117daa8-60e3-4e1a-aef1-7d2b8d8638c3 2025-10-13 12:50:52,105 - sessions - INFO - - Session_id: 6459799090660724736 - App Name: projects/pippo/locations/europe-west1/reasoningEngines/6628419555187149312 - User_id: 123

The list_sessions method of the VertexAiSessionService should:

  • Return all sessions if the user_id is not provided as an input parameter (current behavior).
  • Crucially, it must include the extracted user_id field within the session object for every session returned in the response.

Metadata

Metadata

Assignees

Labels

services[Component] This issue is related to runtime services, e.g. sessions, memory, artifacts, etc

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions