Memory

The Memory service gives agents the ability to remember β€” across turns in a conversation (short-term via events) and across sessions and time (long-term via memory records with semantic search).


Core Concepts

LLMs are stateless by nature β€” each API call is independent. For an agent to maintain context across a conversation or across sessions, it needs an external memory store. AgentBase's Memory module provides this as a managed service with two memory layers:

Short-Term Memory (Conversation History)

Short-term memory stores the ordered sequence of messages in a conversation session. It is scoped to a session identifier.

Session 1: user 1
─────────────────────────────────────────────────────────
Role        Content
human       "What's the weather like in Hanoi today?"
assistant   "Currently 28Β°C, partly cloudy in Hanoi."
human       "What about tomorrow?"
assistant   "Tomorrow: 31Β°C, sunny with light winds."

Key characteristics:

  • Stored as an ordered list of role/content pairs

  • Indexed by session ID

  • Persists across container restarts (stored in the Memory Service, not in the container)

  • Supports configurable maximum history length

Long-Term Memory (Semantic Facts)

Long-term memory stores persistent facts about entities β€” users, products, preferences, past interactions β€” and retrieves them via semantic similarity search against the current query.

When an agent receives a new query, it:

  1. Searches long-term memory for the most similar facts to the current query

  2. Injects those facts into the prompt as context

Key characteristics:

  • Stored as embedding vectors plus raw text plus optional metadata

  • Scoped by namespace (for example, user ID, entity ID)

  • Retrieved via semantic similarity search

Facts are extracted from conversation events using a Long-Term Memory Strategy (LTMS). Three strategy types are supported:

Type
Description
Best For

SEMANTIC

Extracts general facts from conversations

Broad knowledge about users or domain

USER_PREFERENCE

Focused extraction of preferences and behavioral patterns

Delivery preferences, product interests, habits

CUSTOM

User-defined extraction logic via a custom prompt

Full control over what gets remembered and how

Data Model

Concept
Description
Lifetime

Memory

Top-level container (memory store) holding events and records

Permanent until deleted

Event

Single conversation turn (role + message)

Expires after eventExpiryDuration days

Actor

Participant identifier β€” represents the end-user (not the agent)

Created on first event

Session

Conversation thread within an actor

Created on first event

Memory Record

Distilled long-term fact extracted from events

Permanent until deleted

Long-Term Memory Strategy (LTMS)

Extraction rules for generating memory records

Configured at memory creation

Namespace Template

Controls how memory records are partitioned. Default: /strategies/{memoryStrategyId}/actors/{actorId}

Available variables: {memoryStrategyId}, {actorId}, {sessionId}

Note on actorId: Represents the end-user (e.g., alice, user-123), not the agent itself. This partitions facts per user.


Setup β€” Create Memory Store

Before using short-term or long-term memory, you must create a Memory store β€” the top-level container that holds all events and memory records for your agent.

Portal

Create a Memory Store

  1. Open https://aiplatform.console.vngcloud.vn/memory

  2. Click "Create Memory"

  3. Fill in:

    • Name: e.g., customer-support-memory (0–50 chars, ^[a-zA-Z0-9._-]*$)

    • Description: optional

  4. Configure Short-Term Memory:

    • Event Expiry Duration: number of days before conversation events are automatically deleted (1–365), e.g., 30 days

  5. Add one or more Long-Term Memory Strategies (optional, for long-term memory):

    • Strategy Name: e.g., semantic-facts

    • Type: SEMANTIC, USER_PREFERENCE, or CUSTOM

    • Namespace Template: default is /strategies/{memoryStrategyId}/actors/{actorId}

    • Auto-generate records: toggle on/off

    • Custom Prompt (only for CUSTOM type): your extraction prompt

  6. Click Create

List Memory Stores

  1. Open https://aiplatform.console.vngcloud.vn/memory

  2. All memory stores shown with: Name, Status, Descriptopn, Event Expiry, Lated updated

1774584561868

Get Memory Store Details

From the memory list page β†’ click a memory name

1774584650626

Delete a Memory Store

Warning: Deletion is irreversible. All events, actors, sessions, and memory records are permanently removed.

  1. From memory detailed page β†’ Delete β†’ confirm

1774584735238

RESTful API

Prerequisite: All API examples below use $TOKEN β€” an IAM bearer token. See Configure Authentication for how to obtain it.

Create a Memory Store

With SEMANTIC strategy:

With multiple strategies:

Example response:

List Memory Stores

Get Memory Store Details

Delete a Memory Store


SDK

Create a Memory Store

List Memory Stores

Get Memory Store Details

Delete a Memory Store


Step 2 β€” Use Memory in Your Agent

Once your Memory Store is created, your agent reads and writes memory at runtime. Choose the approach that fits your stack.

Approach
When to use

A: Agentic Frameworks

Building with LangGraph or LangChain β€” use built-in checkpointer for short-term + tools for long-term

B: Direct SDK / REST API

Any other stack, or when you need full control over when and how memory is read and written

Required headers: Your agent receives X-GreenNode-AgentBase-User-Id (maps to actor_id) and X-GreenNode-AgentBase-Session-Id (maps to thread_id / session_id) on every request from the Runtime. Always validate them before performing memory operations β€” never fall back to defaults, as silent defaults cause data mixing between users.


Approach A: Agentic Frameworks (LangGraph / LangChain)

Short-Term Memory β€” LangGraph Checkpointer

Pass AgentBaseMemoryEvents as the checkpointer when compiling your graph. LangGraph automatically writes and loads conversation history using the thread_id (mapped from session_id).

Long-Term Memory β€” Tool-Based Approach

Define remember and recall as agent tools backed by MemoryClient. The actor_id and strategy_id are resolved from runtime config β€” they must not be exposed as LLM-accessible parameters.

Pass actor_id via configurable so tools can retrieve it from get_config(). Never expose actor_id or strategy_id as LLM-accessible tool parameters.

Full Example: LangGraph Agent with Both Memory Types


Approach B: Direct SDK / REST API

Short-Term Memory

Write and read conversation events directly via the API at runtime. Each event represents one conversation turn.

Write an event (RESTful API):

Load conversation history (RESTful API):

Long-Term Memory

Long-term records are generated from conversation events, then retrieved via semantic search at runtime.

Generate records from a session (RESTful API):

Semantic search (RESTful API):

Example response:

Generate records from a session (SDK):

Semantic search (SDK):


Reference: Browse and Manage Memory Data

Use these operations to inspect memory data β€” useful for debugging, auditing, or building admin tooling.

List Actors

Browse Memory Records


Memory Service Limits

Parameter
Value
Notes

eventExpiryDuration range

1–365 days

Set at memory store creation

Memory name max length

50 chars

Pattern:^[a-zA-Z0-9._-]*$

Semantic search limit range

5–200

Per search request

Semantic search scoreThreshold

0–1 float

Higher = more strict similarity

Max from for event pagination

5000

Offset-based


Troubleshooting

Error
Cause
Fix

401 Unauthorized

Expired IAM token

Re-obtain token

Memory not found

Wrong memory ID

Verify with GET /memories list

No records returned

Namespace mismatch or async delay

Records generated asynchronously β€” wait and retry

Events not appearing

Events expired

Check eventExpiryDuration

Auto-generation not working

Strategy misconfigured

Verify enableAutomaticMemoryRecordGeneration: true

"Missing required headers"

Request missing User-Id or Session-Id

Include both headers in every request that uses memory


Last updated