ADK Plugin: Session
Overview
Section titled “Overview”FlotorchADKSession
provides an ADK-compatible session service that uses FloTorch’s Session API for persistent session management while maintaining in-memory state for app and user state.
from flotorch.adk.sessions import FlotorchADKSession
API_KEY = "<your_api_key>"BASE_URL = "https://gateway.flotorch.cloud"
FlotorchADKSession
Section titled “FlotorchADKSession”FlotorchADKSession( api_key: str, base_url: str,)
Creates an ADK-compatible session service backed by FloTorch Session API.
create_session(…) -> Session
Section titled “create_session(…) -> Session”async def create_session( self, *, app_name: str, user_id: str, state: dict[str, Any] | None = None, session_id: str | None = None,) -> Session
Creates a new session with optional initial state.
get_session(…) -> Session | None
Section titled “get_session(…) -> Session | None”async def get_session( self, *, app_name: str, user_id: str, session_id: str, config: GetSessionConfig | None = None,) -> Session | None
Retrieves a session with optional event filtering.
list_sessions(…) -> ListSessionsResponse
Section titled “list_sessions(…) -> ListSessionsResponse”async def list_sessions( self, *, app_name: str, user_id: str) -> ListSessionsResponse
Lists sessions for a user/app combination.
delete_session(…) -> None
Section titled “delete_session(…) -> None”async def delete_session( self, *, app_name: str, user_id: str, session_id: str) -> None
Deletes a session.
append_event(…) -> Event
Section titled “append_event(…) -> Event”async def append_event(self, session: Session, event: Event) -> Event
Appends an event to a session with state delta handling.
Features
Section titled “Features”State Management
Section titled “State Management”- Session State: Stored in FloTorch Session
- App State: Kept in memory with
State.APP_PREFIX
keys - User State: Kept in memory with
State.USER_PREFIX
keys
Event Conversion
Section titled “Event Conversion”- ADK → FloTorch: Converts ADK events to FloTorch format for storage
- Flotorch → ADK: Converts stored events back to ADK format
- Tool Call Support: Handles tool calls and function responses
State Delta Handling
Section titled “State Delta Handling”Automatically processes state deltas in events to update app and user state.
Usage Example
Section titled “Usage Example”from google.adk.runner import Runner
# Create session servicesession_service = FlotorchADKSession( api_key=API_KEY, base_url=BASE_URL)
# Use with Runnerrunner = Runner( agent=agent, session_service=session_service)
# Sessions are automatically managed
- Session state is persisted in FloTorch, app/user state in memory
- Event conversion handles complex ADK content structures
- State deltas are processed automatically on event append
- Sync methods are deprecated, use async versions