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:- 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 theMemory 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
Short-term Memory Persistence
Short-term memory requiresSessionManager for persistence to support session recovery after restart.
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:STATIC_CONTROL: Static control mode, framework automatically recalls memories before reasoning and records after replyAGENT_CONTROL: Agent control mode, lets Agent decide when to record and recall through toolsBOTH: 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):apiType: Optional parameter to specify Mem0 deployment typeMem0ApiType.PLATFORM(default): Uses Platform Mem0 API endpointsMem0ApiType.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:8000or your server address
- Platform Mem0: Usually
apiKey: API key (optional)- Platform Mem0: Required
- Self-hosted Mem0: Depends on your service configuration, may not be needed
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: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: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)
agentscope-examples/documentation/advanced/src/main/java/io/agentscope/examples/advanced/BailianMemoryExample.java
Run Example: