Skip to content

DatabaseSessionService class: set a more explicit way to decide the schema #2217

Closed

Description

@Istorn

The class DatabaseSessionService permits to set up the connection to the DB via DB URL and add different flags via kwargs.

From my perspective it would be great to permit the user setting the schema as explicit parameter.

  • Reason: DB schema is one of the core elements when it comes to interact with the DB itself
  • Use case: PostgreSQL database, but it could be related to any other relational DB kind of
  • Proposal:

As is:

session_service = DatabaseSessionService(db_url, connect_args={"options": "-c search_path=NAME_OF_MY_SCHEMA"})

To Be:

session_service = DatabaseSessionService(db_url, schema="NAME_OF_MYSCHEMA")

Activity

  1. added
    services[Component] This issue is related to runtime services, e.g. sessions, memory, artifacts, etc
    on Jul 28, 2025
  2. added theissue type on Jul 28, 2025
  3. dylan-apex commented on Jul 28, 2025

    @dylan-apex
    Contributor

    Duplicate/Related to #2115

  4. jeffreyrubi commented on Jul 31, 2025

    @jeffreyrubi
    Contributor

    hi @Istorn , i'm interested to work on this feature. Left some of the thought and would like to see if this can support your case:

    2 changes to be made for it:

    Change 1: Add optional arg "engine" to init() of the DatabaseSessionService.
    Benefits: Scalable to many agents system because different sessions (of different agent) can share the same connection pool to the same SQL engine. The response time will also be much faster when db connections are reused.

    Change 2:For every session manipulation method, keep it within a context which: (a) create the schema if it does not exist. (b) utilize the schema translate map to make operation under the give schema.
    Benefits: Ensure the designated schema is effective in every operation to allow recycling of db connections.

    This enhancement is very critical to enable the SessionService to support different enterprise cases where agents need to work on separate schemas with proper data isolation. Let me know if it sounds fine. I could submit a PR accordingly.

  5. Istorn commented on Jul 31, 2025

    @Istorn
    Author

    Hi @jeffreyrubi wanna join the forces together?

    I understand your concerns, what if we keep a default option in case of none custom ones are being provided?

  6. jeffreyrubi commented on Jul 31, 2025

    @jeffreyrubi
    Contributor

    Sure. Happy to join force.

    For default option, that's what i mean the engine should be optional. Backward compatibility is important. I'm expecting the change will not impact any current implementation.

  7. dylan-apex commented on Jul 31, 2025

    @dylan-apex
    Contributor

    While working on this, can you update the adk.cli.fast_api.get_fast_api_app() to also accept a database engine?

  8. added this to the 10/27 ADK Week milestone on Oct 28, 2025
  9. klateefa commented on Nov 21, 2025

    @klateefa

    @Istorn Thanks for reporting!
    We are currently reviewing your feature request,Its under review
    Thanks for your patience.

  10. added
    needs review[Status] The PR/issue is awaiting review from the maintainer
    on Nov 21, 2025
  11. DeanChensj commented on Nov 27, 2025

    @DeanChensj
    Collaborator

    Hi @Istorn , thanks for reporting this, we started to record the schema version in 0094eea and also provided a cli command adk migration session for future migrations.

  12. removed
    needs review[Status] The PR/issue is awaiting review from the maintainer
    on Nov 27, 2025
  13. jeffreyrubi commented on Dec 10, 2025

    @jeffreyrubi
    Contributor

    I'm seeing this issue get closed. are we planning to do this or decide not to go ahead?

  14. dylan-apex commented on Dec 10, 2025

    @dylan-apex
    Contributor

    You can add db args when creating the DB Session

    db_args = {"connect_args": {"options": "-csearch_path=sessions"}}
    
    app = get_fast_api_app(
        agents_dir=AGENT_DIR,
        session_service_uri=agent_engine_session,
        session_db_kwargs=db_args,
        web=SERVE_WEB_INTERFACE
    )
  15. divakaivan commented on Sep 21, 2026

    @divakaivan

    if you're using postgresql+asyncpg, this seems to be a solution

    session_service = DatabaseSessionService(
        db_url="postgresql+asyncpg://adk:adk@localhost:5432/adk",
        connect_args={
            "server_settings": {
                "search_path": "other_schame_name",
            }
        },
    )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

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

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions