by SparkofSpike
Committed to building the world’s most cutting-edge, CJK-first memory module for all mainstream agents. Any issues and PRs are welcome.
# Add to your Claude Code skills
git clone https://github.com/SparkofSpike/Brain4AgentGuides for using ai agents skills like Brain4Agent.
See how Brain4Agent compares with popular alternatives.
Brain4Agent is an open-source ai agents skill for AI coding assistants such as Claude Code, Codex CLI, and ChatGPT, built by SparkofSpike. Committed to building the world’s most cutting-edge, CJK-first memory module for all mainstream agents. Any issues and PRs are welcome. It has 60 GitHub stars.
Brain4Agent's catalog security scan is still queued. You can run an instant dependency and prompt-injection check now with the "Scan for vulnerabilities" button above.
Clone the repository with "git clone https://github.com/SparkofSpike/Brain4Agent" and add it to your Claude Code skills directory (see the Installation section above).
Brain4Agent is primarily written in Python. It is open-source under SparkofSpike on GitHub, so you can review or fork the full source.
Yes. SkillsLLM lists many other AI Agents skills you can browse and compare side by side. Open the AI Agents category from the badge at the top of this page, or use the Related Skills and comparison links further down to weigh Brain4Agent against similar tools.
No comments yet. Be the first to share your thoughts!
Available after the catalog security scan passes.
⚠️ Third-Party Software Notice
This skill is third-party open-source software developed and hosted independently on GitHub. SkillsLLM is an informational directory and does not control or maintain the underlying repository.
Any security checks, ratings, or warnings displayed by SkillsLLM are automated and limited in scope. They do not constitute a security certification or guarantee that the software is safe, error-free, or free from malicious code, vulnerabilities, compromised dependencies, or prompt-injection risks.
Review the source code, permissions, dependencies, and configuration before installing or running any third-party skill. Use is at your own risk. To the maximum extent permitted by applicable law, SkillsLLM is not liable for losses arising from third-party software.
The deep catalog scan for this skill is still queued. Run an instant dependency check now instead.
Long-term memory for agents. CJK-first retrieval, no model in the core path, and evidence instead of confidence scores.
pip install "Brain4Agent[precise]" needs Python 3.11+, plus a 20 MB optional
dictionary. Everything works without it.
An agent working on a codebase accumulates context: why a decision was made, which approach failed, where a deployment lives. Brain4Agent stores those turns in one SQLite file and retrieves them by session.
corpus_missing) and which ones a given session
lacked (missing_terms). The caller decides what that means.Memories also carry tags (scope), superseded_by (replacement) and refs
(one-hop links), supplied by the writer.
pip install "Brain4Agent[precise]" # recommended: adds jieba, hit@1 0.950
pip install Brain4Agent # zero dependencies: bigrams only, hit@1 0.875
Windows and macOS both work; Python 3.11 or newer is required. The package is on
PyPI as https://pypi.org/project/Brain4Agent/. To work on the code itself,
git clone and pip install -e ".[precise,dev]".
jieba is a 20 MB static dictionary. Without it the code falls back to bigrams.
Windows, non-ASCII input. The MCP server and the CLI pin their stdin/stdout
to UTF-8, so CJK content works regardless of the console code page. Command
line arguments are decoded by Python before any of that runs, though — if you
pass non-ASCII text as an argument, set PYTHONUTF8=1.
$ brain4agent exchange \
"中文查询搜不到记忆,recall 返回空" \
"根因在 keywords.py 第 443 行,正则不含汉字范围"
stored exchange in session 913bcac81341
$ brain4agent exchange \
"杭州那台测试机的地址是 203.0.113.42" \
"部署目录 /opt/demo-app,跑的是 PostgreSQL 14"
stored exchange in session c060a5294037
$ brain4agent search "中文查询为什么搜不到" -k 1
1 sessions for '中文查询为什么搜不到'
[ 6.73 cov=1.00] 913bcac81341
--- 913bcac81341 score=6.73 coverage=1.00 ---
user: 中文查询搜不到记忆,recall 返回空
assistant: 根因在 keywords.py 第 443 行,正则不含汉字范围
A question the store cannot answer:
$ brain4agent search "杭州测试机上装的是什么数据库" -k 1
1 sessions for '杭州测试机上装的是什么数据库'
corpus has no: 数据库, 机上
[ 4.81 cov=0.28] c060a5294037 session lacks: 数据库, 机上
Bulk-load an existing history from JSONL (one object per line, content
required):
$ brain4agent import conversations.jsonl
imported 4 turns across 2 sessions
{"session_id": "s1", "role": "user", "content": "中文查询搜不到记忆"}
{"session_id": "s1", "role": "assistant", "content": "根因在 keywords.py 第 443 行"}
{"mcpServers": {"brain4agent": {
"command": "python",
"args": ["-m", "brain4agent.mcp_server"],
"env": {"BRAIN4AGENT_DB": "/path/to/brain.db"}
}}}
Five tools:
| Tool | Purpose |
|---|---|
b4a_remember |
Store one turn; returns a session id |
b4a_recall |
Search; returns sessions with corpus_missing and per-session missing_terms |
b4a_ask |
Retrieve and answer in one step; needs a model, and says so when none is configured |
b4a_session |
Read a whole session in order |
b4a_stats |
Counts |
The same library is also packaged as an agent skill.
from brain4agent import MemoryStore
with MemoryStore("brain.db") as store:
sid = store.new_session()
store.add("杭州那台测试机的地址是 203.0.113.42", session_id=sid, role="user")
store.add("部署目录 /opt/demo-app", session_id=sid, role="assistant")
result = store.search("杭州测试机上装的是什么数据库")
print(result.corpus_missing) # ['数据库', '机上']
print(result.best().coverage) # 0.28
add_exchange(user=..., assistant=...) stores a pair as one session. Retrieval
is session-level, not turn-level.
Bulk imports go through batch(), which defers the commit to one per group:
with store.batch():
for turn in turns:
store.add(turn.text, session_id=turn.sid, role=turn.role)
Off by default. Enabled only when a key is present.
from brain4agent import Judge, MemoryStore
judge = Judge.from_env() # reads BRAIN4AGENT_JUDGE_KEY; None if unset
if judge:
r = store.search_judged("question", judge)
print(r.verdict) # found / not_found / uncertain
uncertain is a third state, distinct from not_found: a judge that times out
is not evidence that the memory does not exist.
write read
│ │
bigrams + dictionary words dictionary words
│ │
▼ ▼
┌──────────────────────────────────────────┐
│ SQLite: id, session, role, content, │
│ created_at, tokens │
└──────────────────────────────────────────┘
│ │
▼ ▼
BM25 index (in memory) → session-level evidence
+ corpus_missing
+ per-session coverage
One SQLite file. Rows are turns; the unit of retrieval is the session. Index tokens are computed at write time and cached in a column, so rebuilding the in-memory index is a counting exercise.
import rebuild query
127 turns 44 sessions 3.9 ms 1.8 ms
1016 turns 352 sessions 0.25 s 29 ms 3.7 ms
Writes commit in batches. A 1,016-turn import takes 3.8 s one commit at a time
and 0.25 s inside batch().
Indexing and querying use different tokenizers. Measured over a 3×3 grid of index strategy against query strategy (D-019), then two changes on top of the best cell (D-037):
| index | query | hit@1 | MRR |
|---|---|---|---|
| bigram | bigram | 0.825 | 0.891 |
| jieba | jieba | 0.875 | 0.911 |
| bigrams + words | words | 0.925 | 0.940 |
| bigrams + words | words − question words | 0.950 | 0.961 |
The last row adds two things the 3×3 grid did not test: interrogatives are removed from the query side, and a session's best three turns are folded into one score. Both are measured in D-037; the first 3×3 grid is D-019.
corpus_missing — a content word from the question appears nowhere in the
stored corpus.missing_terms (per session) — which question words that session lacked.term_frequencies — how many sessions each question word appears in. A
word present in 453 of 2898 memories is neither missing nor misspelt; it is
too common to separate anything, and the query needs another word (D-039).related_terms — up to five words the top sessions use that the query did
not. The third word a two-word query needs, taken from the corpus (D-040).Whether to refuse is the caller's decision; the store reports the fact.
All numbers are reproducible from the bench/ scripts, which import the
shipping code rather than a copy of it.
470 answerable questions over the s variant (average haystack 493 turns):
hit@1 0.8660
hit@5 0.9511
hit@10 0.9660
MRR 0.8990
python -m bench.run_longmemeval --dataset s. bench/data/ is fetched by
bench/fetch_data.py (264 MB, not committed).
These use the harness's bigram/bigram configuration. The store's own configuration (wide index, words minus question words, fuzzy) scored 0.8596 on the same 500 tasks and took 8× longer, so LongMemEval keeps bigrams — measured, not assumed.
Across three benchmarks:
| benchmark | metric | this store | best third-party |
|---|---|---|---|
LongMemEval s |
hit@10 | 0.9660 | — |
| PrecisionMemBench | active | 42/43 | 18/43 (open-knowledge-format) |
| PrecisionMemBench | total | 72/77 | 36/77 (open-knowledge-format) |
| LoCoMo | hit@1 | 0.6310 | not comparable |
77 single-turn cases over 35 beliefs. No generation model and no judge: the
answer is the set of belief IDs the store returns. active is the honest
column, because 33 of the 77 cases pass with an empty store.
active 42/43 = 0.9767 cases that need query-dependent retrieval
total 72/77 = 0.9351 including cases any store passes
Three changes lifted this from 34/43 and 64/77. The result set is now sized from
the names a query contains at every length, and only from beliefs the case's
scope can see — the old rule forced top_k=1 below eight words and counted
out-of-scope beliefs. Whole-word name matching replaced substring matching, so
pipe no longer matches inside pipeline. A fuzzy query path then matches a
mis