Agent Memory — 错题本
The error notebook for AI agent tool calls.
pip install agent-memory→ one SQLite file → your agent stops repeating mistakes.
Why
Every AI agent hits the same wall: it calls web_search, gets a timeout, retries with the same long query, times out again. With Agent Memory, it learns: "long queries cause timeouts → shorten them." Next time, it gets it right on the first try.
Benchmark (3 tasks × 5 learning rounds):
| Metric | Without Memory | With Memory | Improvement |
|---|---|---|---|
| Trial-and-error fixes (Web Research) | 20 | 5 | -75% |
| Trial-and-error fixes (File Processing) | 20 | 4 | -80% |
| Trial-and-error fixes (API Debugging) | 20 | 5 | -75% |
Memory doesn't just store data — it stores lessons. The agent re-discovers fewer fixes, wastes fewer tokens, and completes tasks faster.
Install
pip install agent-memory
# With optional semantic search:
pip install agent-memory[embed]
# With MCP server:
pip install agent-memory[mcp]
Quick Start
from agent_memory import AgentMemory
mem = AgentMemory("./agent_errors.db")
# Log a tool call outcome
mem.remember(
tool="web_search",
input="GRPO reinforcement learning survey with comparison...",
outcome="fail",
error="timeout",
error_detail="Request timed out after 30s",
fix="shorten query to under 80 chars",
)
# Search relevant past experiences
results = mem.recall("web_search timeout")
for r in results:
print(f"[{r['outcome']}] {r['tool']}: {r['fix']} (confidence: {r['confidence']:.0%})")
# Review memories for manual correction
mem.review(low_confidence_only=True)
# After using a memory, confirm if it helped
mem.confirm(memory_id=1, was_helpful=True)
MCP Server
Use as an MCP server that any agent framework can connect to:
agent-memory serve --db ./agent_errors.db
Add to your MCP client config:
{
"mcpServers": {
"agent-memory": {
"command": "agent-memory",
"args": ["serve", "--db", "./agent_errors.db"]
}
}
}
Available MCP tools: remember, recall, review, forget, confirm, stats.
How It Works
- Remember: Agent logs every tool call — success or failure, with error type and fix
- Store: SQLite with FTS5 trigram tokenizer (English + CJK), time-decay ranking, confidence scoring
- Recall: Agent queries past experiences before making decisions
- Learn: Confidence adjusts based on whether the memory actually helped
No LLM calls — all storage and retrieval is pure rules + SQL. Your agent's LLM only sees the relevant memories as context.
Write Strategy
| What | Strategy |
|---|---|
| Failures | Always remember (error type, detail, fix) |
| Successes | Deduplicated by tool+input hash (count bumps, not duplicate rows) |
| Output size | Truncated to 500 chars (head + tail) |
| Eviction | Oldest low-confidence memories purged at 10K limit |
Anti-Pollution
- Confidence scoring: +0.2 when memory helps, -0.2 when it misleads
- Time decay: Older memories rank lower (configurable half-life, default 30 days)
- Human review:
review()for manual inspection andforget()for removal
Roadmap
| Version | Scope |
|---|---|
| v0.1 | SQLite + FTS5 + remember/recall/review/forget + MCP server |
| v0.2 | Optional semantic search (fastembed) |
| v0.3+ | Graph-based retrieval (only if benchmark proves FTS5 insufficient) |
License
MIT
Release files for errnote 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| errnote-0.1.0.tar.gz | 13.4 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| errnote-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 25.4 kB
Release files / errnote-0.1.0.tar.gz
| Download URL | errnote-0.1.0.tar.gz |
|---|---|
| Size | 13.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
cd59536448ecfa2c18845cf1b09d1b423532b376da2a1095e220274ad6fd58f1
|
|
BLAKE2b-256 checksum How to use checksums |
07459027999d97bf765e42afe11686e8d1936a9a2ae81413f4a85aadb08b64a9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.3
|
Release files / errnote-0.1.0-py3-none-any.whl
| Download URL | errnote-0.1.0-py3-none-any.whl |
|---|---|
| Size | 11.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
3419e550df991f532e431ba2a6d0181123a2093c09b54c61564bc1f40c79ed84
|
|
BLAKE2b-256 checksum How to use checksums |
0cc020d8f875be8074b1ad50b15814bd412c2ae72458ff089bde9ba0d65d0a1d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.3
|