Mochi
- Date:
- Sun, Oct 18, 2026
- From:
- Atharva Maskar <github.com/AtharvaMaskar>
- To:
- You
- Subject:
- Mochi
mochi is a support desk where no ticket starts from zero. Its memory is one FalkorDB graph. Each answer shows the path it took through that graph, and each number links to the Cypher query that produced it. I built it for Graph Hacks, entered all three tracks, and the code is open source.
All data here is synthetic. E Corp Securities is a fictional broker.
Where this came from
I'm an AI engineer at a stock-broking platform. Opening an account takes a day or two. A ticket about that account can take a week, because it moves between onboarding, KYC, the KRA and back again. I've watched teams lose days to this. One team waits on another. The person who fixed the same problem last month never gets asked, because nobody knows they fixed it. The customer explains everything again at every hand-off.
I also wanted to work on agent memory, and this weekend I could measure it.
I expected FalkorDB to be a place to store nodes. Then I found its graph algorithms and started calling them as tools. Cypher joins, ranks and clusters the tickets. The model picks which query to run and writes the reply. mochi is built around that.
Does it work?
Teams I've worked with are obsessed with keeping agent memory in markdown files. I get why: a file is easy to write, read and diff. It was never enough for what we needed, and I knew there had to be a better way to handle memory.
I want a small model to be enough, because the memory carries the weight. In Mochi, Haiku answers from the graph. On the graph, Haiku got correct at per answer. Sonnet on markdown notes got at . Same questions, same judge.
Most of the gap is multi-hop questions, like "which release caused the issues behind this week's refund tickets?" On Haiku, the graph got of those right, SQLite tables with the same queries , and markdown notes .
Notes also cost tokens to keep. Turning the tickets into markdown memory took tokens; the graph's extraction took . When a fact changes, a model rewrites the notes, at tokens per change on average. The graph closes the old fact with a date in one Cypher write, for tokens. After the changes, the graph gave the current answer on questions, and the notes on .
On Haiku, notes, tables and vector top-k all cost less per answer than the graph. They also answer fewer questions right.
What is a brief?
Watch a support agent take a ticket: "Money deducted, order not placed." Before they can write anything useful, they open the CRM to see who this is, then billing, then the ticket history, then team chat, then a knowledge base that may predate the last release. The context exists. It sits in pieces that don't know about each other, so a person rebuilds it for every ticket.
The pieces also drift. Someone writes a KB article once and moves on. A step changes and nobody updates the doc. A detail gets lost in a hand-off. We're human, and humans forget. Our systems still expect every answer to be right. So the memory has to expect the gaps, and notice when a document no longer matches what the team actually does.
We want every ticket to start with what the company already knows. In Mochi, the agent gets a brief before it types a word: who the customer is, what fixed similar tickets, the likely cause and the team that owns it. The core of it is one walk through the graph, from the new ticket to its issue, to the tickets that shared it, to how they were resolved and the KB article behind the fix:
// agent/queries/index.ts
similar: `/* mochi:briefing.similar@v1 path: graph */
MATCH (t:Ticket {id: $ticketId})-[:ABOUT]->(i:Issue)<-[:ABOUT]-(s:Ticket)-[:RESOLVED_BY]->(r:Resolution)
WHERE s.id <> t.id AND ${N('t')} AND ${N('i')} AND ${N('s')} AND ${N('r')} AND s.resolved_at <= $as_of
OPTIONAL MATCH (r)-[:BASED_ON]->(k:KBArticle) WHERE ${N('k')}
RETURN s.id AS ticket, s.subject AS subject, i.id AS issue_id, i.name AS issue,
r.id AS resolution_id, r.summary AS resolution, k.id AS kb_id, k.title AS kb
ORDER BY s.resolved_at DESC, s.id LIMIT 5`,
N('t') expands to t.created_at <= $as_of, so the same query can answer "as of last Tuesday". The model never writes these rows. Code builds the brief card from them, and the card keeps the path it walked.
RAISED → ABOUT → INTRODUCED. The cabinet costs one read per note, however many notes there are.Who has solved this before?
Senior agents are fast because they carry the links in their heads: which release broke what, which team owns which screen, who fixed this last month. When they leave, the links leave. We want those links in the memory, not in people's heads. In Mochi, "who knows" is a count of SOLVED edges into tickets about the same issue:
// agent/queries/index.ts
whoKnows: `/* mochi:who_knows@v1 */
MATCH (i:Issue) WHERE (i.id = $issueId OR toLower(i.name) = toLower($issueId)) AND ${N('i')}
MATCH (a:AgentUser)-[s:SOLVED]->(t:Ticket)-[:ABOUT]->(i)
WHERE ${N('a')} AND ${N('t')}
WITH a, i, count(s) AS solved, min(t.id) AS example_ticket
OPTIONAL MATCH (a)-[:MEMBER_OF]->(tm:Team)
RETURN a.id AS agent_id, a.name AS agent, tm.name AS team, solved, example_ticket, i.name AS issue
ORDER BY solved DESC, agent_id LIMIT 5`,
The five core queries are hand-written and tested like this one. For questions I didn't write a query for, chat has query_graph: the model writes its own read-only Cypher against a schema generated from the contract. The database runs it as GRAPH.RO_QUERY under a reader account, so a write fails there, not in a prompt. Chat also has graph_algorithm, which runs FalkorDB's PageRank, label propagation, betweenness and shortest path as tools. That is the part that changed my mind about graph databases.
Every number has a receipt
We want every figure to open the query that produced it. In Mochi, every query result is stored as {id: "q_n", cypher, graph, params, rows}, and every stored query takes $as_of. A tool card, a chart or a number in a sentence points at a query_id, and a number without one fails validation. Reports work the same way: the model writes markdown with tags such as <num query_id="q_1" column="median_h"/>, and a renderer fills them from the stored rows. I borrowed that format from nao.
Because every query takes $as_of, a shared report link with ?asOf= re-runs the same Cypher at that time and shows what the brain believed then. That needed no per-query code. It fell out of a rule I made at 11:27 on Sunday morning.
Memory that changes
We want a wrong fact retired, not erased. In Mochi, every fact that can change is an edge with valid_from and valid_until. When a fact changes, the old edge gets a closing date and a new edge starts. Nothing is deleted. My plan said "live means valid_until is null". FalkorDB can't store null, so a live fact ends at the end of the year 9999 instead:
// contracts/graph.ts
// FalkorDB cannot store null, so a live fact ends at 9999-12-31 (docs/falkordb.md gotcha 1).
export const VALID_FOREVER = 253402300799000;
export const untilOrForever = (v: number | null) => v ?? VALID_FOREVER;
// One filter for live and as-of reads; live passes $as_of = now. Every temporal read uses these.
export const EDGE_AS_OF = (alias: string) => `${alias}.valid_from <= $as_of AND ${alias}.valid_until > $as_of`;
export const NODE_AS_OF = (alias: string) => `${alias}.created_at <= $as_of`;
One range filter now serves both "now" and "as of last Tuesday". The cost is a magic number on every live edge, and an as-of fragment in every query. I wrote by hand what Graphiti would have given me for free. Now I can explain every line of it.
The nightly dream
We want the brain to consolidate overnight and wake up knowing what changed. In Mochi, the dream is a Pi Durable background task and the only writer of the company graph. It snapshots with GRAPH.COPY, ingests the day's tickets, applies changed facts, clusters, promotes repeated fixes into practice, checks doctrine against practice and writes the morning report.
A model touches two steps: pulling entities out of ticket text, and two sentences of suggestion prose. Spotting that a KB article promises one thing while tickets show another is arithmetic, not a guess:
// agent/dream/rules.ts
/** The rules: CONTRADICTS {delta} when measured TAT beats the promise by the tolerance, UNDOCUMENTED for repeated KB-less workarounds. */
export function mismatchesOf(patterns: Pattern[]): MismatchEdge[] {
const out: MismatchEdge[] = [];
for (const p of patterns) {
if (p.support < MISMATCH.MIN_SUPPORT) continue;
const base = { pattern_id: p.id, key: p.key, area: p.area, support_count: p.support, ticket_ids: p.tickets };
if (p.kind === 'tat' && p.promised != null && p.promised > 0 && p.measured! > p.promised * (1 + MISMATCH.TAT_TOLERANCE))
out.push({ ...base, type: 'CONTRADICTS', target: p.target!, promised: p.promised, measured: p.measured!, delta: round(p.measured! - p.promised) });
if (p.kind === 'workaround') out.push({ ...base, type: 'UNDOCUMENTED', target: p.area, summary: p.summary });
}
return out;
On the planted doctrine-vs-practice mismatches, these rules found . A model given every doc and ticket as text found . Both found the mismatches. One of them also found things that were never there.
A note on clusters, in the interest of honesty. The graph_algorithm tool and the clusters benchmark run label propagation over SIMILAR_TO, a dated nearest-neighbour edge the dream builds between similar tickets. On the planted bad-release spikes the graph found , and a model reading the same text found . The nightly report does not use that path. Its cluster step groups the last seven days' tickets by issue. So the benchmark number describes the chat tool, not the report, and I'd rather say so than let one number cover both.
Learning from past tickets
We want the agent to reuse what worked last time, and to drop it the moment its facts stop being true. In Mochi, every answer that worked becomes a decision trace in a mochi_traces graph, with the queries it ran. A new ticket finds similar resolved tickets through SIMILAR_TO and replays their stored queries, so the model reads rows instead of exploring. Before any replay, the trace checks that it is still true:
// agent/traces/index.ts
/**
* Still true? Re-run each cited query at the current as_of: a receipt that had rows and now has none, or whose columns
* changed, means the fact under the trace was retired; so does a cited KB article with a live CONTRADICTS edge. A stale
* trace is closed (valid_until = now) so it is never offered again.
*/
export async function fresh(read: ReadDb, journal: JournalDb, t: Trace, as_of: number, journalGraph: string = J.graph): Promise<boolean> {
const kbs = new Set<string>();
let ok = true;
for (const q of t.queries) {
const r = await read.selectGraph(q.graph).roQuery<Record<string, unknown>>(q.cypher, { params: { ...q.params, as_of } }).catch(() => null);
const rows = r?.data ?? [];
if (!r || (q.row_count > 0 && !rows.length) || (rows.length && Object.keys(rows[0]).join() !== q.columns.join())) { ok = false; break; }
for (const row of rows) if (typeof row.kb_id === 'string') kbs.add(row.kb_id);
}
if (ok && kbs.size) {
const g = t.queries[0].graph;
const c = await read.selectGraph(g).roQuery<{ n: number }>(`MATCH (:ObservedPattern)-[c:CONTRADICTS]->(k:KBArticle)
WHERE k.id IN $kbs AND ${EDGE_AS_OF('c')} RETURN count(c) AS n`, { params: { kbs: [...kbs], as_of } });
ok = !(c.data?.[0]?.n ?? 0);
}
if (!ok) await journal.selectGraph(journalGraph).query(`MATCH (t:${J.Trace} {id: $id}) SET t.valid_until = $now`, { params: { id: t.id, now: as_of } });
return ok;
}
Decision traces are experimental and off by default, behind MOCHI_TRACES=on. I tested them against five other ways to learn. Each learned from the same earlier resolved tickets, with the same facts per lesson, and answered the same later ones. Then I retired facts and checked whether stale fixes came back. "Devin-style Knowledge" is modelled on Devin's documented Knowledge feature, not Devin itself.
Traces got right at per 1,000 answers. Plain graph memory, with no learning, got at . Replay is cheaper because the model reads input tokens instead of , in one model call instead of two. After the retirements, traces stayed current on . LESSONS.md stayed current on , and the stale fix came back times. A lesson doesn't know its fact was retired. A trace checks.
. Top: correct answers on the later tickets. Bottom: answers still current after the retirements. The label shows cost per 1,000 answers. Tap a bar for its receipt. Source: decision_traces.approaches.Many agents, one memory
We want a shared brain that no conversation can quietly edit. In Mochi, memory lives in tiers: the company graph, a graph per team and a graph per user. Each process connects with the role it needs, and FalkorDB's own ACL users enforce it. A prompt-injected conversation can ask for a write. The database says no:
# docker-compose.yml
--user mochi_reader on >${MOCHI_READER_PASSWORD:?} resetkeys ~mochi_company ~team_* ~mochi_journal resetchannels -@all +GRAPH.RO_QUERY +GRAPH.EXPLAIN +GRAPH.LIST +PING +INFO +CLIENT|SETINFO
--user mochi_dream on >${MOCHI_DREAM_PASSWORD:?} resetkeys ~mochi_company ~mochi_company_prev ~algo_scratch ~team_* resetchannels -@all +GRAPH.QUERY +GRAPH.RO_QUERY +GRAPH.EXPLAIN +GRAPH.COPY +GRAPH.DELETE +GRAPH.CONSTRAINT +GRAPH.LIST +PING +INFO +CLIENT|SETINFO
--user mochi_journal on >${MOCHI_JOURNAL_PASSWORD:?} resetkeys ~mochi_journal resetchannels -@all +GRAPH.QUERY +GRAPH.RO_QUERY +GRAPH.EXPLAIN +GRAPH.LIST +PING +INFO +CLIENT|SETINFO
The obvious grant, Redis's read-only key pattern %R~, breaks GRAPH.RO_QUERY, because that command declares its keys as read-write. I found that in a throwaway container, which is the best place to find it. The refusal test tries forbidden writes and foreign graphs as the reader. Refused: .
Readers keep reading while the dream writes. Torn reads during the dream: . Briefing latency by number of parallel conversations, on one container:
Survives a crash
We want an always-on agent to survive dying. In Mochi, every step of a run is a Pi Durable checkpoint. The crash demo submits a brief with a fixed requestId, sends kill -9 during the first tool call, reopens the same storage and resubmits:
// agent/scripts/crash-demo.ts
const sub = await pi.root.submit({ type: 'input', content: `Brief me on ticket ${ticket}.`, requestId: REQUEST_ID }, ctx);
say('submitted', { mode, submission: sub.id });
const settled = await sub.wait(ctx);
The second process gets the original submission back and finishes with one answer. Read tools are marked safe to replay and run again. Write tools never repeat silently: the model is told the call was interrupted. This is demonstrated, not benchmarked. Run npm run crash-demo -w agent to see it.
By default, Pi Durable keeps that journal in SQLite. The FalkorDB journal is optional: MOCHI_STORAGE=falkordb moves the agent's own history into a mochi_journal graph, one atomic write per commit batch, so a conversation's history becomes something you can walk like the memory. The upstream storage conformance suite passes against it. That is also demonstrated, not benchmarked, so I quote no number for it.
The numbers
One dataset and one question set go to six memory designs, with the same model and the same judge. A puts everything in the prompt. B is vector top-k, in FalkorDB's own vector index, so only the traversal differs from D. C is markdown file memory, following the open Agent Memory Repo spec. D is the graph. E holds the same data in SQLite, with SQL tools that mirror D one for one. I added E because it was the design most likely to embarrass me. F, TencentDB Agent Memory, had no clean Node adapter inside the time box, so it says "not measured".
The headline is cost per answer next to accuracy, because that is what a team would pay. Answer model , priced at . Judge . Run . The benchmark graph held nodes and edges.
per_task[].cost_usd_mean, accuracy.per_task[].cost_usd_mean, accuracy.per_task[].p50_ms, p95_ms.summary.Averages hide where each design wins, so the questions come in three types. Single-fact: "what plan is this customer on?" Honestly, files or tables should win those. Multi-hop: "which release caused the issues behind this week's refund tickets?" The graph should win those, if it is worth anything. Structural: "which KB article does practice contradict?" Whoever can compute it wins, not whoever can recall it.
Each graph feature against its closest rival:
The full ledger, as text
Answer-model spend across every benchmarked task: . My own build-time assistant usage is not in that number.
Try it
The live demo is at the platform; sign in as admin with password admin@1234. Shared reports and this page need no sign-in. To run it yourself you need Node 24 and Docker:
- Clone github.com/AtharvaMaskar/mochi-ai.
- Copy
.env.exampleto.envand set the passwords and API keys. - Start FalkorDB with its ACL users:
docker compose up -d. - Install:
npm install. - Generate the seeded synthetic dataset:
npm run gen. - Load the graph:
npm run load. - Run everything:
npm run dev, then openlocalhost:4000and sign in.
Mochi is a weekend build and it looks like one in places. Decision traces and the FalkorDB journal are off by default. The numbers describe a fixed, seeded slice of the simulated helpdesk, not production volume.
What's next
The nightly report should cluster over SIMILAR_TO, like the chat tool already does, so one number can describe both. Decision traces should earn their way to default by closing the gap with plain graph memory. And I want to run the same benchmark against real ticket shapes, at real volume. If you are building agent memory, I'd like to hear where this breaks for you: I'm @AtharvaMaskarML on X. The repo is open, and every number on this page can be re-run with npm run bench.
What I liked most: graph algorithms as tools. The graph memory layers I looked at give an agent storage and search; here Mochi can run PageRank or label propagation as a tool call and get a ranked or grouped answer back. Clustering a day of tickets that way found the same spikes as asking the model, with no invented groups ( against ) and about a ninth of the tokens ( against ).
Use of AI
Honest take: I could have built all of this without AI. But alone, something would have given: the UI, the UX, a feature I'd cut, or a benchmark I'd skip. I'm obsessed with getting things right, and that's what I used AI for. Every screen here went through 10 to 15 variations before I kept one. I rethought every interaction and every component, tried them side by side, and threw most of them away. AI didn't decide what was good. It made trying ten versions cheap enough that I actually did it. What I got out of it: more thoughtfulness, and a lot more experiments per hour.
Disclosure: built with Claude Code on Claude Opus 5.5. I used it to write specs and proposals, to write and test code in parallel git worktrees, one OpenSpec change per worktree, and to review diffs. I approved every design decision and spec amendment. An agent drafted this page from the git log, the archived changes and bench/results.json, and I edited it. I can explain every graph model, query and decision on it. The figures come in through blog/fill-bench.ts, which refuses to fill the page while any marker is left.