8000 Add `session_db_kwargs` to FastAPI App · Issue #1287 · google/adk-python · GitHub
[go: up one dir, main page]

Skip to content
Add session_db_kwargs to FastAPI App #1287
Open
@jackwotherspoon

Description

@jackwotherspoon

The get_fast_api_app function supports a session_db_url argument that allows constructing the session service with a DatabaseSessionService.

def get_fast_api_app(
*,
agents_dir: str,
session_db_url: str = "",
artifact_storage_uri: Optional[str] = None,
allow_origins: Optional[list[str]] = None,
web: bool,
trace_to_cloud: bool = False,
lifespan: Optional[Lifespan[FastAPI]] = None,
) -> FastAPI:

session_service = DatabaseSessionService(db_url=session_db_url)

However, it does not support passing additional DB kwargs required for full control or advanced use cases that production resources require. DB kwargs are where users can configure their connection pool settings like pool size, timeouts, etc.

The DatabaseSessionService supports database engine kwargs and these should be configurable using the the FastAPI app.

class DatabaseSessionService(BaseSessionService):
"""A session service that uses a database for storage."""
def __init__(self, db_url: str, **kwargs: Any):
"""Initializes the database session service with a database URL."""
# 1. Create DB engine for db connection
# 2. Create all tables based on schema
# 3. Initialize all properties
try:
db_engine = create_engine(db_url, **kwargs)

This is critical for creating DatabaseSessionServices's with Cloud SQL and AlloyDB as the recommended best practice is to use an AlloyDB Python Connector which thousands of customers use today.

The Python Connectors for Cloud SQL and AlloyDB require the creator SQLAlchemy kwarg to work. They can not be used with ADK via the FastAPI app until this is fixed.

< 4D3C /div>

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

    0