session_id: reuse the same session_id and the agent remembers earlier turns.
When a user starts a conversation, VeADK automatically creates a Session object and tracks everything in that conversation.
Short-term memory builds on Google ADK’s Session mechanism. For background, see Google ADK Session.
Single entry point: ShortTermMemory
Whatever backend you use, you interact with one class —veadk.memory.short_term_memory.ShortTermMemory. It selects the storage mode based on backend (or db_url) and exposes a uniform session-management surface.
Parameters
Backend behavior
All backends provide the same session-management operations. They differ in persistence location and connection method:localkeeps sessions in the current process only;sqlitewrites sessions to a local file;mysqlandpostgresqlwrite sessions to an external database for multi-instance sharing.
Choosing a backend
Working with the Runner
Short-term memory is usually passed to theRunner, which then creates or restores sessions automatically. Reuse the same session_id at run time to continue the context.
If you pass neither
short_term_memory nor session_service to the Runner, it falls back to creating a local (in-memory) short-term memory automatically.Session management interface
You rarely create or manage aSession directly; instead you use session_service to manage the full lifecycle:
- Start a session
create_session(): create a newSessionwhen the user starts interacting. - Resume a session
get_session(): retrieve aSessionbysession_idto continue. - Save progress
append_event(): append a new interaction (Event) to the history. - List sessions
list_sessions(): query active sessions for a user and app. - Clean up
delete_session(): delete aSessionand its associated data.
after_create_session_callback:
async def). If it raises an exception,
the exception is propagated to the caller and agent execution does not continue.
Under a database backend,
ShortTermMemory.create_session() first checks for
and reuses an existing session with the same session_id to avoid duplicates.
The callback only runs on first creation.Context compaction
As a conversation grows, the history keeps expanding, increasing what the model must process and slowing responses. Context compaction summarizes the history with a sliding window: when the history exceeds a threshold, older events are compacted automatically.Configure compaction
Once configured, theRunner compacts the history each time the interval is reached.
Custom compactor
UseLlmEventSummarizer to set the model and prompt template for compaction. Provide the model’s API key and base via environment variables (read from os.environ, never hard-code):