Overview
TheBaseSessionService abstract class provides a set of methods for managing sessions and events. Implementations include in-memory storage, database persistence, and cloud-based solutions.
Available Implementations
- InMemorySessionService - Simple in-memory storage for development
- DatabaseSessionService - PostgreSQL/SQLite persistence with Drizzle ORM
- VertexAiSessionService - Google Vertex AI backed sessions
Methods
createSession
Creates a new session.The name of the app.
The id of the user.
The initial state of the session. Defaults to an empty object.
The client-provided id of the session. If not provided, a generated ID will be used.
The newly created session instance.
getSession
Gets a session with optional filtering of events.The name of the app.
The id of the user.
The id of the session.
Optional configuration for getting the session.
The session or undefined if not found.
listSessions
Lists all sessions for a user.The name of the app.
The id of the user.
The response containing the list of sessions.
deleteSession
Deletes a session permanently.The name of the app.
The id of the user.
The id of the session.
Resolves when the session is deleted.
endSession
Ends a session and returns its final state. This is typically called when a session is complete and should be stored in long-term memory before potential cleanup.The name of the app.
The id of the user.
The id of the session.
The session with its final state, or undefined if not found.
appendEvent
Appends an event to a session object and updates the session state based on the event’s state delta.The session to append the event to.
The event to append. If the event is marked as
partial, it will not be appended or update state.The appended event.
State Management
The session service automatically manages state updates through events:- When an event is appended with
actions.stateDelta, those state changes are applied to the session - Keys starting with
temp_are ignored and won’t be persisted - Setting a value to
nullorundefinedremoves that key from state
Usage with Agents
Related
- Session Interface - Session data structure
- MemoryService - Long-term memory from sessions
- SessionConfig - Configure sessions in agents