p-layer
Memory for AI agents with rules that are kept, not just written - P0-P6 layered rules enforced in code, SQLite + PostgreSQL, MCP server, eval harness. PyPI: p-layers
Install / Use
claude mcp add humanerd-drew -- npx -y github:humanerd-drew/p-layerIf the server publishes to npm under a different name, use that package instead โ check the repo README.
MCP Server
Model Context Protocol server
Quality Score
Category
AI & Machine LearningSupported Platforms
Our assessment of p-layer
p-layer scores 83/100 on our quality scale, 660th of 961 AI & Machine Learning skills we index.
Its MCP Server is 14 KB long, well organised into 27 sections with 7 code examples: a thorough specification that gives an agent plenty to work with.
It has 3 GitHub stars, so there is little community track record yet; judge it on its content.
Maintenance, license and trust
- The repository was last updated about 2 months ago, so p-layer is actively maintained.
- It is released under the MIT license, a permissive license that allows use, modification and commercial use with attribution.
- Its trust signals score 92/100, with 1 caution from licensing, adoption, age or documentation. These come from repository metadata, not a code audit โ read the skill file before letting an agent act on it.
p-layer compared with similar skills
All 4 of these similar skills score higher than p-layer; compare them before choosing.
| Skill | Score | Stars | Updated | Format |
|---|---|---|---|---|
| p-layer (this skill)by humanerd-drew | 83 | 3 | 2mo ago | MCP Server |
| claude-memby thedotmack | 100 | 113.0k | today | CLAUDE.md |
| Agent-Reachby Panniantong | 100 | 108.9k | 1d ago | CLAUDE.md |
| Understand-Anythingby Egonex-AI | 100 | 90.7k | 10d ago | CLAUDE.md |
| headroomby headroomlabs-ai | 100 | 78.9k | today | CLAUDE.md |
Frequently asked questions
- How do I install p-layer?
- Run
claude mcp add humanerd-drew -- npx -y github:humanerd-drew/p-layer. The install tabs above show the steps for each supported agent. - Which AI agents does p-layer work with?
- It is written for Claude Code and Claude Desktop, as a MCP Server file. Other agents that read the same format can often use it too.
- Is p-layer safe to use?
- It is MIT-licensed and scores 92/100 on trust signals. Skills are instructions an agent will follow, so read the file before installing it and do not approve commands you do not understand.
- Is p-layer still maintained?
- The repository was last updated about 2 months ago, so p-layer is actively maintained.
Skill content
View source on GitHubp-layer
Memory for AI agents with rules that are kept, not just written.
๐ README.ko.md โ ํ๊ตญ์ด
Demo
Agent conversation
<img src="examples/p-layer-chat-demo.gif" width="620" alt="p-layer demo โ agent recalls past decisions and gets refused when trying to change a rule">The agent remembers across sessions (recall), and when it tries to change a rule the system refuses until a human approves โ then it's applied and audited.
Memory health report (real data)
<img src="examples/memory-health-dashboard.png" width="620" alt="p-layer memory health dashboard โ real metrics from a production agent stack">A weekly health report: is the memory actually being distilled? Are rules alive? Are there silent failures? (Real numbers from a production agent stack.)
AI assistants today are brilliant and forgetful. When a conversation ends, what was decided in it โ which payment system you switched to, how a client prefers to be contacted, what actually fixed a bug โ ends with it. The next session starts from zero. And when an agent does keep notes, there is no control: anyone can write anything, rules are suggestions, and nothing is ever traced.
p-layer gives an agent a memory that works like a well-run organization instead of a junk drawer:
- it remembers across sessions and finds what you need even weeks later,
- it is organized in layers with clear jobs โ from rules that must never change, to incident reports,
- it enforces its own rules โ the system refuses and records a write that isn't allowed, instead of trusting a prompt,
- it never destroys โ old versions are superseded, and the full history stays,
- and it puts everything on the record โ every write, every refused write, is audited.
It is small, has zero dependencies, speaks the standard connector (MCP) that Claude, opencode, and Cursor already use, and runs on your own machine.
The problem this is trying to solve
Agents are amnesiacs. A chatbot or coding agent only "remembers" what is in the current window. Ask it next week about the decision it made today and it will guess. The first fix for this is a memory store โ a place where facts survive. That part is easy.
The hard part is control. Once an agent can write to a long-term memory, three things go wrong:
- Anyone can write anything. A stray thought gets saved as if it were a company rule, and nobody can tell the difference.
- Rules are only suggestions. "Never change the pricing policy" lives in a text file and is hoped to be followed, not enforced. The agent that is supposed to obey it is also the one that can edit it.
- Everything accumulates, nothing is organized. Raw session logs pile up forever. Finding "the time we fixed the payment bug" means searching through everything.
p-layer is the answer to those three failures: rules first, retrieval second.
The design direction โ five principles
1. Memory is organized in layers, like a brain or an org chart
Every piece of memory belongs to one of seven layers. Each layer has a job and rules about who may touch it:
| Layer | What lives there | Plain-language purpose | Who may write | |---|---|---|---| | P0 | Rules | The constitution. "Never expose secrets." Must not change. | only the system | | P1 | Identity & persona | Who the agent is, how it speaks. | only the system | | P2 | Raw sessions | Everything that happened, kept as-is. | system, gateways, cron | | P3 | Tool integrations | What the agent can plug into. | system, gateways, cron | | P4 | Skills & growth | What the agent has learned to do. | system, agent, human | | P5 | Compiled knowledge | Distilled insights โ the first place to look. | system, agent, tools | | P6 | Incidents & fixes | What broke, why, and what fixed it. | system, agent, human |
Lower layers are higher authority: a P0 rule wins over a P1 preference, without negotiation.
2. Rules are enforced by the system, not by asking nicely
When an agent tries to write to a layer it is not allowed to touch, the write is refused with an error, and the refusal itself is recorded. The rule is not a suggestion in a text file โ it is a permission the system checks on every write.
3. Memory is never destroyed โ it is superseded
There is no delete button that erases history. "Forgetting" marks an entry as superseded: it stops showing up in searches, but the record of it โ and of what replaced it โ remains. This is version control applied to memory.
4. Everything is on the record
An audit log records every write and every refused write: who did it, to which layer, when, and why. If something wrong ever lands in memory, you can see exactly how it got there โ and roll the memory back to a snapshot from before it happened.
5. Memory organizes itself
Raw notes are fine for a while; they are not fine forever. p-layer runs maintenance the way a good organization does:
- Consolidation โ batches of raw session notes are distilled into short insights (the messy P2 becomes useful P5).
- A compiled wiki โ active knowledge is rendered into clean, per-layer pages with their origin story attached.
- Snapshots โ you can freeze the memory at a point in time and roll back to it.
- Re-embedding โ when the underlying understanding model changes, memory is re-indexed in the background instead of breaking.
One method, two homes
The same memory, with the same rules, runs in two places:
- SQLite โ a single file on your machine. Perfect for one personal agent.
- PostgreSQL โ a shared database. For a team or a small business where several agents (or people) use one memory.
The rules, layers, and behavior are identical in both; the same test suite verifies both so they cannot drift apart.
How it works โ one story
Suppose your AI assistant is maintaining a small shop's payment system.
- P6 โ the incident. The assistant discovers a payment bug. It writes an incident report: what happened, timeline, and its first guess at a root cause.
- P0 โ the rule check. The root cause turns out to be a rule violation. The assistant proposes a rule amendment; only the system can actually change P0.
- The knowledge graph. The incident is linked to the payment tool and to the fix pattern it depends on. "What is related to this payment bug?" is now answerable by walking those links โ a root-cause analysis.
- Weeks later โ recall. A similar symptom appears. The assistant searches memory and the old incident surfaces, ranked by relevance and how certain it was โ before the same mistake is repeated.
- Nightly โ consolidation. The session's raw notes are distilled into a durable insight and added to the compiled knowledge.
- The same bug never happens twice โ not because the agent is smarter, but because the organization of its memory remembered.
Proof it works
The eval harness (p_layer eval <suite.json>) runs the same data through two engines โ the drewgent baseline (a reconstruction of its searchKnowledge: quote-stripped OR-join FTS5) and p-layer (hybrid FTS5 + semantic, RRF-fused) โ and reports recall@k for both, plus ACL compliance:
python3 -m p_layer eval examples/suite.example.json
Retrieval scores depend on your data and embedder, so this page does not hard-code them; benchmarks/real_data_bench.py measures recall@k / MRR on a real memory archive. What is deterministic is the governance: p-layer ranks by how certain the memory was and how fresh it is, not just by word matching, and all 30 (layer, who) permission cases (every layer ร every writer) are enforced by the system (pass_rate: 1.0) with every denied write recorded in the audit log.
Try it in two minutes
pip install p-layers
p-layer --db ~/.p_layer/memory.db --embed hash init
p-layer --db ~/.p_layer/memory.db --embed hash status
p-layer --db ~/.p_layer/memory.db --embed hash remember "we switched to PortOne v2 for payments" --type decision --source onboarding
p-layer --db ~/.p_layer/memory.db --embed hash recall "payment" --why
p-layer --db ~/.p_layer/memory.db --embed hash context "current payment task"
p-layer --db ~/.p_layer/memory.db --embed hash doctor
init creates the store and prints the next commands. status is safe to run
before initialization; doctor checks the schema, integrity, FTS index, and
embedding configuration. Call context once at session start to retrieve
task-relevant memory and place canonical rules first within the budget. Add
--why to recall to see each result's source, session, and creation time.
No separate database or service is required; the memory is one file.
Use it with your AI tools
Agents talk to memory through MCP, the standard connector. Add one block to your tool's config and the agent can remember, recall, audit, snapshot, and trace root causes:
At the start of a task, call context with the current user request; it returns
relevant memories and canonical rules in one bounded payload.
{
"mcp": {
"p-layer": {
"type": "local",
"command": ["python3", "-m", "p_layer", "serve"],
"env": { "P_LAYER_DB": "~/.p_layer/memory.db" }
}
}
}
For developers โ the technical shape
- Engine:
p_layer.store.Storeโ SQLite + FTS5 + pluggable embeddings, forward-only checksummed migrations. One schema, one implementation. - Governance: P0-P6 layer ACLs enforced at write time (
WriteDenied), supersede-not-delete, snapshots/rollback, full audit log, contradiction scan. - Recall: hybrid FTS5 + semantic, RRF fusion, additive rerank (confidence + recency + TTL boosts), superseded excluded, type-diversified.
- Graph: typed entity/relation ontology with constraint validation, explore / trace / root-cause analysis / transitive closure (cycle-safe).
- Ops jobs:
reembed(versioned vector backfill),consolidate(episodic โ semantic digests),compile-wiki(P5 pages). SQLite-only; on PostgreSQL they raise loudly rather than silently degrade. - Governance & drift (0.7.0):
gate(P0 ontology review gate โ propose โ approve โ apply/deprecate, human approval required, idempotent, JSONL validation) anddrift-report(weekly baseline comparison over knowledge/episodes/entities/gate state; read-only, distinguishes no-change from failure). - PostgreSQL:
p_layer.pgstore.PgStoreโ same interface and behavior, verified by a shared parity suite (pg_trgm ILIKE for CJK, pgvector optional). - MCP server: 14 tools, including query-aware startup
context, with a zero-dependency stdio implementation verified end-to-end by wire-level tests (and against the official SDK in CI). - Migration from legacy agent memory: already running an agent memory store?
import-drewgentcopies a legacyknowledge.db(knowledge/entities/relations/sessions) into p_layer, andp_layer.drewdbcan even open it in place under p_layer's governance (WAL, busy timeout) so your existing tools keep working while p_layer takes over the connection.import-rules/import-incidentsbring your existing rule and incident files in. You migrate when you're ready โ nothing is locked in. - Tests: 167 โ SQLite + PostgreSQL parity, governance, graph, ops, MCP wire, packaging, FTS5 query sanitization regressions, additive rerank, and CLI UX/context.
- PyPI:
p-layersยท GitHub:p-layerยท package:p_layerยท console:p-layer
python3 -m unittest discover -s tests -v # no dependencies, no network
Additive Rera
Truncated for display โ read the full file on GitHub.
Related Skills
claude-mem
113.0kPersistent Context Across Sessions for Every Agent โ Captures everything your agent does during sessions, compresses it with AI, and injects relevant context back into future sessions. Works with Claude Code, OpenClaw, Codex, Gemini, Hermes, Copilot, OpenCode + More
Agent-Reach
108.9kGive your AI agent eyes to see the entire internet. Read & search Twitter, Reddit, YouTube, GitHub, Bilibili, XiaoHongShu โ one CLI, zero API fees.
Understand-Anything
90.7kGraphs that teach > graphs that impress. Turn any code into an interactive knowledge graph you can explore, search, and ask questions about. Works with Claude Code, Codex, Cursor, Copilot, Gemini CLI, and more.
headroom
78.9kCompress tool outputs, logs, files, and RAG chunks before they reach the LLM. 20% fewer tokens for coding agents, 60-95% fewer tokens for JSON, same answers. Library, proxy, MCP server.
Languages
Trust signals
From repository metadata: license, adoption, age and documentation. Not a code audit โ see the Safety scan above for what the skill file itself contains.
