Persistent memory for AI agents. One SQLite file. No server, no API keys, no LLM calls. MCP server included.
Project description
brainctl
Your AI agent forgets everything between sessions. brainctl fixes that.
One SQLite file gives your agent persistent memory — what it learned, who it talked to, what decisions were made, and why. No server. No API keys. No LLM calls.
from agentmemory import Brain
brain = Brain(agent_id="my-agent")
# Start of session — get full context in one call
context = brain.orient(project="api-v2")
# → {'handoff': {...}, 'recent_events': [...], 'triggers': [...], 'memories': [...]}
# During work
brain.remember("API rate-limits at 100 req/15s", category="integration")
brain.decide("Use Retry-After for backoff", "Server controls timing", project="api-v2")
brain.entity("RateLimitAPI", "service", observations=["100 req/15s", "Retry-After header"])
# End of session — preserve state for next agent
brain.wrap_up("Documented rate limiting, auth module complete", project="api-v2")
Next session, a different agent (or the same one) picks up exactly where you left off.
Install
pip install brainctl
That's it. No dependencies beyond Python 3.11+ and SQLite (built-in). Optional extras:
pip install brainctl[mcp] # MCP server for Claude Desktop / VS Code
pip install brainctl[vec] # vector similarity search (sqlite-vec + Ollama)
pip install brainctl[all] # everything
Quick Start
Python API
from agentmemory import Brain
brain = Brain() # creates ~/agentmemory/db/brain.db automatically
brain.remember("User prefers dark mode", category="preference")
brain.search("dark mode") # FTS5 full-text search with stemming
brain.entity("Alice", "person", observations=["Engineer", "Likes Python"])
brain.relate("Alice", "works_at", "Acme")
brain.log("Deployed v2.0", event_type="result", project="myproject")
brain.decide("Keep JWT expiry at 24h", "Security vs UX balance")
brain.trigger("deploy fails", "deploy,failure,502", "Check rollback procedure")
brain.doctor() # {'healthy': True, 'active_memories': 5, ...}
CLI
brainctl memory add "Auth uses JWT with 24h expiry" -c convention
brainctl search "auth"
brainctl entity create "Alice" -t person -o "Engineer"
brainctl entity relate Alice works_at Acme
brainctl event add "Deployed v2.0" -t result -p myproject
brainctl trigger create "deploy issue" -k deploy,failure -a "Check rollback"
brainctl stats
MCP Server (Claude Desktop / VS Code / Cursor)
{
"mcpServers": {
"brainctl": {
"command": "brainctl-mcp"
}
}
}
192 tools available. See MCP_SERVER.md for the full list and a decision tree showing which tools to use when.
The Drop-In Pattern
Any agent, any framework. Three lines:
context = brain.orient() # session start: handoff + events + triggers + memories
# ... do work ...
brain.wrap_up("what I accomplished") # session end: logs event + creates handoff
orient() returns a single dict with everything the agent needs: pending handoff from the last session, recent events, active triggers, relevant memories, and stats. wrap_up() creates a handoff packet so the next session can resume.
See examples/ for runnable scripts and docs/AGENT_ONBOARDING.md for the full agent integration guide.
Framework Integrations
LangChain
pip install brainctl langchain-core
from agentmemory.integrations.langchain import BrainctlChatMessageHistory
from langchain_core.runnables.history import RunnableWithMessageHistory
chain_with_history = RunnableWithMessageHistory(
runnable=my_chain,
get_session_history=lambda sid: BrainctlChatMessageHistory(session_id=sid),
)
Chat messages persist in brain.db. The Brain instance is accessible via history.brain for knowledge operations beyond chat (entities, decisions, triggers, search).
CrewAI
pip install brainctl crewai
from crewai import Crew
from crewai.memory import ShortTermMemory, LongTermMemory, EntityMemory
from agentmemory.integrations.crewai import BrainctlStorage
crew = Crew(
agents=[...], tasks=[...], memory=True,
short_term_memory=ShortTermMemory(storage=BrainctlStorage("short-term")),
long_term_memory=LongTermMemory(storage=BrainctlStorage("long-term")),
entity_memory=EntityMemory(storage=BrainctlStorage("entity")),
)
All crew memory goes to a single brain.db. FTS5 search out of the box, optional vector search with pip install brainctl[vec].
Python API (21 methods)
| Method | What it does |
|---|---|
remember(content, category) |
Store a durable fact |
search(query) |
FTS5 full-text search with stemming |
vsearch(query) |
Vector similarity search (optional) |
forget(memory_id) |
Soft-delete a memory |
entity(name, type) |
Create or get an entity |
relate(from, rel, to) |
Link two entities |
log(summary, type) |
Log a timestamped event |
decide(title, rationale) |
Record a decision with reasoning |
trigger(condition, keywords, action) |
Set a future reminder |
check_triggers(query) |
Match triggers against text |
handoff(goal, state, loops, next) |
Save session state |
resume() |
Fetch + consume latest handoff |
orient(project) |
One-call session start |
wrap_up(summary) |
One-call session end |
doctor() |
Diagnostic health check |
consolidate() |
Promote important memories |
tier_stats() |
Write-tier distribution |
stats() |
Database overview |
affect(text) |
Classify emotional state |
affect_log(text) |
Classify + store emotional state |
Core Concepts
Memories — Durable facts with categories that control their natural decay rate. Identity lasts a year; integration details fade in a month. Recalled memories get reinforced.
Events — Timestamped logs of what happened. Append-only. Searchable by type and project.
Entities — Typed nodes (person, project, tool, service) with observations. Form a self-building knowledge graph — when a memory mentions a known entity, the link is created automatically.
Decisions — Title + rationale. The "why" record. Prevents future agents from unknowingly contradicting prior choices.
Triggers — Prospective memory. "When X comes up, remind me to do Y." Fire on keyword match during search.
Handoffs — Working state packets for session continuity. Goal, current state, open loops, next step.
What Makes It Different
| Feature | brainctl | mem0 | Zep | MemGPT |
|---|---|---|---|---|
| Single file (SQLite) | yes | - | - | - |
| No server required | yes | yes | - | - |
| No LLM calls | yes | - | yes | - |
| MCP server included | yes | - | - | - |
| Full-text search (FTS5) | yes | - | - | - |
| Vector search | yes | yes | yes | yes |
| Knowledge graph | yes | - | yes | - |
| Self-building graph | yes | - | - | - |
| Confidence decay | yes | - | - | - |
| Duplicate suppression | yes | - | - | - |
| Write gate (surprise scoring) | yes | - | - | - |
| Consolidation engine | yes | - | - | - |
| Prospective memory (triggers) | yes | - | - | - |
| Session handoffs | yes | - | - | - |
| Multi-agent support | yes | - | yes | - |
| Affect tracking | yes | - | - | - |
| Model-agnostic | yes | - | yes | - |
Multi-Agent
Every operation accepts agent_id for attribution. Agents share one brain.db. Search sees everything. The knowledge graph connects insights across agents automatically.
researcher = Brain(agent_id="researcher")
deployer = Brain(agent_id="deployer")
researcher.remember("Auth uses bcrypt cost=12", category="convention")
deployer.search("bcrypt") # finds researcher's memory
Obsidian Integration
Bidirectional sync between brain.db and an Obsidian vault:
pip install brainctl[obsidian]
brainctl obsidian export ~/Documents/MyVault # brain → markdown + wikilinks
brainctl obsidian import ~/Documents/MyVault # new notes → brain (through write gate)
brainctl obsidian watch ~/Documents/MyVault # auto-sync on file changes
brainctl obsidian status ~/Documents/MyVault # drift report
Memory Lifecycle
brainctl manages memories like biological memory:
- Write gate — Surprise scoring rejects redundant writes. Bypass with
force=True. - Three-tier routing — High-value memories get full indexing; low-value get lightweight storage.
- Duplicate suppression — Near-duplicates reinforce existing memories instead of creating new ones.
- Half-life decay — Unused memories fade based on category. Recalled memories get reinforced.
- Hard cap — 10,000 per agent. Emergency compression retires lowest-confidence memories.
- Consolidation — Batch maintenance: Hebbian learning, temporal promotion, compression. Schedule with cron.
Health & Diagnostics
brain.doctor() # table checks, integrity, vec availability, DB size
brainctl stats # database overview
brainctl lint # quality issues (low confidence, duplicates, orphans)
brainctl lint --fix # auto-fix safe issues
brainctl cost # token usage dashboard
Token Cost Optimization
brainctl search "deploy" --output oneline # ~60 tokens (~97% savings vs JSON)
brainctl search "deploy" --budget 500 # hard token cap
brainctl search "deploy" --limit 3 # fewer results
Vector Search (Optional)
Works without embeddings. For semantic similarity:
pip install brainctl[vec]
ollama pull nomic-embed-text # install Ollama first: https://ollama.ai
brainctl embed populate # backfill embeddings
brainctl vsearch "semantic query"
Docker
docker build -t brainctl .
docker run -v ./data:/data brainctl # MCP server
docker run -v ./data:/data brainctl brainctl stats # CLI
Documentation
| Doc | What it covers |
|---|---|
| Agent Onboarding Guide | Step-by-step integration for agents |
| Agent Instructions | Copy-paste blocks for MCP, CLI, Python agents |
| MCP Server Reference | 192 tools with decision tree |
| Architecture | Technical deep-dive |
| Cognitive Protocol | The Orient-Work-Record pattern |
| Examples | Runnable scripts (quickstart, lifecycle, multi-agent) |
| Contributing | Development setup and PR workflow |
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file brainctl-1.1.1.tar.gz.
File metadata
- Download URL: brainctl-1.1.1.tar.gz
- Upload date:
- Size: 530.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
096d2c4f2a956365d23a1da5b3ef7925380be9028481cb94ebb4a0651ce1faf0
|
|
| MD5 |
32411722f547721bc484a9c5517bbe64
|
|
| BLAKE2b-256 |
56c06c925dad6503d6558a73cf879caaed5ad8fc99dc8e07ba0c9d22988d6fad
|
Provenance
The following attestation bundles were made for brainctl-1.1.1.tar.gz:
Publisher:
publish.yml on TSchonleber/brainctl
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
brainctl-1.1.1.tar.gz -
Subject digest:
096d2c4f2a956365d23a1da5b3ef7925380be9028481cb94ebb4a0651ce1faf0 - Sigstore transparency entry: 1274287030
- Sigstore integration time:
-
Permalink:
TSchonleber/brainctl@6d57178f06837c5673deafabd404219ada9aa17a -
Branch / Tag:
refs/tags/v1.1.1 - Owner: https://github.com/TSchonleber
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@6d57178f06837c5673deafabd404219ada9aa17a -
Trigger Event:
push
-
Statement type:
File details
Details for the file brainctl-1.1.1-py3-none-any.whl.
File metadata
- Download URL: brainctl-1.1.1-py3-none-any.whl
- Upload date:
- Size: 459.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
58d27dabcc5631a895b7768148b24e882a7bde77b0a4b9970a8f1734cf0dc8ba
|
|
| MD5 |
df595532249df9c45b100bc8f6afc623
|
|
| BLAKE2b-256 |
09fbe8d0b6dffdb13d0065006090abfe604ac16bd0f73a8da171f38a70bf6904
|
Provenance
The following attestation bundles were made for brainctl-1.1.1-py3-none-any.whl:
Publisher:
publish.yml on TSchonleber/brainctl
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
brainctl-1.1.1-py3-none-any.whl -
Subject digest:
58d27dabcc5631a895b7768148b24e882a7bde77b0a4b9970a8f1734cf0dc8ba - Sigstore transparency entry: 1274287125
- Sigstore integration time:
-
Permalink:
TSchonleber/brainctl@6d57178f06837c5673deafabd404219ada9aa17a -
Branch / Tag:
refs/tags/v1.1.1 - Owner: https://github.com/TSchonleber
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@6d57178f06837c5673deafabd404219ada9aa17a -
Trigger Event:
push
-
Statement type: