Repository navigation
Description
Hi folks,
I'm new to ADK and am trying to replicate the BIDI demos using SQLite for persistence.
Specifically, I'm working with the sample at:
https://github.com/google/adk-samples/tree/main/python/agents/bidi-demo
To test persistence, I configured SQLite and temporarily hard-coded the user_id and session_id inside the WebSocket endpoint:
from google.adk.sessions import DatabaseSessionService
db_url = "sqlite:///./adk_sessions.db"
session_service = DatabaseSessionService(db_url=db_url)
@app.websocket("/ws/{user_id}/{session_id}")
async def websocket_endpoint(websocket: WebSocket, user_id: str, session_id: str) -> None:
"""WebSocket endpoint for bidirectional streaming with ADK."""
user_id = "user_123"
session_id = "session_123"
logger.debug(f"WebSocket connection request: user_id={user_id}, session_id={session_id}")
await websocket.accept()
logger.debug("WebSocket connection accepted")
# rest of the code...My expectation is that if I reconnect to the WebSocket (with the same hardcoded user and session IDs), the session should be restored and previous conversation context should be loaded automatically.
However, this does not seem to be happening—each reconnection starts a completely fresh conversation, even though I see rows written to the events table in the SQLite DB.
So I'm unsure whether the session is being saved correctly, or whether it is being loaded but not applied.
Could you clarify:
- Does the BIDI demo automatically restore conversation state when a session ID is reused?
- Is any additional configuration required for
DatabaseSessionServicewhen using SQLite? - Which tables/columns should I inspect to verify that session and conversation state are actually being persisted?
Any guidance would be greatly appreciated!
Activity
quantexperts commentedon Nov 17, 2025
I started with a completely clean SQLite DB, launched the server, and opened a WebSocket connection using a fixed
user_idandsession_id.Then I tested persistence with this sequence:
I said: “My favourite color is Blue.”
The agent correctly responded:
→ “Blue is a great choice!…”
I then restarted the server (without deleting the database).
On reconnect, the server logs show:
So the events are being stored and loaded successfully.
I then asked: “What is my favourite color?”
But the agent replied:
→ “I don’t know your favorite color. Can you tell me what it is?”
So even though the stored events were loaded from SQLite, the agent is not able to recall anything from earlier in the conversation.
I suspect I may be misunderstanding how conversational memory is supposed to work in ADK. My assumption was:
DatabaseSessionServicerestores the previous session’s events,LlmAgent.include_contentsdefaults to"default",Is there an additional step required for the agent to use restored session state as prompt context?
I tried the same approach with a normal setup (without BIDI) and it works fine. So I am confused why in case of BIDI, it is not working in the same way.
Any guidance on what I’m missing would be greatly appreciated — especially since the session is loading correctly but the agent still behaves as if it’s a fresh conversation.
DeanChensj commentedon Nov 19, 2025
Hi @quantexperts , does your sqlite session persist when you test with non-bidi agents?
surajksharma07 commentedon Nov 19, 2025
@quantexperts events are loading but the conversation history isn't being reconstructed in BIDI mode.
In your WebSocket endpoint, after calling
get_session()andget_events(), you need to explicitly build the conversation history by iterating through the events and extracting the Content objects (filtering for "user" and "model" roles), then combine this history with new messages before passing to the agent.This reconstruction happens automatically in non-BIDI mode but needs to be done explicitly in BIDI WebSocket handlers.
Thanks!
quantexperts commentedon Nov 19, 2025
@surajksharma07 Thanks for your suggestions.
I am having trouble understanding how the data is saved in the database in case of BIDI.
When I inspect the event object, I see the output like this and I cant figure out how to extract the user and agent text. This works in non BIDI mode.
In the logs, the
output_transcriptionfields are empty.The screenshot from the database event table:
surajksharma07 commentedon Nov 20, 2025
I see the issue - you're using
getattr(session, 'events', [])which doesn't properly load events.Change it to
events = await session.get_events()instead.Then filter for content:
conversation_history = [event.content for event in events if event.content and event.content.role in ("user", "model")].If content is still None after this fix, that indicates a BIDI-specific persistence bug where content isn't being saved to events - in that case, please share your full WebSocket handler code so we can investigate further.
quantexperts commentedon Nov 20, 2025
It says
session.get_events()is an invalid method. I couldn't figure out what is the right method8 remaining items
fix(cli): replay existing session events on BIDI reconnection (google…
fix(cli): replay session events on BIDI reconnection (google#3573, go…
fix(cli): prevent duplicate responses in Live mode sessions (google#3395
surajksharma07 commentedon Feb 6, 2026
@quantexperts This is a confirmed BIDI-specific persistence bug — user messages aren't being saved into session events in Live/BIDI mode, so there's nothing to replay on reconnection.
ADK v1.24.0 added history replay infrastructure (
contents.pytranscription-to-content conversion,send_history()inrun_live()), but the root issue remains: user input events are stored withcontent=Noneand no transcription data.PR #4194 is linked to address this but hasn't been merged yet.
This issue remains open and we're tracking it.
surajksharma07 commentedon May 6, 2026
@quantexperts Traced through the thread — the content=None behaviour in BIDI/Live mode was addressed in v1.23.0 (commit a04828d: "Persist user input content to session in live mode"), with session replay on reconnect completed in v1.24.0 and further refined in v1.32.0.
Worth upgrading to v1.23.0+ (ideally v1.32.0) and switching from DatabaseSessionService to SqliteSessionService for SQLite — the dedicated class was introduced in v1.19.0 specifically for this backend:
session_service = SqliteSessionService(db_path="./adk_sessions.db")Could you test on the latest version and confirm whether session history is being restored correctly on reconnect?
If it's working, happy to close this out!
surajksharma07 commentedon May 19, 2026
Going ahead and closing this out since we haven't heard back in a couple of weeks — assuming the v1.23.0 upgrade + SqliteSessionService sorted the session persistence issue for you!
Just to confirm for anyone landing here: the content=None bug for BIDI/live mode user messages was fixed in v1.23.0 (commit a04828d), and SqliteSessionService is available from that version onward as the right persistence layer for live sessions.
Feel free to reopen if the upgrade didn't fully cover your case or you're seeing something different on v1.23.0+ — happy to dig in further!