TL;DR. Mnemosyne is a TypeScript transpiler that records where every value in a program came from — a provenance graph over plain computation, package calls, and AI calls — and lets you query that graph through an MCP server with 16 tools. In the demo system built on top of it, a cost optimizer driven by the provenance graph cut the cost of a full execution from $6400 to $5248 (−18%), and the graph behind that run contains 188 nodes, every one of them answerable with the same question: where did you come from?
- Code: github.com/andrey-karasev-gmail/mnemosyne (MIT)
- Package:
@web4w3/mnemosyneon npm, current release 0.2.1 - Demo system:
mnemosyne-demo(Next.js dashboard, REST and GraphQL APIs, Prisma + SQLite)
The explanation gap
Modern server code rarely computes a number in one place. A premium, a score, a price — the final value is a braid of arithmetic, configuration, third-party package calls, and, increasingly, LLM calls. When the number looks wrong, logs tell you which path executed. They do not tell you the ancestry of the value: which inputs, in which proportions, produced exactly this result.
So debugging becomes archaeology. You re-read code, guess which factor moved, add print statements, and rerun — hoping the bug reproduces and that your guess about "what could have happened" matches what actually happened.
Mnemosyne takes the other side of that trade. Instead of reconstructing the past from logs, it records it as it happens.
What Mnemosyne does
Mnemosyne is a Babel-plugin transpiler for TypeScript/JavaScript. It instruments your program so that, at runtime, every meaningful value is recorded on a "tape" as a node in a directed acyclic graph: the value itself, the operation that produced it, and the nodes its inputs came from. Package calls become package-boundary nodes. AI calls become first-class nodes that keep the prompt, the returned value, and usage metadata.
Two properties make this usable rather than decorative:
Observation without interference. An instrumented program must produce exactly the output of the plain program, or the graph is fiction. Trace equivalence is checked explicitly — on the bundled examples the outputs are identical, with 47 and 51 provenance nodes recorded:

Trace equivalence: the instrumented program's output is identical to the plain run — provenance is observation, not interference.
The graph is queryable, not just viewable. The recorded graph is exposed through an MCP server, so an AI assistant (or a script) can ask questions about an execution in the same protocol it uses for everything else:

Sixteen MCP tools over the provenance graph: query_causality, findAIInfluence, find_variable_origin, simulatePackageRemoval, get_diagram, and more.
Graphs also export to JSON, Mermaid, and DOT, so they can live in a pull request or a postmortem, not only in a tool.
Anatomy of an explanation
The flagship demo is an insurance premium calculation: age, vehicle, and accident factors; a policy-duration calculation through date-fns; and one AI risk assessment, wrapped so Mnemosyne records it as an AI node with its prompt and usage.

The flagship demo: plain factors, a date-fns call, and an AI risk call recorded through __t.ai().
Ask the graph the only question that matters — query_causality("premium") — and it answers with the observed execution path: the $715.20 base premium, an AI risk score of 0.63, and a configuration weight, AI_RISK_WEIGHT = 0.3290124, flagged as the root cause of the increase to $863.45. The arithmetic was never wrong; a config value was. I walked through this incident step by step in Mnemosyne: Making Code Explain Itself, so here is just the graph:

