Repository navigation
Replies: 2 comments
|
Response from ADK Answering Agent (experimental, answer may be inaccurate) TLDR: Your current approach using Hi! That's a great question. It's good to see you're thinking about production-level concerns like session management. You can be confident in your current approach. Using To answer your specific questions:
Your method of passing a Hopefully, this confirms you're on the right track! References |
|
A concrete way to check the built-in service before adding custom tables is to give two users the same session ID, store different history, then close and reopen the database. This passed locally with Python 3.12.16, The lookup uses the composite app/user/session key. You can use the following as an isolation regression for your own pinned release: python -m pip install 'google-adk[db]==2.16.0' 'SQLAlchemy==2.1.10' 'aiosqlite==0.22.1' 'google-genai==3.7.0'
python test_isolation.pyThis tests SQLite persistence/API behavior; I have not run it against PostgreSQL or your WebSocket host. For the WebSocket boundary, derive import asyncio
import tempfile
from pathlib import Path
from google.adk.sessions import DatabaseSessionService
from google.adk.events import Event
from google.genai import types
async def main():
with tempfile.TemporaryDirectory() as folder:
url = 'sqlite+aiosqlite:///' + (Path(folder) / 'sessions.db').as_posix()
service = DatabaseSessionService(db_url=url)
for user in ('alice', 'bob'):
session = await service.create_session(app_name='demo', user_id=user,
session_id='same-name', state={'owner': user})
await service.append_event(session=session, event=Event(
invocation_id='run-' + user, author='user',
content=types.Content(role='user', parts=[types.Part(text='private-' + user)])))
await service.close()
service = DatabaseSessionService(db_url=url)
for user in ('alice', 'bob'):
session = await service.get_session(app_name='demo', user_id=user, session_id='same-name')
assert session.state['owner'] == user
assert [e.content.parts[0].text for e in session.events] == ['private-' + user]
listed = await service.list_sessions(app_name='demo', user_id=user)
assert [(s.user_id, s.id) for s in listed.sessions] == [(user, 'same-name')]
assert await service.get_session(app_name='demo', user_id='mallory', session_id='same-name') is None
assert await service.get_session(app_name='other', user_id='alice', session_id='same-name') is None
await service.delete_session(app_name='demo', user_id='alice', session_id='same-name')
assert await service.get_session(app_name='demo', user_id='alice', session_id='same-name') is None
assert await service.get_session(app_name='demo', user_id='bob', session_id='same-name') is not None
await service.close()
print('PASS: same session name / different users; exact histories; list scope; wrong user/app; reopen; scoped delete')
asyncio.run(main()) |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Hi!
I'm building a production assistant using ADK with PostgreSQL session persistence and I'd like to know how others are approaching session and user management.
Specifically:
Currently using DatabaseSessionService with a per-user session_id passed via WebSocket, but wondering if there's a more idiomatic pattern the community has converged on.
Thanks!
All reactions