Skip to content

DatabaseSessionService() doesn't store data to db #1587

Closed
@eibednejo

Description

@eibednejo

** Please make sure you read the contribution guide and file the issues in the right place. **
Contribution guide.

Describe the bug
Hello, has anyone successfully created a session with persistent storage using DatabaseSessionService by an API call?

Image

I tried this, successfully called it, and it returned with the session ID. But, I couldn't find it in the db (sqlite).
To Reproduce
Steps to reproduce the behavior:

from google.adk.agents import Agent
from google.adk.tools import google_search
import os
from dotenv import load_dotenv
from google.adk.sessions import DatabaseSessionService
from google.adk.runners import Runner

load_dotenv()
APP_NAME = "Search Agent"
root_agent = Agent(
    name="search_assistant",
    model="gemini-2.5-flash",
    instruction="""
        You are a helpful assistant. Answer user questions using Google Search when needed.
    """,
    description="An assistant that can search the web.",
    tools=[google_search]
)

# dbname=os.environ["DB_NAME"]
# user=os.environ["DB_USER"]
# password=os.environ["DB_PASSWORD"]
# host=os.environ["DB_HOST"]
# port=os.environ["DB_PORT"]
# db_url = f"postgresql+psycopg://{user}:{password}@{host}:{port}/{dbname}"
db_url_sqlite = "sqlite:///./test_session.db"
session_service = DatabaseSessionService(db_url=db_url_sqlite)
print(f"INFO: DatabaseSessionService configured to use: {db_url_sqlite}")

# runner = Runner(agent=root_agent, app_name=APP_NAME, session_service=session_service)

I ran adk api_server, then I executed

curl -X POST "http://127.0.0.1:8000/apps/search/users/user123/sessions" \
-H "Content-Type: application/json" \
-d '{
  "initial_state": {}
}

This is the response
{"id":"89e4bbbd-20b7-4d5d-8f6e-5bbd00128c38","appName":"search","userId":"user123","state":{},"events":[],"lastUpdateTime":1750670261.2048588}
Image

Then, I tried to call /run_sse and it was just fine.
I noticed that the test_session.db was created not when creating a session, but when running /run_sse instead. But still no data inside.

Did I miss something?
Thanks!

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions