Repository navigation
Memory
weego edited this page Nov 15, 2026
·
2 revisions
LightAgent supports external memory backends through a minimal protocol. The framework does not force a specific vector database or memory provider.
A memory object should implement:
class CustomMemory:
def store(self, data: str, user_id: str):
...
def retrieve(self, query: str, user_id: str):
...Then pass it to LightAgent:
agent = LightAgent(
model="gpt-4.1",
api_key="your_api_key",
base_url="https://api.openai.com/v1",
memory=CustomMemory(),
)
print(agent.run("Remember that I prefer short answers.", user_id="user_01"))
print(agent.run("How should you answer me?", user_id="user_01"))Use a stable user_id. Memory quality and isolation depend on it.
Install Mem0:
python -m pip install 'lightagent[mem0] @ git+https://github.com/wanxingai/LightAgent.git@v1.0.0'Adapter shape:
from mem0 import Memory
class Mem0Memory:
def __init__(self):
self.memory = Memory.from_config(config_dict={"version": "v1.1"})
def store(self, data: str, user_id: str):
return self.memory.add(data, user_id=user_id)
def retrieve(self, query: str, user_id: str):
return self.memory.search(query, user_id=user_id)For shared backends, use MemoryPolicy to scope memory calls and filter retrieved records that expose provenance:
from LightAgent import LightAgent, MemoryPolicy
agent = LightAgent(
model="gpt-4.1",
api_key="your_api_key",
base_url="https://api.openai.com/v1",
memory=memory_backend,
memory_policy=MemoryPolicy(
namespace="prod-tenant-a",
allow_unattributed_results=False,
),
)namespace prefixes the user_id sent to the backend. If retrieved memory items include user_id, userId, metadata.user_id, or metadata.userId, LightAgent filters out records that do not match the current user.
You can also use the shortcut:
agent = LightAgent(
model="gpt-4.1",
api_key="your_api_key",
base_url="https://api.openai.com/v1",
memory=memory_backend,
memory_namespace="prod-tenant-a",
)- Use separate namespaces per user, tenant, agent, and environment.
- Do not mix trusted system facts and untrusted user claims in the same namespace.
- Keep provenance metadata for memory writes.
- Filter retrieval by user, tenant, agent, and trust level.
- Treat retrieved memory as context, not as guaranteed truth.
- For finance, healthcare, legal, or enterprise automation, require trusted source verification before making high-impact recommendations.
More detail: Memory Security Guidance.
LightAgent Wiki - see the repository, releases, and issues.
- Installation and Your First Agent
- Tools and Integrations
- Memory, Sessions, and RAG
- Workflows and Multiple Agents
- Agent Backends and Codex
- Durable Execution, Jobs, and Subagents
- Safety, Observability, and Evaluation
- Usage, Cost Estimates, and Budgets
- Deployment, Migration, and Verification
- 安装与第一个 Agent
- 工具和集成
- 记忆、会话与 RAG
- 工作流与多 Agent
- 执行后端与 Codex
- 持久执行、Jobs 与 Subagents
- 安全、观测与评测
- 用量统计、费用估算与预算
- 部署、升级与验收
- Quick Start
- Core Concepts
- API Reference
- Examples Cookbook
- Migration Guide
- Tools
- Tool Generator
- Memory
- MCP
- Skills
- LightFlow
- Tree of Thought
- Self-Learning
- Multi-Agent
- Tracing and Debugging
- Langfuse Observability
- Model Providers
- browser-use Integration
- Testing and CI
- Deployment Guide
- Architecture
- Security
- Known Limitations
- FAQ
- FAQ 中文
- Roadmap
- Release Process
- Contributing