- storing messages, and
- managing messages with marks across different storage implementations.
ReActAgent, hint messages are typically stored with mark hint, and memory-aware workflows (such as compression pipelines) can be organized around marks.
The memory module focuses on storage and management. Algorithmic logic (for example, compression strategy) is implemented at the agent layer.
For conceptual background, see Context and Memory.In AgentScope, memory can be viewed in two layers:
- Short-term memory (
MemoryBaseimplementations) for current conversation/session state - Long-term memory (
LongTermMemoryBaseimplementations) for cross-session persistence and retrieval
Short-Term Memory
Short-term memory storesMsg objects and supports optional marks (for example: hint, summary, tool_result) for filtering and lifecycle management.
Built-in short-term memory implementations:
Common API
All short-term memory classes inherit fromMemoryBase and expose a unified async API:
InMemoryMemory: Basic Usage
InMemoryMemory is the easiest option for quick testing and local prototyping.
AsyncSQLAlchemyMemory: Basic Usage
AsyncSQLAlchemyMemory works with either an async engine or an async session.
AsyncSQLAlchemyMemory as Context Manager
When used as an async context manager, session cleanup is handled automatically.SQLAlchemy Memory with FastAPI Pooling
In production, create and reuse an async engine/session maker with pooling:RedisMemory: Basic Usage
RedisMemory is suitable for distributed services and horizontally scaled workers.
Redis Memory with FastAPI Pooling
Use a global Redis connection pool and createRedisMemory per request:
Customizing Short-Term Memory
To build a custom short-term memory backend, inherit fromMemoryBase and implement the required methods:
Long-Term Memory
AgentScope provides long-term memory abstractions for cross-session persistence and retrieval.Long-Term Memory Modes in ReActAgent
ReActAgent supports three long-term memory modes:
When mode is
agent_control or both, tool functions such as record_to_memory and retrieve_from_memory are registered in the toolkit.
Mem0LongTermMemory: Basic Usage
ReMePersonalLongTermMemory: Usage Patterns
ReMePersonalLongTermMemory supports both tool-style APIs and direct APIs:
Integrating Long-Term Memory with ReActAgent
Customizing Long-Term Memory
To implement your own long-term memory backend, inherit fromLongTermMemoryBase and implement methods according to your target mode:
If your backend supports all methods, it can be used in
both mode.
Further Reading
Agent
Understand the agent’s core methods and the ReAct paradigm.
Tool
Learn how to extend agents with native functions, MCP, and skills.