Skip to main content

Overview

Memory manages conversation history and context for agents in AgentScope. AgentScope provides two types of memory:
  • Short-term Memory: Stores conversation history for the current session, requires Session for persistence and recovery
  • Long-term Memory: Stores user preferences and knowledge across sessions, automatically persisted by external memory components (e.g., Mem0, ReMe)

Memory Architecture

In ReActAgent, short-term memory and long-term memory work together:
Division of Responsibilities:
  • Short-term Memory: Stores current session messages, provides context to LLM, supports reasoning loop
  • Long-term Memory (Independent Component):
    • Internally integrates LLM (memory extraction/summarization) and vector database (storage/retrieval)
    • Recall: At conversation start, recalls relevant memories and injects into short-term memory
    • Store: After user reply, asynchronously stores to long-term memory for extraction and persistence

Memory Interface

All short-term memory implementations extend the Memory interface:
Memory extends StateModule, supporting state serialization and deserialization, can be combined with SessionManager for persistence.

Short-term Memory

InMemoryMemory

The default short-term memory implementation, stores messages in memory. Characteristics:
  • Simple in-memory storage
  • No context management capability, messages grow indefinitely
  • Suitable for simple short conversations
Usage Example:

Short-term Memory Persistence

Short-term memory requires SessionManager for persistence to support session recovery after restart.
Complete Example: agentscope-examples/documentation/quickstart/src/main/java/io/agentscope/examples/quickstart/SessionExample.java

Long-term Memory

LongTermMemory Interface

Long-term memory is used to store and recall user preferences and knowledge across sessions:
Persistence Note: Long-term memory relies on external memory components (e.g., Mem0, ReMe services), data is automatically persisted to external storage, no manual management required. LongTermMemoryMode: Configure long-term memory working mode in ReActAgent:
  • STATIC_CONTROL: Static control mode, framework automatically recalls memories before reasoning and records after reply
  • AGENT_CONTROL: Agent control mode, lets Agent decide when to record and recall through tools
  • BOTH: Enable both modes simultaneously

Mem0LongTermMemory

Long-term memory implementation based on Mem0.

Background

The OpenAPI interfaces provided by self-hosted Mem0 and Platform Mem0 are inconsistent (different endpoint paths and response formats). Mem0LongTermMemory internally provides a compatibility adapter mechanism. By specifying the Mem0 deployment type through the apiType parameter, it automatically selects the correct API endpoints and response parsing methods.

Usage Examples

Platform Mem0 (default):
Self-hosted Mem0:
Configuration Notes:
  • apiType: Optional parameter to specify Mem0 deployment type
    • Mem0ApiType.PLATFORM (default): Uses Platform Mem0 API endpoints
    • Mem0ApiType.SELF_HOSTED: Uses self-hosted Mem0 API endpoints
  • apiBaseUrl: Base URL of the Mem0 service
    • Platform Mem0: Usually https://api.mem0.ai
    • Self-hosted Mem0: Usually http://localhost:8000 or your server address
  • apiKey: API key (optional)
    • Platform Mem0: Required
    • Self-hosted Mem0: Depends on your service configuration, may not be needed
Complete Example: agentscope-examples/documentation/advanced/src/main/java/io/agentscope/examples/advanced/Mem0Example.java Run Example:

ReMeLongTermMemory

Long-term memory implementation based on ReMe. Usage Example:
Complete Example: agentscope-examples/documentation/advanced/src/main/java/io/agentscope/examples/advanced/ReMeExample.java Run Example:

BailianLongTermMemory

Long-term memory implementation based on Bailian Memory Library. Usage Example:
Configuration Notes:
  • apiKey: Alibaba Cloud DashScope API key (required)
  • userId: User ID (required)
  • memoryLibraryId: Bailian memory library ID (optional)
  • projectId: Bailian project ID (optional)
  • profileSchema: Bailian configuration Schema ID (optional)
Complete Example: agentscope-examples/documentation/advanced/src/main/java/io/agentscope/examples/advanced/BailianMemoryExample.java Run Example: