agent-sleep
This server does not currently have a deployable release on Glama. Follow the repository's setup instructions to install and configure it for your MCP client, including any required credentials and local dependencies.
š§ agent-sleep
Persistent Experience Consolidation & Decision Support for AI Agents.
A lightweight, framework-agnostic Python library and MCP server that provides persistent experience consolidation and decision-support signals that a host agent can use to adapt across sessions ā inspired by how the biological brain uses sleep cycles to consolidate waking experiences into lasting procedural rules and lessons.
The Problem: "Agent Amnesia"
Every modern AI agent framework (LangChain, AutoGen, CrewAI, OpenAI Assistants) suffers from Agent Amnesia:
Every new chat or subagent run starts completely from scratch.
When an agent hits an error or discovers a codebase convention on Monday, it repeats the exact same mistake on Tuesday.
Vector DBs (RAG) only search static documents ā they do not learn from runtime experience.
Related MCP server: recall-memory-mcp
MCP Quick Start ā 10 seconds
This is the primary usage path.
agent-sleepships as an MCP server, so any agent that supports MCP (Antigravity, Claude Desktop, Cursor, Cline) can use it without writing any code.
Step 1 ā Install and generate your config
# Option A: Install from GitHub with pip (recommended)
pip install "agent-sleep[mcp] @ git+https://github.com/thevisionhub/agent-sleep.git"
# Option B: Local editable install (if cloned)
git clone https://github.com/thevisionhub/agent-sleep.git
cd agent-sleep
pip install -e ".[mcp]"
# Option C: Zero-install via uvx (if uv is installed)
uvx --from "git+https://github.com/thevisionhub/agent-sleep.git" agent-sleep-mcpAfter installing, generate your platform-specific config snippet:
agent-sleep initagent-sleep init auto-detects your OS and prints the exact JSON snippet to paste into your MCP client.
Step 2 ā Paste the config snippet into your MCP client
For Claude Desktop:
macOS:
~/Library/Application Support/Claude/claude_desktop_config.jsonWindows:
%APPDATA%\Claude\claude_desktop_config.json
{
"mcpServers": {
"agent-sleep": {
"command": "agent-sleep-mcp"
}
}
}(Or if using zero-install uvx without pip install:)
{
"mcpServers": {
"agent-sleep": {
"command": "uvx",
"args": [
"--from",
"git+https://github.com/thevisionhub/agent-sleep.git",
"agent-sleep-mcp"
]
}
}
}For Antigravity / Cursor / Cline:
Add to your mcp_config.json or .cursor/mcp.json:
{
"mcpServers": {
"agent-sleep": {
"command": "agent-sleep-mcp"
}
}
}Restart your MCP client, and you're done.
Step 3 ā Ask your agent to use it
"Before we start, check your memory for anything relevant to this task."
"Record that we use pytest fixtures ā not unittest ā in this project."
"Run a sleep consolidation so you remember today's lessons next session."Memory is automatically stored in .agent_sleep/memory.db in your project directory (gitignored by default).
Inspect what's stored ā CLI
You don't need to go through an LLM to see what your agent has learned:
# See all memories and rules for the current project
agent-sleep show
# Clear a project's memory (with confirmation prompt)
agent-sleep reset
# Target a specific scope or DB
agent-sleep show --scope my_api --db /path/to/memory.dbHow It Works: The 3-Phase Pipeline
[ ONLINE EXECUTION PHASE ]
Agent executes tool calls
ā
ā¼
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
ā 1. EPISODIC RECORDING ā
ā memory.record_episode(...) ā Fast, minimal overhead.
ā Records goal, action, outcome, errors. ā Stores execution events.
āāāāāāāāāāāāāāāāāāāāāāāā¬āāāāāāāāāāāāāāāāāāāāāāāā
ā
(Session ends / Agent idle)
ā
ā¼
[ OFFLINE SLEEP CONSOLIDATION ]
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
ā 2. SLEEP CONSOLIDATOR (8-Stage Pipeline) ā
ā SleepConsolidator.run(session_id) ā
ā ā
ā ⢠Priority Replay (prediction error) ā
ā ⢠Deterministic Episodic Distillation ā Grounding first:
ā ⢠Procedural Recipe Extraction ā distills facts & lessons
ā ⢠How-Memory Trajectory Abstraction ā before optional LLM
ā ⢠Behavioral Rule Promotion (seen ā„2x) ā generalization passes.
ā ⢠Epistemic Status (observed vs verified)ā
ā ⢠Episodic Compression over time ā
ā ⢠Self-Competence EMA Tracking ā
āāāāāāāāāāāāāāāāāāāāāāāā¬āāāāāāāāāāāāāāāāāāāāāāāā
ā
(Next session / New task)
ā
ā¼
[ ONLINE SELECTIVE RECALL ]
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
ā 3. SELECTIVE SEMANTIC RECALL ā
ā memory.recall(new_task) ā Pre-computed vector BLOBs.
ā Returns only relevant lessons & rules ā Prevents prompt dilution.
ā filtered by project scope & relevance. ā
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāKey Features (v0.1.2-alpha)
Pre-Computed Vector BLOBs: Embeds the query once and compares it against pre-computed stored vectors, eliminating repeated text embedding during recall.
Epistemic Memory Lifecycle: Tracks memory progression through stages (
RAWāOBSERVEDāREPEATEDāVERIFIEDāACTIVE), automatically quarantining contradictory or high-failure memories.Verifiable Causal Attribution & Utility Feedback: Evaluates whether retrieved memories actually helped future execution via structured evidence records (
retrievalāaction changeāoutcome attribution).Evidence Diversity Causal Hypotheses: Distills recurring failures into causal mechanisms using evidence diversity scaling across independent sources and environments.
Bayesian Self-Competence Model: Estimates domain competence and Bayesian Beta-distribution uncertainty across composite domains to provide adaptive decision support (verification intensity, retry budgets) for host agents.
First-Class Rule Specificity Engine: Resolves rule conflicts through hierarchical precedence (
specific verified>general verified>specific candidate>general candidate) and dynamic exception suppression.Scope & Project Isolation: Multi-tier namespaces (
scope="repo_a",scope="global"). Project-specific knowledge is strictly isolated, while universal idioms and tool failure modes can optionally be shared viaglobal.Zero Mandatory Heavy Dependencies: Works out-of-the-box using standard SQLite and a deterministic hashed bag-of-words fallback. Seamlessly upgrades to
sentence-transformers(all-MiniLM-L6-v2) when installed.
Benchmarks & Evaluation
1. Controlled Transfer Simulation (benchmarks/run.py)
Evaluates memory consolidation, vector retrieval, and knowledge transfer across 12 sequential software tasks with recurring architectural traps:
Metric | Memory OFF | Memory ON | Improvement |
Pass Rate (Pass@12) | 67% | 92% | +25 percentage points |
Avg LLM Calls / Task | 14.7 | 8.5 | -42% (fewer calls) |
Repeated Mistakes | 8 | 2 | -75% (fewer mistakes) |
Note: The controlled transfer simulation evaluates the deterministic cognitive-control dynamics of memory retrieval and trap avoidance.
2. Canonical 6-Way Ablation Benchmark (benchmarks/agent_eval/runner.py)
Controlled sandbox evaluation of memory-driven agent-control dynamics across 8 standardized software engineering tasks:
Experimental Condition | Pass Rate (Zero-Shot) | Avg LLM Calls / Task | Repeated Traps | Memory Useful Rate |
| 12.5% | 3.6 | 4 | 0.0% |
| 12.5% | 3.6 | 4 | 0.0% |
| 12.5% | 3.6 | 4 | 0.0% |
| 25.0% | 2.9 | 2 | 12.5% |
| 37.5% | 2.5 | 1 | 25.0% |
| 75.0% | 1.4 | 0 | 75.0% |
python benchmarks/agent_eval/runner.pyScientific & Backend Disclosure:
The sandbox benchmark evaluates agent control dynamics, token efficiency, and error avoidance under controlled test suites.
Embedding Backends: High-precision vector similarity relies on
sentence-transformers(all-MiniLM-L6-v2). When dependencies are absent, the library automatically falls back to a deterministic hashed bag-of-words embedding.Full reproducibility protocols and metric logs are documented in
benchmarks/agent_eval/results.json.
Python Library Usage
If you prefer to drive the memory system from your own agent code rather than via MCP, the Python API is fully supported.
from agent_sleep import AgentMemory, SleepConsolidator
# 1. Initialize memory scoped to your project/repo
memory = AgentMemory(session_id="session_01", scope="payment_service")
# 2. Record actions and outcomes during your agent's loop
memory.record_episode(
goal="Refactor payment processor to async",
action="edit_file('processor.py', ...)",
outcome="failure",
failure_reason="SyntaxError: 'await' outside async function",
)
# 3. Trigger sleep consolidation when idle or at session end
consolidator = SleepConsolidator(scope="payment_service")
report = consolidator.run(session_id="session_01")
# -> {'episodes_processed': 1, 'memories_written': 1, 'rules_promoted': 0, ...}
# 4. Next session: recall relevant context before executing
context = memory.recall("Add Stripe webhook handler")
print(context)
# [MEMORY CONTEXT]
# Relevant past experience:
# ā [LESSON] Caution on task: Refactor payment processor to async:
# A previous attempt failed: SyntaxError: 'await' outside async function.
# [END MEMORY CONTEXT]Installation
From GitHub (Latest Alpha with MCP):
pip install "agent-sleep[mcp] @ git+https://github.com/thevisionhub/agent-sleep.git"With full semantic embeddings (sentence-transformers):
pip install "agent-sleep[all] @ git+https://github.com/thevisionhub/agent-sleep.git"Editable install for local development:
git clone https://github.com/thevisionhub/agent-sleep.git
cd agent-sleep
pip install -e ".[all]"MCP Tools Reference
Tool | When to call |
| Before planning or executing any non-trivial task ā retrieves lessons, rules, causal traps, and self-competence directives |
| During execution ā after each tool failure or milestone |
| After a session ends or when the agent is idle |
| Anytime ā inspects memory health, epistemic breakdowns, and pending episodes |
| After applying retrieved knowledge ā records causal outcome attribution and updates utility scores |
| When discovering exceptions or boundary conditions for existing rules |
All tools default scope to the current working directory name and db_path to .agent_sleep/memory.db in the project root. No configuration required for the common case.
Run Tests
pytest tests/ -vGet Discovered ā Registry Listings
Submitting agent-sleep to MCP registries takes about 5 minutes each and is the fastest way to reach developers looking for memory tools:
Smithery ā paste the GitHub URL, add a short description, done.
modelcontextprotocol/servers ā open a PR adding an entry to the README under "Community Servers".
Cursor ā also surfaces MCP servers; check their current docs for the latest submission process.
License
MIT License ā free for personal, commercial, and research use.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelogā¦
This server cannot be deployed
Maintenance
Related MCP Connectors
Persistent memory for AI agents to retain, retrieve, and recall conversation context through MCP.
Persistent memory for AI agents: keyed facts, a wake bundle each session, one memory in every model.
Persistent memory for AI agents: save, search and connect context across tools and sessions.
Persistent memory, inline redaction, per-agent access, and code localization for AI agents.
Related MCP Servers
- AlicenseNot gradedqualityCmaintenanceProvides persistent, cross-session memory for AI agents, allowing them to store and automatically retrieve information across different conversations and sessions without repeating context.8 npm178MIT
- AlicenseNot gradedqualityDmaintenanceEnables AI agents to store, retrieve, and self-improve procedural memories (lessons learned) based on relevance to the current task, pruning unused memories to reduce context load and prevent repetition of past mistakes.MIT
- AlicenseAqualityBmaintenanceEnables AI agents to persistently recall, apply, and reinforce solutions to previously solved problems across different models and tools, so mistakes are not repeated.14202 npm1MIT
- AlicenseNot gradedqualityBmaintenanceEnables AI agents to record episodic events, decay stale transient interactions using an Ebbinghaus forgetting curve, and consolidate frequent episodes into enduring semantic user persona traits for long-term personalization.7MIT