Skip to main content
Short-term memory holds session-level context so an agent remembers what was said across turns. It is essentially the conversation context sent to the model — the system prompt plus the message history — keyed by 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

If a username or password in the connection string contains special characters such as @ or :, URL-encode it with urllib.parse.quote_plus first (e.g. p@ssword → p%40ssword), otherwise parsing fails.

Backend behavior

All backends provide the same session-management operations. They differ in persistence location and connection method:
  • local keeps sessions in the current process only;
  • sqlite writes sessions to a local file;
  • mysql and postgresql write sessions to an external database for multi-instance sharing.

Choosing a backend

Working with the Runner

Short-term memory is usually passed to the Runner, 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 a Session directly; instead you use session_service to manage the full lifecycle:
  • Start a session create_session(): create a new Session when the user starts interacting.
  • Resume a session get_session(): retrieve a Session by session_id to 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 a Session and its associated data.

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, the Runner compacts the history each time the interval is reached.

Custom compactor

Use LlmEventSummarizer 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):
Last modified on September 19, 2026