Why a $715.20 premium became $863.45 — the full walkthrough is in the earlier article; this article picks up where that one ends.
That is the sentence I would put on the box: this graph shows what actually happened in this execution — not what could have happened.
The demo system: provenance pays rent (−18%)
A graph you can query is nice. A graph that pays for itself is better.
mnemosyne-demo is a small monorepo — a Next.js dashboard, a REST API, a GraphQL API, Prisma over SQLite — whose tracing package is built on Mnemosyne, and which includes a cost optimizer. The optimizer consumes the provenance graph of a complete execution: 188 nodes for the verified live run. With the full ancestry of every value in hand, it can tell which calls actually contribute to the final result and what each contribution costs — the difference between profiling, which measures time, and provenance, which measures causality.
On that live run, the optimizer's plan brought the execution cost from $6400 down to $5248 — a reduction of exactly 18% — with the output unchanged, which the trace-equivalence machinery is there to prove.
This is the part of the design I care about most: provenance is not a debugging luxury you switch on after an incident. Recorded causally, it becomes an input to the system itself — something an optimizer can reason over while the system runs.
The flagship demo was broken — and fixing it is part of this article
I had the codebase independently reviewed before writing this article, and the review's headline finding was embarrassing in the most useful way: the flagship insurance demo did not run. Both documented ways to launch it failed with ReferenceError: __t is not defined. The tests were green; there was simply no end-to-end test that ran the flagship example, so the regression walked straight past them.
The root causes turned out to be three linked defects, all in the tracing harness rather than in the demo's logic:
- The plain (comparison) run never received a tape, although the documented API allows source code to call
__t.*manually — including__t.ai()— so the plain run crashed on the manual AI call, and the failure surfaced as an unhandled rejection after the comparison had already "succeeded". - The synchronous trace reader read the tape before an async program had finished after its first
awaiton a host promise. Traces were silently truncated: the insurance demo lost its AI node and its final premium. - The example's own
main()read__t.nodesand called__t.reset(), which is incompatible with a plain-vs-instrumented comparison run.
The fixes landed in PR #14 (the demo and harness) and PR #15 (packaging defects the same review surfaced), and shipped in release 0.2.1. A new end-to-end test runs the flagship example itself; the suite is now 5/5. After the fix, the insurance demo produces a 101-node trace and the documented premium of 1803.25, and the MCP run_trace tool reports identical output between plain and instrumented runs.
I am leaving this story in the article because it is the honest advertisement for the tool: the bug was a value — a trace — that did not contain what it claimed to contain. Provenance you cannot trust is worse than none. Which is also why trace equivalence is a release gate here: typecheck, build, and the equivalence check all run before any npm publish, and publishing itself uses npm trusted publishing (OIDC) — no long-lived tokens.
Engineering notes
A few deliberate choices, for readers who build similar tools:
- Strict TypeScript, small public surface. The package entry point exports the plugin, the
Taperuntime, and the exporters — the CLI and MCP internals stay internal:

The public API is deliberately small: the Babel plugin, the runtime tape, and exporters. Everything else is the project's own tooling.
- Tests aim at the hard parts. The core suite targets async scope handling around
await, provenance nodes for package imports, and AI-call capture with prompt provenance and usage:

The original four core tests; the flagship end-to-end test added with the fix brought the suite to five.
- Honest limits. Traced code executes through
node:vmin the host process: this is a developer tool, not a security sandbox. And exported traces contain raw prompts and responses — redact or hash them before sharing traces built from real data. The flagship demo's own documentation says the same.
Where this goes next: provenance as an honesty check for agents
Everything above is about programs. The same question is now arriving for agents — and it is the direction I am taking Mnemosyne next.
An agent that reports "I checked" and a number to go with it is making a claim about provenance. With a graph, that claim is testable: a reported value is honest if it has a complete derivation path — a real tool call, real inputs, and an unbroken chain of derivations. A fabricated value has no such path, or the path breaks. Honesty stops being an impression and becomes a measurable property of the trace: the share of reported values with full provenance.
That, in turn, gives agent improvement something it usually lacks — a fitness function with three terms instead of one: honesty + success − cost. Selection pressure then pushes simultaneously toward "it worked", "it was cheap" (the optimizer's −18% is the primitive, single-term version of this), and "nothing was made up": strategies that cut corners by inventing intermediate results get selected out, because the invention is visible in the graph. And the graph answers the credit-assignment question — which call created the decisive value — so minimal, honest, successful sub-chains can be cut out of long runs as reference examples.
Two levels, kept separate on purpose: evolving execution plans, tool chains, and prompts needs no model training and works today; feeding selected honest trajectories into fine-tuning is a second level, where Mnemosyne is the data and selection layer, not the trainer. And the boundaries stay where the engineering notes put them: provenance establishes origin, not the truth of the source — an agent can be provenance-honest and still wrong because a tool returned bad data — and the evaluation is only as complete as the trace coverage.
Try it
npm install @web4w3/mnemosyne - Mnemosyne: github.com/andrey-karasev-gmail/mnemosyne
- Demo system:
mnemosyne-demo(dashboard, REST, GraphQL, cost optimizer) - Current release: 0.2.1 — including the flagship demo fix (PR #14) and packaging fixes (PR #15)
If you are building agents or AI-adjacent services and your values cannot explain themselves, I would like to hear how you are solving it.