Context engineering for AI agents — persistent memory, knowledge graph, affect tracking, and MCP server. Single SQLite file, zero LLM cost.
Project description
brainctl
Forgetful agents, fixed by a SQLite file.
One brain.db gives your agent durable memory across sessions — facts learned, decisions made, entities tracked, and state handed off. No server. No API keys. No LLM calls required.
from agentmemory import Brain
brain = Brain(agent_id="my-agent")
ctx = brain.orient(project="api-v2") # session start: handoff + events + triggers + memories
brain.remember("rate-limit: 100/15s", category="integration")
brain.decide("use Retry-After for backoff", "server controls timing", project="api-v2")
brain.wrap_up("auth module complete", project="api-v2") # session end: logs + handoff for next run
Install
pip install brainctl
Requires Python 3.11+. SQLite is built-in. No other mandatory dependencies.
pip install brainctl[mcp] # MCP server — 201 tools for Claude Desktop, Cursor, VS Code
pip install brainctl[vec] # vector similarity search (sqlite-vec + Ollama)
pip install brainctl[signing] # Ed25519-signed memory exports + optional Solana on-chain pinning
pip install brainctl[all] # everything
5-line example
from agentmemory import Brain
brain = Brain(agent_id="research-bot")
brain.remember("OpenAI rate-limits at 500k TPM on tier 3", category="integration")
results = brain.search("rate limit") # FTS5 full-text, stemming, ranked
brain.entity("OpenAI", "service", observations=["500k TPM tier 3", "REST API"])
brain.relate("OpenAI", "provides", "GPT-4o")
Feature checklist
Memory types
convention,decision,environment,identity,integration,lesson,preference,project,user- Category controls natural half-life: identity decays over ~1 year; integration details over ~1 month
- Hard cap: 10,000 memories per agent. Emergency compression retires lowest-confidence entries.
Retrieval modes
- FTS5 full-text search with stemming (default, zero dependencies)
- Vector similarity via sqlite-vec + Ollama nomic-embed-text (
brainctl[vec]) - Hybrid: Reciprocal Rank Fusion over FTS5 + vector results
- Context profiles: named search presets scoped to task type (
--profile ops,--profile research, etc.) --benchmarkpreset: flattens recency/salience for synthetic evaluation runs
Reranker chain
- Intent classifier (regex, 10 labels → 6 profiles) routes queries at
cmd_search - Post-FTS reranking by recency, salience, Q-value utility, and Bayesian recall confidence
- Cold-start: auto-detects available reranker backends (cross-encoder > sentence-transformers > fallback)
- Retrieval regression-gated in CI: >2% drop on P@1/P@5/MRR/nDCG@5 fails the build
Knowledge graph
- Typed entity nodes:
agent,concept,document,event,location,organization,person,project,service,tool - Auto entity linking: memories mentioning a known entity create the edge automatically
- Compiled truth synthesis per entity (
brainctl entity compile <name>) - 3-level enrichment tier; canonical alias dedup (
brainctl entity alias add) - Spreading-activation recall across the graph (
brain.think(query))
Belief revision (AGM)
- Belief set per agent with confidence weights
- Conflict detection and resolution via
brainctl belief conflictsandbrainctl belief merge - Collapse mechanics: decoherent beliefs quarantined, recovery candidates surfaced
- PII recency gate (Proactive Interference Index) on supersedes operations
Signed exports
brainctl export --signproduces a portable Ed25519-signed JSON bundlebrainctl verify <bundle.json>checks the signature offline — no brainctl required for verification- Optional:
--pin-onchainwrites the SHA-256 hash as a Solana memo transaction (~$0.001 per pin) - Managed wallet:
brainctl wallet newcreates a local keypair at~/.brainctl/wallet.jsonfor users without an existing Solana setup - Memories never leave the machine; only the hash goes on-chain (opt-in)
Plugins (16 first-party)
Agent frameworks:
| Plugin | Target |
|---|---|
plugins/claude-code/ |
Claude Code |
plugins/codex/ |
OpenAI Codex CLI |
plugins/cursor/ |
Cursor |
plugins/gemini-cli/ |
Gemini CLI |
plugins/eliza/ |
Eliza (TypeScript) |
plugins/hermes/ |
Hermes Agent |
plugins/openclaw/ |
OpenClaw |
plugins/rig/ |
Rig |
plugins/virtuals-game/ |
Virtuals Game |
plugins/zerebro/ |
Zerebro |
Trading bots:
| Plugin | Target |
|---|---|
plugins/freqtrade/ |
Freqtrade |
plugins/jesse/ |
Jesse |
plugins/hummingbird/ |
Hummingbird |
plugins/nautilustrader/ |
NautilusTrader |
plugins/octobot/ |
OctoBot |
plugins/coinbase-agentkit/ |
Coinbase AgentKit |
MCP server (201 tools)
{
"mcpServers": {
"brainctl": {
"command": "brainctl-mcp"
}
}
}
Add to ~/.claude/claude_desktop_config.json, ~/.cursor/mcp.json, or equivalent. Full tool list and a decision tree: MCP_SERVER.md.
CLI reference
brainctl memory add "content" -c convention # store a memory
brainctl search "query" # FTS5 search
brainctl vsearch "semantic query" # vector search (requires [vec])
brainctl entity create "Alice" -t person # create entity
brainctl entity relate Alice works_at Acme # link entities
brainctl event add "deployed v3" -t result # log an event
brainctl decide "title" -r "rationale" # record a decision
brainctl export --sign -o bundle.json # signed export
brainctl verify bundle.json # verify a bundle
brainctl wallet new # create managed signing wallet
brainctl stats # DB overview
brainctl doctor # health check
brainctl lint # quality issues
brainctl gaps scan # coverage + orphan + broken-edge scans
brainctl consolidate cycle # full consolidation pass
Python API (22 methods)
| Method | What it does |
|---|---|
orient(project) |
One-call session start: handoff + events + triggers + memories |
wrap_up(summary) |
One-call session end: logs event + creates handoff |
remember(content, category) |
Store a durable fact through the W(m) write gate |
search(query) |
FTS5 full-text search with stemming |
vsearch(query) |
Vector similarity search (optional) |
think(query) |
Spreading-activation recall across the knowledge graph |
forget(memory_id) |
Soft-delete a memory |
entity(name, type) |
Create or retrieve 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 prospective reminder |
check_triggers(query) |
Match triggers against text |
handoff(goal, state, loops, next) |
Save session state explicitly |
resume() |
Fetch and consume latest handoff |
doctor() |
Diagnostic health check |
consolidate() |
Promote high-importance memories |
tier_stats() |
Write-tier distribution |
stats() |
Database overview |
affect(text) |
Classify emotional state |
affect_log(text) |
Classify and store emotional state |
close() |
Close the shared SQLite connection |
Memory lifecycle
- Write gate (W(m)): 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 rows.
- Half-life decay: unused memories fade at a rate set by category. Recalled memories are reinforced.
- Consolidation: Hebbian learning, temporal promotion, compression — runs on a cron schedule.
Retrieval benchmarks
Tested with default settings, no tuning for benchmark data. Backend: Brain.search.
LongMemEval (289 questions, 4 categories):
| metric | overall | single-session-assistant | single-session-user | multi-session |
|---|---|---|---|---|
| hit@1 | 0.882 | 1.000 | 0.900 | 0.910 |
| hit@5 | 0.976 | 1.000 | 1.000 | 0.985 |
| MRR | 0.924 | 1.000 | 0.935 | 0.944 |
LOCOMO (1,982 questions, 5 categories, 10 conversations):
| metric | overall | adversarial | temporal | open-domain | single-hop | multi-hop |
|---|---|---|---|---|---|---|
| hit@1 | 0.341 | 0.377 | 0.405 | 0.373 | 0.167 | 0.174 |
| hit@5 | 0.572 | 0.603 | 0.648 | 0.602 | 0.429 | 0.315 |
| MRR | 0.445 | 0.479 | 0.510 | 0.479 | 0.282 | 0.232 |
LOCOMO single-hop and multi-hop hit@1 are weak (0.167 / 0.174). Root cause: recency and salience rerankers bias toward recent memories; LOCOMO uses uniform synthetic timestamps with gold evidence concentrated in early sessions, so the rerankers fight FTS ranking. A --benchmark preset that flattens recency/salience is available for evaluation runs. See tests/bench/ for the full harness.
Upgrading
cp $BRAIN_DB $BRAIN_DB.pre-upgrade
brainctl doctor # diagnose migration state
brainctl migrate # apply pending migrations
For databases predating the migration tracker, see the full recovery workflow in the README's Upgrading section (below the install block in the full docs).
Multi-agent
researcher = Brain(agent_id="researcher")
writer = Brain(agent_id="writer")
researcher.remember("API uses OAuth 2.0 PKCE", category="integration")
writer.search("OAuth") # finds researcher's memory — same brain.db, shared graph
Every operation accepts agent_id for attribution. Agents share one brain.db. The knowledge graph connects insights across agents automatically.
Documentation
| Doc | What it covers |
|---|---|
| docs/QUICKSTART.md | 60-second onboarding — install, remember, search, sign |
| docs/COMPARISON.md | Feature matrix vs Mem0, Letta, Zep, Cognee, OpenAI Memory |
| docs/AGENT_ONBOARDING.md | Step-by-step agent integration guide |
| docs/AGENT_INSTRUCTIONS.md | Copy-paste blocks for MCP, CLI, Python agents |
| docs/SIGNED_EXPORTS.md | Bundle format, threat model, verify-without-brainctl recipe |
| MCP_SERVER.md | 201 tools with decision tree |
| ARCHITECTURE.md | Technical deep-dive |
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-2.4.0.tar.gz.
File metadata
- Download URL: brainctl-2.4.0.tar.gz
- Upload date:
- Size: 762.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 |
9c193d35cdc2e2abe24ea2507b03c839b98776462e15d9690e207b5e6cd583d7
|
|
| MD5 |
53564e274df4d57f83462658d1892b90
|
|
| BLAKE2b-256 |
b10f5fd4123143c0c9458c7fd030b886e38b70ea550b8f14a86684fb29dd5f55
|
Provenance
The following attestation bundles were made for brainctl-2.4.0.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-2.4.0.tar.gz -
Subject digest:
9c193d35cdc2e2abe24ea2507b03c839b98776462e15d9690e207b5e6cd583d7 - Sigstore transparency entry: 1337909810
- Sigstore integration time:
-
Permalink:
TSchonleber/brainctl@21f224a9e069911f2f74e7b1c01bb37d230e7d61 -
Branch / Tag:
refs/tags/v2.4.0 - Owner: https://github.com/TSchonleber
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@21f224a9e069911f2f74e7b1c01bb37d230e7d61 -
Trigger Event:
push
-
Statement type:
File details
Details for the file brainctl-2.4.0-py3-none-any.whl.
File metadata
- Download URL: brainctl-2.4.0-py3-none-any.whl
- Upload date:
- Size: 572.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 |
b4563d951c5c88686861800cbc8711feae5ef3d35620c72ecc63b792fd781bf0
|
|
| MD5 |
9e14613974c6418de60c2e81424b8c09
|
|
| BLAKE2b-256 |
ed9e742a495ba74bdc13f5b77bf5cd1b5c6d0944679130653fba0a4650230570
|
Provenance
The following attestation bundles were made for brainctl-2.4.0-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-2.4.0-py3-none-any.whl -
Subject digest:
b4563d951c5c88686861800cbc8711feae5ef3d35620c72ecc63b792fd781bf0 - Sigstore transparency entry: 1337909903
- Sigstore integration time:
-
Permalink:
TSchonleber/brainctl@21f224a9e069911f2f74e7b1c01bb37d230e7d61 -
Branch / Tag:
refs/tags/v2.4.0 - Owner: https://github.com/TSchonleber
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@21f224a9e069911f2f74e7b1c01bb37d230e7d61 -
Trigger Event:
push
-
Statement type: