VertexAiSessionService: Fully-Managed Enterprise Session Storage
Run ADK conversations on Google Cloud's managed Agent Platform: what VertexAiSessionService requires, why app_name must be the Reasoning Engine resource, and how to work around its get_user_state gap.
Published on • December 3, 2026
AI Assistant

InMemorySessionService is a demo, and DatabaseSessionService means operating a database — schema migrations, backups, connection pooling, replicas. For teams already on Google Cloud, there is a third path: VertexAiSessionService, which stores conversations on Agent Platform infrastructure so session durability becomes someone else’s pager.
This tutorial covers the exact prerequisites, how app_name must be phrased for this service, the one API it refuses to implement (get_user_state) with a working alternative, and a side-by-side comparison that tells you when managed is the right call.
Prerequisites
- A Google Cloud project with billing and authentication configured (
gcloud auth application-default login). - The GCP extra:
pip install google-adk[gcp]. - A Google Cloud Storage bucket that the project can use.
- An Agent Runtime resource (Reasoning Engine) created on Agent Platform — its ID doubles as your
app_name. - A
Runneryou have already run against an in-memory service.
1. What the service actually is
VertexAiSessionService implements the same SessionService contract — create_session, get_session, list_sessions, delete_session, append_event — but every call becomes an API request against Agent Platform instead of a local dict or a SQL table.
InMemorySessionService | DatabaseSessionService | VertexAiSessionService | |
|---|---|---|---|
| Persistence | Lost on restart | Your database rows | Managed by Agent Platform |
| You operate | Nothing | DB server, backups, migrations | Nothing (GCP project only) |
| Requirements | None | google-adk[db] + async driver | GCP project, google-adk[gcp], Cloud Storage bucket, Agent Runtime |
app_name means | Arbitrary label | Arbitrary label | Reasoning Engine ID or full resource name |
get_user_state | Supported | Supported | Raises NotImplementedError |
| Best for | Prototyping | Self-managed relational storage | Scalable production on Google Cloud |
Supported in ADK Python, Go, Java, and Kotlin (in Kotlin the service is JVM-only, not Android).
2. Constructing the service and phrasing app_name
# Requires: pip install google-adk[gcp], plus GCP setup and authentication
from google.adk.sessions import VertexAiSessionService
PROJECT_ID = "your-gcp-project-id"
LOCATION = "us-central1"
# app_name must be the Reasoning Engine ID or its full resource name
REASONING_ENGINE_APP_NAME = (
"projects/your-gcp-project-id/locations/us-central1/reasoningEngines/1234567890"
)
session_service = VertexAiSessionService(project=PROJECT_ID, location=LOCATION)
session = await session_service.create_session(
app_name=REASONING_ENGINE_APP_NAME,
user_id="user-123",
state={"user:preferred_language": "fr"},
)
The gotcha that breaks most first integrations: app_name is not a free-form label for this service. It must be the Reasoning Engine ID or the full resource name projects/<p>/locations/<l>/reasoningEngines/<id>. Every call — create_session, get_session, list_sessions, delete_session, append_event — routes against that resource, so a typo’d label fails at the API rather than silently creating orphaned data.
Authentication and configuration otherwise follow the standard ADK-on-GCP path: gcloud auth application-default login, with GOOGLE_CLOUD_PROJECT and GOOGLE_CLOUD_LOCATION exported where your environment expects them.
3. The get_user_state gap — and the workaround
User-scoped state (user: keys) is a headline feature of ADK state, and Python offers a convenience reader for it:
# Works on InMemorySessionService and DatabaseSessionService:
state = await session_service.get_user_state(app_name=..., user_id=...)
VertexAiSessionService always raises NotImplementedError here, because the Agent Runtime API does not expose user state independently of a session. The documented alternative is to enumerate the user’s sessions and read state from each one — later sessions win, so the most recent value of each user: key survives:
from google.adk.sessions import VertexAiSessionService
async def get_user_state_from_sessions(
service: VertexAiSessionService, app_name: str, user_id: str
) -> dict:
"""Replacement for get_user_state() on VertexAiSessionService.
list_sessions returns sessions without events or state, so each
result must be re-fetched with get_session before it can be read.
"""
merged: dict = {}
page = await service.list_sessions(app_name=app_name, user_id=user_id)
for listed in page.sessions:
full = await service.get_session(
app_name=app_name, user_id=user_id, session_id=listed.id
)
if full is None:
continue
merged.update(
{k: v for k, v in full.state.items() if k.startswith("user:")}
)
return {key[len("user:"):]: value for key, value in merged.items()}
Two details to note: list_sessions returns Session objects without events or state attached, which is why the second get_session call is mandatory — and why this pattern costs one round trip per session. Cache the result if your user has a long session history.
4. Where it fits in an architecture
Choosing managed storage is an operational decision, not a technical one:
| Requirement | Verdict |
|---|---|
| ”We already run Postgres and have backups” | Use DatabaseSessionService |
| ”Nobody on the team wants to own a database” | Use VertexAiSessionService |
| ”Sessions must be readable with plain SQL for analytics” | Use DatabaseSessionService |
| ”We need horizontal scale without connection-pool tuning” | Use VertexAiSessionService |
| ”Local development and unit tests” | Use InMemorySessionService |
| ”We already use Agent Platform features (Memory Bank, runtimes)“ | Use VertexAiSessionService — the integrations align |
Because the SessionService interface is shared, the pragmatic pattern is to swap implementations by environment: in-memory locally, Vertex AI in production — the Runner never notices.
Checklist
-
pip install google-adk[gcp]is installed and GCP authentication is configured. - A Cloud Storage bucket exists and is usable by the project.
- An Agent Runtime (Reasoning Engine) resource has been created.
-
app_nameis the Reasoning Engine ID or the fullprojects/.../reasoningEngines/...resource name on every service call. - Nothing in the codebase calls
get_user_stateon this service — the enumerate-and-merge helper is used instead. - Callers of
list_sessionsre-fetch each session withget_sessionbefore reading events or state. - The
Runnershares oneVertexAiSessionServiceinstance per process. - Environment differences (in-memory vs Vertex AI) are a configuration choice, not a code branch.
Conclusion
VertexAiSessionService trades you out of the database business entirely: same SessionService API, managed durability on Agent Platform, and two sharp edges — the app_name resource-name rule and the missing get_user_state. Handle those two and you get production-grade session storage whose scaling, backup, and availability are the platform’s problem, while your agent code stays byte-for-byte identical to the version running locally on InMemorySessionService.