Open-source memory observability and introspection layer for LLM agents
Debug what your AI agent remembers.
llm agent memory observability introspection ai artificial-intelligence langchain mem0 claude codex grok cursor langgraph tracing debugging production monitoring
MemLens is an open-source memory observability and introspection layer for LLM agents. It provides visibility into what your agent remembers, why it remembers it, and how that memory affects behavior across sessions. MemLens fills the critical gap between tracing LLM calls and understanding memory state in production AI systems.
You can trace every LLM call, but you have no idea what your agent remembers.
When an agent gives a wrong answer in production, teams cannot determine if it was a model failure or a memory failure — because memory extraction, retrieval, and belief state are completely invisible.
INFRASTRUCTURE → latency, uptime, errors [✅ Solved by APM tools]
LLM CALLS → tokens, costs, quality [✅ Solved by LangSmith, etc.]
AGENT BEHAVIOR → tool use, reasoning chains [✅ Solved by agent tracing]
MEMORY STATE → what was extracted, stored, [❌ ALMOST NO TOOLING]
retrieved, believed
MemLens fills this critical gap by providing memory observability — the ability to see, understand, and debug what your agent remembers.
- AI Engineers building production agents with Claude Code, Codex, Grok, Cursor, LangGraph, or custom frameworks
- DevOps/SRE teams monitoring agent health and memory drift
- Compliance officers in regulated industries requiring audit trails
- AI Researchers studying memory system behavior
- Open-source contributors building the next generation of agent frameworks
Log every memory extraction decision with full visibility:
- What was stored vs. dropped
- Importance scores and confidence levels
- Deduplication decisions
- LLM reasoning for each decision
- Extraction latency metrics
Log every memory retrieval with complete transparency:
- What was returned vs. rejected
- Relevance scores and ranking
- Retrieval strategy used
- Query-to-result mapping
Query what the system believes about any user at any time:
- Total memories and type distribution
- Top memories by importance
- Detected contradictions
- Confidence distribution
- Temporal range of memories
Trace any wrong response backward to its memory origins:
- Response → Retrieved memories → Extraction decisions → Original sessions
- Identify whether failures are model-level or memory-level
- Root-cause analysis for production incidents
Monitor memory system health in real-time:
- Memory drift detection over time
- Contradiction rate tracking
- Staleness scores
- Latency trends and percentiles
- Extraction quality metrics
pip install memlenspython -m memlens.api.main
# Server running at http://localhost:8000import asyncio
from memlens.sdk import MemLensClient
async def main():
# Initialize client
client = MemLensClient("http://localhost:8000")
# Trace a memory write
trace = await client.create_write_trace({
"session_id": "session_123",
"user_id": "user_456",
"agent_id": "agent_1",
"candidates": [...],
"stored_memories": [...],
})
# Get belief state
belief = await client.get_belief_state("user_456")
print(f"Agent believes: {belief['top_memories']}")
asyncio.run(main())Open memlens/dashboard/index.html in your browser to view memory health metrics, traces, and belief states.
from memlens.sdk import MemLensClient, memlens_trace
memlens = MemLensClient("http://localhost:8000")
@memlens_trace(user_id="user_123", agent_id="claude_code")
async def process_with_claude(user_input: str):
# Your Claude Code logic here
# MemLens automatically traces memory operations
passfrom memlens.integrations import BaseIntegration
class CodexIntegration(BaseIntegration):
async def wrap_memory_add(self, user_id: str, context: dict):
# Wrap Codex memory operations
return await self.memlens.create_write_trace({...})from memlens.sdk import MemLensClient
memlens = MemLensClient("http://localhost:8000")
# Trace Grok memory operations
await memlens.create_write_trace({
"session_id": grok_session_id,
"user_id": user_id,
"agent_id": "grok",
"candidates": extracted_memories,
})from memlens.sdk import MemLensClient
memlens = MemLensClient("http://localhost:8000")
# Trace Cursor's memory operations
await memlens.create_write_trace({
"session_id": cursor_session_id,
"user_id": user_id,
"agent_id": "cursor",
"candidates": cursor_memories,
})from memlens.sdk import MemLensClient
from langgraph.graph import StateGraph
memlens = MemLensClient("http://localhost:8000")
# Integrate with LangGraph nodes
async def memory_node(state: dict):
# Your LangGraph memory logic
await memlens.create_write_trace({...})
return statefrom memlens.sdk import MemLensClient
memlens = MemLensClient("http://localhost:8000")
class MyCustomAgent:
async def add_memory(self, user_id: str, content: str):
# Your custom memory logic
# Trace with MemLens
await memlens.create_write_trace({
"session_id": self.session_id,
"user_id": user_id,
"agent_id": "custom_agent",
"candidates": [...],
})┌─────────────────────────────────────────────────────────────┐
│ Agent Application │
│ ┌─────────────┐ ┌─────────────┐ ┌───────────────────── │
│ │ Claude Code │ │ Codex │ │ Custom Agent │ │
│ │ Cursor │ │ Grok │ │ LangGraph │ │
│ └──────┬──────┘ └──────┬────── └──────────┬────────── │
│ └─────────────────┼─────────────────────┘ │
│ │ │
│ ┌──────────▼──────────┐ │
│ │ MemLens Wrapper │ │
│ │ (Instrumentation │ │
│ │ & Interception) │ │
│ └──────────┬───────────┘ │
│ │ │
│ ┌───────────────┼───────────────┐ │
│ │ │ │ │
│ ┌────▼────┐ ┌────▼────┐ ┌────▼────┐ │
│ │ Write │ │ Read │ │ Belief │ │
│ │ Traces │ │ Traces │ │ State │ │
│ └────┬────┘ └────┬────┘ └────┬────┘ │
│ │ │ │ │
│ └───────────────┼───────────────┘ │
│ │ │
│ ┌──────────▼──────────┐ │
│ │ MemLens Storage │ │
│ │ (SQLite/Postgres │ │
│ │ + Time-series DB) │ │
│ └──────────┬─────────── │
│ │ │
│ ┌──────────▼──────────┐ │
│ │ MemLens Dashboard │ │
│ │ (Web UI for memory │ │
│ │ introspection) │ │
│ └─────────────────────┘ │
└─────────────────────────────────────────────────────────────┘
from memlens.integrations import Mem0Integration
memlens = MemLensClient()
mem0 = Mem0Client()
integration = Mem0Integration(mem0, memlens)
await integration.wrap_memory_add(user_id="user_123", messages=[...])from memlens.integrations import LangChainIntegration
memlens = MemLensClient()
langchain_memory = ConversationBufferMemory()
integration = LangChainIntegration(langchain_memory, memlens)
await integration.wrap_memory_add(user_id="user_123", inputs={"input": "...", "output": "..."})| Endpoint | Method | Description |
|---|---|---|
/health |
GET | Health check |
/traces/write |
POST | Create write trace |
/traces/write/{id} |
GET | Get write trace |
/traces/read |
POST | Create read trace |
/traces/read/{id} |
GET | Get read trace |
/belief-state/{user_id} |
GET | Get belief state |
/belief-state/{user_id}/health |
GET | Get health metrics |
/causal-chain/{response_id} |
GET | Get causal chain |
- Agent Integration Guide — executable instructions and prompts for coding agents
- Quick Start Guide
- API Reference
- Architecture Guide
- Integration Guide
- Contributing
git clone https://github.com/grimdalltech/MemLens.git
cd MemLens
pip install -e ".[dev]"pytestpython -m memlens.api.main- Core tracing engine
- SQLite storage
- FastAPI server
- Python SDK
- Mem0 integration
- LangChain integration
- Web dashboard
- PostgreSQL support
- Memory drift detection
- Advanced analytics
- Enterprise features
We welcome contributions! Please see CONTRIBUTING.md for details.
MIT License - see LICENSE for details.
MemLens — Because you can't fix what you can't see.