-
Notifications
You must be signed in to change notification settings - Fork 167
Memory
weego edited this page May 28, 2026
·
1 revision
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:
pip install mem0aiAdapter 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.
- Home
- 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