Skip to main content
Long-term memory persists important information across sessions and over time — user preferences, task history, key facts, or long-lived state. Short-term memory only lives within a single session; long-term memory lets an agent remember facts across different sessions. Why you need it:
  • Continuous conversation experience across sessions;
  • Retain learnings and user-specific information over many interactions;
  • Avoid repetitive questions, improving satisfaction and efficiency;
  • Support long-term strategy optimization such as personalization or task tracking.

Single entry point: LongTermMemory

Whatever backend you use, you interact with veadk.memory.long_term_memory.LongTermMemory. It plugs directly into an agent as its memory service and selects the storage backend through backend.

Parameters

Vector backends (local, opensearch, redis) embed memories, which requires pip install "veadk-python[extensions]" and an embedding model (env prefix MODEL_EMBEDDING_, falling back to MODEL_AGENT_API_KEY). viking, mem0, and openviking manage memory on the service side and need no local embedding.

Choosing a backend

Use local for debugging. In production, choose viking, mem0, or openviking according to the service you operate.

Binding to an Agent

Passing long_term_memory to an Agent auto-injects the load_memory tool so the agent can retrieve past sessions at run time.

Managing memory

Write: add_session_to_memory

When a session ends or hits a checkpoint, call the async add_session_to_memory to persist it. Most backends keep only user text events to improve retrieval quality. The openviking backend keeps text from both the user and the agent so OpenViking can form memory from the complete conversation.

Retrieve: search_memory

Besides the agent’s automatic retrieval via load_memory, you can call the async search_memory directly for semantic search — useful for debugging or custom RAG:
get_user_profile(user_id) is supported only by the viking backend; others return an empty string.

Auto-save sessions

Set auto_save_session=True on the Agent with long-term memory configured, and VeADK persists sessions automatically — no manual add_session_to_memory.
To avoid frequent index re-initialization, VeADK exposes MIN_MESSAGES_THRESHOLD and MIN_TIME_THRESHOLD env vars to tune the save cadence: by default it saves after 10 accumulated events or a 60-second interval; additionally, when you switch session_id and start a new turn, VeADK saves the previous session to long-term memory.

Cross-session example

An end-to-end flow: session #1 tells the agent a fact and auto-archives it, then a brand-new session #2 asks a question — and the agent recalls the fact via memory retrieval (not the context window). This uses the local backend, which needs pip install "veadk-python[extensions]".
In session #2 the agent recognizes the same user’s preferences left in session #1 and answers coherently and personally (e.g. a peanut-free vegetarian dish).
Last modified on September 19, 2026