1. Executive Summary
ai-knot is a self-hosted memory library for agents in Python, with an
MCP server, an HTTP sidecar, a CLI, framework adapters and a TypeScript
client. A fact is a line of text, optionally addressed as an
entity-attribute slot, kept in SQLite, PostgreSQL or YAML under one
agent's namespace. Recall is lexical fusion with an optional embedding
channel, and no model runs on the default read or write path;
learn is the opt-in exception that calls a provider.
Notable: validity is anchored on the time a fact held. Given an event time, a fact is valid from it, and a supersession closes the old value at the successor's event time, so recall at a past point returns the value of that point. Derived facts carry their sources' revision digests and leave every read when one changes. An opt-in always-on package adds a freshness verdict that withholds a fact from task context and blocks an action until it is confirmed.
Weak: forget deletes the row and leaves its copies in
every snapshot, which restore reinstates. add
never supersedes, so two values for one slot stay active unless the
caller uses add_resolved. The freshness gate covers the
always-on reads only, and each recall rewrites the agent's
namespace.
Four marks are present and three are withheld (section 9).
Licence. MIT in LICENSE (copyright 2026
ai-knot contributors), in agreement with pyproject.toml and
npm/package.json; no rider.
.github/SECURITY.md asks for vulnerabilities to go by email
or a private GitHub advisory, not a public issue.
2. Mental Model
A fact is one stored row in one agent's namespace. Whether it is
believed at a given moment is decided on read by its interval: active
when valid_from is at or before the query time and
valid_until is empty or after it
(src/ai_knot/types.py:180-189). Recall takes an optional
point in time, so the same store answers what held last year.
The interval is anchored on the world, not on the store, when the
caller says when something happened. _apply_temporal sets
valid_from to the supplied event time and resolves relative
phrases against it (src/ai_knot/knowledge.py:69-89). When a
slot gets a different value through add_resolved or
learn, _supersede_close ends the old fact at
the new fact's event time, falling back to the ingest time when there is
none or when it would invert the interval
(src/ai_knot/learning.py:39-54, :367-379).
created_at stays the record time throughout.
A fact can also stop being usable without changing. A derived fact
stores the revision digests of the facts it came from, and every read
recomputes them (src/ai_knot/always_on/lineage.py:135-191).
In the always-on package a freshness policy adds a host's verdict on the
fact against its outside source.
Diagram source
%% caption: validity follows the caller's event time, supersession closes the old slot value at the successor's event time, and reads filter on the interval, the supported flag, derivation sources and, for always-on work, a freshness verdict
flowchart TD
W["add, add_resolved,<br/>learn"] --> ET{"event_time<br/>supplied?"}
ET -- "yes" --> VF["valid_from =<br/>event time"]
ET -- "no" --> VN["valid_from =<br/>ingest time"]
VF --> SL{"same slot,<br/>other value?"}
VN --> SL
SL -- "yes, via add_resolved<br/>or learn" --> CL["old valid_until =<br/>successor event time"]
SL -- "no" --> ROW["fact row<br/>in agent namespace"]
CL --> ROW
ROW --> RC["recall at a<br/>point in time"]
RC --> F1{"active then,<br/>not episodic,<br/>supported?"}
F1 -- "no" --> OUT["not returned"]
F1 -- "yes" --> F2{"derived: source<br/>revisions current?"}
F2 -- "no" --> OUT
F2 -- "yes" --> RANK["BM25F + dense,<br/>RRF, MMR"]
ROW --> AO["always-on context<br/>or action begin"]
AO --> F3{"freshness verdict<br/>confirmed, in date?"}
F3 -- "no" --> BLK["withheld,<br/>action blocked"]
F3 -- "yes" --> USE["admitted"]3. Architecture
src/ai_knot/knowledge.py holds
KnowledgeBase: add, recall, list, get, lineage, forget,
decay, snapshots. learning.py holds learn,
add_resolved and the slot resolver;
_resolve.py the similarity and slot matching;
retriever.py, _bm25.py and
_inverted_index.py the rankers. pool.py and
_pool_recall.py hold SharedMemoryPool, a
reserved __shared__ namespace that agents publish into and
recall from, with the multi_agent/ package doing
facet-aware recall over it.
Storage is a protocol with three backends. SQLite and PostgreSQL keep
every agent in one facts table keyed on (agent_id, id)
(src/ai_knot/storage/sqlite_storage.py:29-67); YAML keeps a
file per agent directory. save is a full replace by design:
the SQL backends load the namespace, run the change under a write
transaction, delete the agent's rows and insert the result
(src/ai_knot/storage/sqlite_storage.py:284-305,
src/ai_knot/storage/base.py:229-245).
always_on/ is opt-in and SQL-only: intents with fenced
leases, actions with permits and reconciliation, lessons bound to action
outcomes, freshness policies, a change stream with subscriptions,
workspaces and budgeted maintenance
(src/ai_knot/always_on/storage.py:142-182,
src/ai_knot/always_on/state_storage.py:30-74).
Deployment and ergonomics
pip install ai-knot gives the library and the CLI;
extras add MCP, PostgreSQL, the HTTP server and each framework adapter.
ai-knot setup claude and
ai-knot setup openclaw write the MCP client configuration
(src/ai_knot/cli.py:1023-1146). The MCP server reads its
agent id, backend and provider from AI_KNOT_* variables,
defaulting to SQLite and agent default
(src/ai_knot/config.py:98-154);
AI_KNOT_ALWAYS_ON adds the durable tools and refuses YAML.
ai-knot serve binds loopback and takes an optional bearer
token from AI_KNOT_SERVER_TOKEN
(src/ai_knot/cli.py:1148-1184). The dense channel calls an
Ollama-compatible endpoint at localhost:11434 by default
and falls back to lexical recall, warning once, when it is unreachable
(src/ai_knot/knowledge.py:509-524).
4. Essential Implementation Paths
- Add.
addbuilds the fact, applies the event time, splits enumerations into child facts, and appends unless a Jaccard score of 0.7 or more matches one of the agent's last five facts (src/ai_knot/knowledge.py:240-318). - Add resolved.
add_resolvedderives a slot key from entity and attribute and runs the resolver: same value reinforces, a different value supersedes,op=deletecloses the slot,op=noopskips (src/ai_knot/learning.py:172-213,:292-416). - Learn.
learnextracts candidates with a configured provider, keeps those its token-overlap check marks supported, stamps the conversation's event time, and commits through the same resolver (src/ai_knot/learning.py:78-171,src/ai_knot/extractor.py:231-261). - Recall.
_execute_recallclassifies the query's intent, loads the agent's rows, filters, decays, collects four candidate channels, fuses six or seven ranked signals and selects by MMR, then records access (src/ai_knot/knowledge.py:643-979). - Forget.
forgetremoves the row and re-runs aggregate consolidation inside one transaction (src/ai_knot/knowledge.py:1434-1458). - Lineage.
lineagewalkssupersedes_idfrom a fact back through its predecessors (src/ai_knot/knowledge.py:1269-1293). - Publish and pool recall.
publishcopies facts into__shared__under slot compare-and-swap; pool recall filters by visibility, lineage and trust (src/ai_knot/pool.py:381-444,src/ai_knot/_pool_recall.py:158-216). - Guard an action.
begin_actionvalidates the intent's and the action's basis, freshness included, and blocks the intent on any issue (src/ai_knot/always_on/memory.py:975-1025).
5. Memory Data Model
facts(SQLite) or"ai-knot_facts"(PostgreSQL): content, type, importance, retention, access count and intervals, tags,created_at,last_accessed, source snippets and spans,supported,support_confidence,verification_source, origin agent, visibility, verbatim source,valid_from,valid_until, entity, attribute, version, MESI state, three text surfaces, slot key, value, JSON qualifiers, state confidence, topic channel,visibility_scope, claim key, memory tier andevent_time(src/ai_knot/storage/sqlite_storage.py:29-67).snapshots: a named JSON copy of an agent's facts.pool_stats,acl_grants,trust_events,usage_events: pool counters, read grants per agent and scope, and two append-only ledgers of trust changes and of which recall surfaced which fact (src/ai_knot/storage/sqlite_storage.py:88-122).- Always-on:
ao_streamsandao_changes(a per-namespace change sequence holding before and after revision digests, not content),ao_subscriptions,ao_intents,ao_actions,ao_experiences,ao_freshness, maintenance runs and workspace tables (src/ai_knot/always_on/storage.py:142-182,src/ai_knot/always_on/state_storage.py:30-74).
Provenance lives in qualifiers: supersedes_id,
published_by, and for derived facts the encoded roots and
dependencies, each a namespace, a fact id and a SHA-256 over 26 evidence
fields (src/ai_knot/always_on/changes.py:14-67,
src/ai_knot/always_on/lineage.py:118-132). The
Fact docstring calls the validity model mono-temporal
(src/ai_knot/types.py:114); the code beside it keeps an
event-anchored interval apart from created_at.
6. Retrieval Mechanics
Recall loads the agent's rows and keeps those active at the query
time, not episodic, and not supported=False, then drops
derived facts whose sources changed
(src/ai_knot/knowledge.py:686-701). Retention is recomputed
by a power-law curve per type, with procedural facts immune
(src/ai_knot/forgetting.py:128-155); it is a ranking signal
and removes nothing.
Candidates come from four channels: every fact with a positive BM25F
score, every fact holding a rarer-than-median query token, facts whose
entity matches a candidate's value, and dense cosine matches when
embeddings are available
(src/ai_knot/knowledge.py:721-772). The rankers — BM25F,
slot match, trigram Jaccard, importance, retention, recency and the
dense score — are fused by reciprocal rank with weights chosen by the
query's intent class, then diversified by MMR
(src/ai_knot/knowledge.py:792-874). Embeddings are held in
process memory keyed on fact id, so a fresh process re-embeds the
namespace on its first recall
(src/ai_knot/retriever.py:47-72).
recall renders each fact with its slot and any resolved
event date. The pool path adds a trust discount per publishing agent and
an abstention signal when coverage is low or no returned fact carries
evidence (src/ai_knot/_pool_recall.py:71-89).
The repository publishes LoCoMo and LongMemEval QA accuracy in
docs/benchmarks.md, naming reader and judge, and a
deterministic retrieval suite runnable without a model.
7. Write Mechanics
Writes block the caller and are retrievable on return: each one loads
the namespace and replaces it in one transaction
(src/ai_knot/storage/base.py:229-245). Recall is a write
too: _record_access updates access counts and intervals for
the returned facts by the same full replace
(src/ai_knot/knowledge.py:978-991). No background pass
rewrites the store.
add deduplicates; it does not
supersede. It compares the new text only against the last five
facts and sets no slot key, so "lives in Paris" and a later "lives in
Berlin" are both active (src/ai_knot/knowledge.py:294-318).
The slot resolver runs for add_resolved, learn
and pool publish. For a fact with no slot, the resolver closes an active
fact whose text is similar above the conflict threshold by combined
Jaccard and containment (src/ai_knot/_resolve.py:90-147,
src/ai_knot/learning.py:410-416).
learn is the one model call: a provider extracts facts
with an operation label, _verify_facts_atc sets
supported from token overlap with the source text at
threshold 0.6, and unsupported candidates are dropped before commit
(src/ai_knot/extractor.py:231-261,
src/ai_knot/learning.py:158-160). With no provider, the MCP
and HTTP learn store the last user message verbatim
(src/ai_knot/_mcp_tools.py:490-512).
Operational cost
Every add, recall and forget reads and rewrites the agent's whole namespace, so the cost grows linearly with it. Recall also builds an inverted index over the candidate facts per call. The dense channel costs one embedding call per unseen fact per process and one per query.
8. Agent Integration
The MCP server registers 19 tools: add, add_resolved, recall, search,
get, forget, delete, list, list_facts, memory_lineage, stats, snapshot,
restore, recall_json, learn, recall_with_trace, list_snapshots, health
and capabilities (src/ai_knot/mcp_server.py:154-365). With
AI_KNOT_ALWAYS_ON, 26 durable tools are added through one
typed decoder: intent, action, subscription, context, freshness and
maintenance verbs (src/ai_knot/_always_on_tools.py:12-39).
Each process serves one agent id from its environment.
The HTTP sidecar exposes the same verbs under /v1/ and a
read-only /inspect page
(src/ai_knot/server/app.py:582-746). Framework adapters
wrap KnowledgeBase for CrewAI, LangChain and LangGraph,
LlamaIndex, AutoGen, the OpenAI Agents SDK and PydanticAI, and OpenClaw
gets a setup command (src/ai_knot/integrations/,
src/ai_knot/cli.py:1088-1146). The npm package runs the
Python engine underneath, as its README says, and carries an HTTP
client.
9. Reliability, Safety, and Trust
Validity is on the world's clock
test_supersession_closes_at_successor_event_time stores
Paris at 2020 and Berlin at 2023 and requires Paris to close at 2023;
the next test asks at 2021 and 2024 and requires each answer to exclude
the other (tests/test_temporal_validity.py:100-127). An
out-of-order successor falls back to ingest time instead of inverting
the interval (:133-166). A pool copy is stamped valid from
its publish time and closed at the time of the next publish
(src/ai_knot/pool.py:525, :562), so the shared
pool answers by record time only.
Derivations follow their sources
lineage_status re-reads every root and dependency of a
derived fact and reports it not current if a source is missing, changed,
or a generated fact without roots of its own, and unreadable if a source
is out of the reader's sight; filter_current_lineage
applies this to private recall, pool recall and tag recall alike
(src/ai_knot/always_on/lineage.py:135-191,
src/ai_knot/knowledge.py:1413-1423). A test derives a fact,
revokes the source's scope or deletes the source, and requires the
derived fact gone from the reader's recall
(tests/always_on/test_grounded_context_integration.py:16-90).
The freshness verdict
set_freshness binds a fact or slot to an outside source
and a recheck interval. freshness_blocks is true until a
confirmed verdict with evidence arrives, after
verified_until passes, and once a verdict is
changed
(src/ai_knot/always_on/_state.py:88-95,
:482-530). validate_basis turns that into
verification_due, and task snapshots, context review,
semantic context and begin_action exclude or refuse on it
(src/ai_knot/always_on/context.py:50-67,
:225-230). Ordinary recall, search, MCP recall
and pool recall do not read ao_freshness.
Deletion
forget removes the row
(src/ai_knot/knowledge.py:1434-1458). Snapshots are
separate copies; no code path deletes a snapshot, and
restore, an MCP tool, replaces the namespace with one
(src/ai_knot/knowledge.py:1510-1524). The pool's
compare-and-swap refuses a replayed fact id that a peer superseded, so
an agent cannot re-claim a slot by re-sending its old fact; a fresh fact
with the same value passes
(src/ai_knot/pool.py:551-560).
Marks
trust_state— present. A stored freshness verdict gates always-on context and actions, andsupported=False, written when a lesson's action is revised, leaves every recall path (src/ai_knot/always_on/experience.py:72-86). The ordinary read paths ignore freshness, and the agent can record its own verdicts.bitemporal— present. Event-anchored validity apart fromcreated_at, set by the MCP and HTTP add paths and the CLI'sadd-resolved, closed at the successor's event time and queried by point-in-time recall.scope_enforced— present. Anagent_idpredicate on every SQL read and a visibility-and-grant filter in the pool; the agent id is configuration, not an authenticated identity.audit_log— withheld.ao_changesrecords every insert, update and delete with before and after digests, but it is a delivery stream: maintenance andprune_changesdelete rows up to the slowest subscriber's cursor (src/ai_knot/always_on/maintenance.py:526-602,src/ai_knot/always_on/subscriptions.py:426-459).trust_eventsandusage_eventsare append-only and record trust deltas and retrievals, not memory mutations.human_review— withheld. No fact waits on a person; verification verdicts arrive throughmemory_freshness_record, a tool the agent holds.negative_eval— present. Populated exclusions for another agent, a closed value, an ungranted scope and a revoked derivation.tombstone— withheld.forgetleaves no record of the value, and the pool's replay refusal is keyed on a fact id, not a value.
10. Tests, Evals, and Benchmarks
The suite is 1,783 pytest functions in 158 files. An autouse fixture
replaces the embedding call with an MD5-derived vector, so dense ranking
runs offline (tests/conftest.py:17-60). CI runs the suite
without slow tests on Python 3.11, 3.12 and 3.13, again against
PostgreSQL 16 with AI_KNOT_REQUIRE_POSTGRES so the backend
tests cannot skip, an MCP end-to-end job, an always-on process-recovery
acceptance on both SQL backends, an MRR smoke gate, and the 64 vitest
cases of the TypeScript client (.github/workflows/ci.yml).
I ran none of them.
The negative cases worth reading are the temporal pair above, the
visibility scope tests
(tests/test_shared_pool.py:1122-1169), and the
grounded-context case, which checks a positive recall before the
revocation and an exact remaining set after it.
docs/benchmarks.md reports LoCoMo at 78.0% (1,201 of
1,540, categories 1 to 4, reader gpt-4.1, judge gpt-4o) and LongMemEval
Oracle at 59.6%. The per-run outputs behind those figures are not in the
tree; the deterministic suite that backs the retrieval numbers is
(tests/eval/benchmark/). docs/performance/
holds JSON results from the always-on and multi-agent studies.
Cases to want first: an add of a changed value followed
by a recall that expects one answer; a forget followed by
restore of a prior snapshot; and ordinary recall of a fact
whose freshness verdict is changed.
No paper describes ai-knot; the research notes under
docs/research/ and
docs/multi-agent-governance.md cite related work.
11. For Your Own Build
Steal
- Close at the successor's event time.
_supersede_closeis sixteen lines, and it is the difference between a knowledge update and an as-of query that answers correctly. - Store the sources' revision digests on a derived fact. One SHA-256 over the evidence fields of each source, checked on read, removes a stale summary from every path without a background job.
- Bind a lesson to an action revision. Revising the action withdraws the lesson in the same transaction.
- Refuse replayed ids in a shared slot. A cheap guard against an agent undoing a peer's correction by re-sending its old fact.
Avoid
- Do not let snapshots outlive deletion. A forget
that leaves copies in every named snapshot, behind an agent-reachable
restore, is not a forget. - Do not ship two add verbs with different correction
semantics unless the difference is in their names;
addappends a contradiction thatadd_resolvedwould have superseded. - Do not make recall a full-namespace write. Access statistics written by replacing every row couple read latency to store size.
Fit
Fits a single developer or a small team that wants an embeddable, inspectable memory with as-of queries over SQLite or PostgreSQL and no model in the loop. The always-on package suits a host that schedules agent work itself and wants evidence checks before external actions.
Walk away if deletion must be complete, if callers must be authenticated per agent on one server, or if the store will grow large enough that a linear rewrite per recall matters.
12. Open Questions
- Whether
addis meant to supersede by slot when the caller passes an entity and attribute, asadd_resolveddoes. - Whether
forgetis meant to reach snapshots and export files. - Whether ordinary recall is meant to consult freshness verdicts where a policy exists.
- Why a pool publish resets
valid_fromto the publish time instead of carrying the fact's event time.
Appendix: File Index
- Core:
src/ai_knot/knowledge.py,src/ai_knot/learning.py,src/ai_knot/_resolve.py,src/ai_knot/types.py,src/ai_knot/forgetting.py - Retrieval:
src/ai_knot/retriever.py,src/ai_knot/_bm25.py,src/ai_knot/_inverted_index.py,src/ai_knot/_query_intent.py - Extraction:
src/ai_knot/extractor.py,src/ai_knot/providers/ - Storage:
src/ai_knot/storage/sqlite_storage.py,src/ai_knot/storage/postgres_storage.py,src/ai_knot/storage/yaml_storage.py,src/ai_knot/storage/base.py - Shared pool:
src/ai_knot/pool.py,src/ai_knot/_pool_recall.py,src/ai_knot/multi_agent/ - Always-on:
src/ai_knot/always_on/memory.py,_state.py,context.py,lineage.py,changes.py,experience.py,maintenance.py,subscriptions.py,storage.py,state_storage.py - Surfaces:
src/ai_knot/mcp_server.py,src/ai_knot/_mcp_tools.py,src/ai_knot/_always_on_tools.py,src/ai_knot/server/app.py,src/ai_knot/cli.py,src/ai_knot/integrations/,npm/src/ - Tests:
tests/test_temporal_validity.py,tests/test_integration.py,tests/test_shared_pool.py,tests/always_on/,tests/eval/
Recorded searches
Run from the repository root at the pinned commit with
/usr/bin/git grep.
- No review verb.
git grep -n -i -E 'approv|quarantin|pending_review' -- srcreturns nothing;git grep -n -i -E 'approv|quarantin|supersed' -- src/ai_knot/_resolve.pyreturns hits at:202and:217, so the pattern can match. - Nothing deletes a snapshot.
git grep -n -E 'delete_snapshot\(' -- srcreturns the four definitions instorage/base.py,postgres_storage.py,sqlite_storage.pyandyaml_storage.py, and no caller. - No value-keyed tombstone.
git grep -n -i -E 'tombstone|blocklist|denylist' -- srcreturns one docstring,src/ai_knot/pool.py:771, describing invalidations sent to peers on sync. - The change stream is pruned.
git grep -n -F 'DELETE FROM ao_changes' -- srcreturnssrc/ai_knot/always_on/maintenance.py:595andsrc/ai_knot/always_on/subscriptions.py:450. - Ordinary recall ignores freshness.
git grep -n -E 'validate_basis|ao_freshness|_policy\(' -- src/ai_knot/knowledge.py src/ai_knot/_pool_recall.py src/ai_knot/_mcp_tools.pyreturns nothing; the same pattern returns hits insrc/ai_knot/always_on/memory.py. - Episodic consolidation has no caller.
git grep -n -F 'consolidate_episodic(' -- srcreturns its definition atsrc/ai_knot/learning.py:793, a log message at:823and a docstring atsrc/ai_knot/knowledge.py:399. - No QA run outputs.
git ls-files | grep -i -E 'locomo|longmem'returnstests/eval/benchmark/scenarios/s_locomo.pyandtests/eval/test_locomo_helpers.py. - No paper.
CITATION.cffis absent;git grep -n -i -E 'arxiv|doi\.org|bibtex' -- .returns related-work citations indocs/research/,docs/multi-agent-governance.md,docs/superpowers/specs/,tests/eval/benchmark/BENCHMARK.mdand one docstring insrc/ai_knot/_pool_recall.py. - No project rename.
git grep -n -i 'renam' -- CHANGELOG.mdreturns one line,:398, on a variable renamed toaccess_time.
History
2026-12-04 — 544856ed….
First reading, from the 2026-12-04 triage shortlist, at the head of
main. Screened: two auto-run surfaces
(.devcontainer/devcontainer.json and
server.json), none inside the cooldown, three build-time
execution points (the npm postinstall and two pytest
conftest.py files) and two unpinned surfaces; repository
text read as data. Nothing was installed, built or run, and none of the
1,783 test functions was run. Four marks (section 9).