From the Mnemo documentation. Synthetic data only.
How Mnemo works
A technical overview for someone who has not seen the project. Everything here was read from the code or run; where something has not been done, it says so. The setup steps are in docs/SETUP.md, a worked example is in docs/demo_transcript.md, and the design is in docs/walkthrough-spec.md.
What it is
Mnemo is an AI trading journal with a reflective coach for futures traders. It stores a trader's closed trades and computes facts about them in code. Then it asks an AI model to do one of two things: write reflective questions about the trader's history or about one trade, and, for a trade walkthrough, set what the trader said about a trade beside what the record shows. The coach describes and asks. It gives no advice, no predictions and no judgment, and it does not label the trader's psychology. Code checks everything the model writes before anything is saved.
What has and has not been run. The code, the checks and the evaluation are tested with a fake client that returns scripted replies. The real AI model has been run against the trade walkthrough once, on 2026-10-31, on synthetic data with scripted answers: one sample, not deterministic, and the same day the walkthrough evaluation (five cases) was run for real once. The output is stored in docs/real_run/. The review and memory evaluations have not been run for real. The older "review" command (coach_cli review) calls the real API when given a key, but this document makes no claim about how the real model behaves on it.
The data flow
trades in store facts, computed in code prompt
--------- ----- ----------------------- ------
CSV import --> SQLite database --> patterns.py (history-wide facts) --> system prompt + FACTS
POST /trades fees, results trade_card.py (9 facts for one + TRADES (rows, notes)
seed_demo.py in integer cents trade vs. its history) + ANSWERS (walkthrough step 2)
(Decimal in code) |
v
saved <-- checks, in code <-- structured JSON <-- the AI model (a client passed in; tests pass a fake)
----- ------------------ --------------- ---
coach notes citations real? questions, or the
walkthrough quotes real? reply (compared /
tables wording lists how_it_went /
size limit not_in_record)
- In. Trades come from
import_cli(a CSV in Mnemo's own format; there is no broker parser yet), from the API'sPOST /trades, or fromseed_demo.py. Every field is validated and limited (models.py). - Store. SQLite (
store.py). Money is exact:Decimalin code, integer cents in the database (fees and net results), rounding half-up. Entry and exit prices are stored as floating-point numbers, since they are prices and not money amounts. Times are stored in UTC. - Facts. All numbers come from code.
patterns.pycomputes the history-wide facts the review uses (hold time of winners against losers, results by time of day, direction and instrument, the biggest losses, what follows a loss).trade_card.pycomputes the ninewt.*facts that set one trade beside the trader's earlier history. Each fact has a key, a sentence, its values and the trades it rests on. - Prompt. The prompt carries the facts, the trade rows (with the trader's notes, marked as the trader's words) and, for the reply step, the trader's answers (also marked as data, never instructions). Its size is estimated first and a request over the limit (default 150000 tokens) is refused before anything is sent.
- Model. The model is asked for structured JSON that matches a schema. There is no "advice" field to fill in. The client is passed into the code, so tests and evaluations use a fake one;
settings.make_client()is the only place a real one is built. - Checks, then save. See below. A failed check rejects the whole result and saves nothing from it.
The one rule that matters
Numbers come from code. The model does no arithmetic. It is told to quote numbers exactly as they appear in the facts. The walkthrough's reply step lists any number it cannot trace to the facts, the cited rows or the answers, and the review evaluation does the same (its check e). That is a warning, not a rejection (see the limits below), and the older review command does not trace numbers at run time. Step 1 also warns, without refusing, when a question's text contains a figure, because a question that states a figure states a fact.
Around it, three more rules, enforced differently:
- Every statement cites the facts (
stat_keysorfact_keys) or trades (trade_ids) it rests on. The code checks that each citation exists in the input, and that questions and compared statements cite something. A bad citation rejects the whole result. - Every quote is checked. In a walkthrough reply, a quote of the trader must be a piece of one of their answers (case, spacing and look-alike characters ignored; a quote under 8 characters must be a whole answer). A quote that is not there rejects the reply.
- The wording lists are a backstop only.
compliance.pyflags advice and psychology-label wording andneutrality.pyflags 14 judging words (better, worse, best, worst, good, great, bad, terrible, poor, poorly, well, mistake, mistakes, wrong). They catch the obvious. They have false alarms and misses (below). The real safeguards are the system prompt, the structured output, and the citation and quote checks.
What the model writes, and what code does
| The model writes | Code does |
|---|---|
| Step 1: 3 to 5 open questions about one trade, each citing a fact or trade | Picks the trade, builds the card and the rows, decides which older trades are shown, builds the prompt, checks the questions, saves the walkthrough |
| Step 2: a reply in three lists. compared: a quote of the trader plus what the record shows. how_it_went: the trade against the history, in neutral words. not_in_record: things the record cannot show (a plan, a reason), with a quote | Asks the questions and collects the answers, builds the reply prompt, checks the reply (citations, quotes, counts, wording), saves it |
| The older review: observations and open questions about the whole history | Computes the patterns, builds the prompt, checks and saves the notes, feeds recent notes back in as memory |
A rejected reply. If any check fails, nothing from the reply is saved. The trader's answers are saved, so they never retype them, and answer can be run again: it says the answers are already there and asks only for the reply. The message names what was wrong, for example compared 1: "should" (directive).
What the evaluation proves, and what it does not
walkthrough_eval builds five planted cases from the synthetic data (a hold that was short, a size above the median, a "first trade of the day" that was the fourth, one true claim as a control, and a stop and plan the record cannot show), runs each through the real code with a scripted reply, and grades the saved reply: is the claim in the right list, is the right fact cited, is the record's figure stated, is the control not called a mismatch, and is the coach's own text free of advice, psychology labels and judging words. Tests feed deliberately bad replies through the same grader and assert each one fails the right check. coach_eval grades a review against its own answer key (three planted habits and the trades whose note says "wanted to make it back").
- It proves that the plumbing works from prompt to saved reply, that the grader can fail (the negative controls), and that a well-formed scripted reply passes every check.
- It does not prove anything about the real model in fake mode, because the replies are scripted to be good. The one real run (2026-10-31) shows what one sample did, and nothing more. It does not judge whether a reply is true, fair, clear or useful: it checks where a claim lands, what it cites and how it is worded. It tests five planted claims and says nothing about anything else a model might write.
Module map
mnemo/
| File | What it does |
|---|---|
api.py | FastAPI app: add a trade, summary stats, the accountant export downloads. Answers only requests addressed to 127.0.0.1 or localhost. No login |
coach.py | The reflective review: system prompt, prompt building, the model call with structured output, validation, saving notes |
coach_cli.py | Command line for the review: prompt (no API call), review (calls the API), notes |
coach_eval.py | Evaluates a review against an answer key; fake client by default, --real calls the API |
compliance.py | The advice and psychology-label word lists (a backstop) |
csv_import.py | Reads trades from Mnemo's CSV format |
eval_checks.py | Pure check functions, used by the review evaluation and by the reply's number tracing |
export.py | The accountant export of closed trades. Lists trades; no tax logic of any kind |
export_cli.py | Command line for the export |
import_cli.py | Command line for the CSV import |
import_plan.py | Decides what an import would do without writing anything |
memory_eval.py | Runs two reviews in a row and checks the second is built from the first one's notes |
models.py | The trade and note shapes, with their limits (Decimal money, field limits) |
money.py | Exact conversion between dollars and whole cents |
neutrality.py | The 14 judging words (a backstop) |
patterns.py | History-wide facts computed in code, and the time-of-day buckets |
pricing.py | A cost estimate from token counts (a dated price table) |
settings.py | Reads .env, the model name, the size limit, builds the API client, hides the key in error text |
stats.py | Summary statistics and half-up rounding |
store.py | The SQLite schema and the functions that read and write it |
trade_card.py | The nine facts that set one trade beside the trader's earlier history |
walkthrough_ai.py | Both AI steps of a walkthrough: prompts, schemas, calling the model, the checks |
walkthrough_cli.py | Command line for walkthroughs: start, answer, show, settings |
walkthrough_eval.py | The evaluation with planted mismatches |
walkthrough_models.py | The shapes and limits of walkthrough data |
walkthrough_rows.py | Which trades the model sees in full: the walked trade, the 15 before it, and up to 15 older ones |
walkthrough_store.py | Saving and reading walkthroughs, with ownership checks |
tools/
| File | What it does |
|---|---|
make_demo_transcript.py | Generates docs/demo_transcript.md by running the real command-line code with a fake client |
mutation_check.py | Breaks the code on purpose, one small change at a time, and reports changes no test noticed |
Also at the top level: seed_demo.py (loads a sample file into a database), mnemo_journal.py (the original interactive console journal) and samples/ (the synthetic data and its answer keys, and the script that generated it).
Known limits
Copied from the README and the spec, not softened.
- The neutrality list has false alarms. It rejects better, worse, best, worst, good, great, bad, terrible, poor, poorly, well, mistake, mistakes and wrong as whole words in the coach's own text. It also rejects harmless uses: "well-known" and "as well as" (a hyphen ends a word, and the idiom is not special-cased), "best bid", "good till cancelled", "a good number of", "worst first", and a question such as "Which trade felt best to you?". Step 1 and the reply refuse the whole step for any of them.
tests/test_neutrality_lists.pylists them all. - It also has misses. "Excellent", "sloppy", "reckless", "smart", "the right size", "you held too long" and more pass the neutrality list. Some are caught by the advice or psychology checks ("should have", "disciplined", "panicked"); many are caught by nothing. The same test file lists them on purpose.
- Number tracing in the reply is only a warning. It lists numbers it cannot find in the facts, rows or answers (and, in a "cannot show" text, the ids of the trades shown to the model); a wrong number that happens to appear elsewhere passes.
- The word lists are a backstop, like the advice check in the README. A model can say the same thing in words they miss.
- The sample dataset has no 40-second trade, the example in the spec. The evaluation's short-hold case uses trade 21 (2.3 min against a median of 5.5).
- No memory across walkthroughs in version 1. Each walkthrough sees the trades and the trade card, not earlier walkthroughs or their answers.
- One walkthrough, one trade. There is no open conversation, and no screen for traders yet.
- The real model has been run once. One walkthrough and one evaluation of five cases on 2026-10-31, from one sample; how often the model is rejected by these checks is not known. The review and memory evaluations have not been run for real.
From the spec, what is not decided yet:
- The neutrality list's false alarms. The corpus (
tests/test_neutrality_lists.py) shows the list rejects some harmless wording, for example "as well as", "best bid", "a good number of" and a question such as "Which trade felt best to you?". Whether to narrow the list or add a small allowlist is the owner's decision; nothing has changed. - Real-API runs: one walkthrough and one evaluation were run on 2026-10-31. More runs are for the owner to choose, and spend credit on. With more real replies we will learn how often the label and neutrality checks reject a reply, and whether the questions are good.
- Root-symbol grouping, and the trading day by close time: later, as above.
- Trader-facing screens and an open conversation: later versions.
From the spec, out of version 1: trader-facing screens (parked), an open multi-turn conversation, plans, stops, targets and market data, and broker adapters (Tradovate).
Also true, and stated elsewhere: there is no login or per-firm authorization, so the API must not be exposed beyond this machine; the walkthrough and the review send trade rows and notes to an AI service when run for real, so only the synthetic sample should be used for now.
Found in the first real run (2026-10-31)
These are facts from one real run, on synthetic data, with scripted answers: one walkthrough (trade 18) and one evaluation of five cases. Each finding is recorded as it was found. The second has been fixed, and the first has a warning-only check (see their status lines). The output is in docs/real_run/, and tests/test_real_run_files.py pins each statement to those files.
- Two questions state facts inside the question, and no code checks for that. The prompt's rule 13 says not to state or compare facts inside a question. Question 4 reads "Trade 18 was your fourth trade of the day, coming after trades 15, 16 and 17" and question 5 reads "the 37.4 minutes between closing trade 17 and opening trade 18"; both repeat the card's own figures. Questions 2 and 3 also repeat a figure from the card (20223.0, and 29.4 minutes). The code checks the number of questions, their citations and the word lists for step 1; it does not check this rule. Status: found on 2026-10-31; a warning-only check was added in commit ba45d96. Step 1 now warns
question N: states ...with the figures when a question's text contains a number that is not a clock time (12:05, 12:05:53) and not the id of a shown trade written after "trade" or "trades". The questions are still saved, andstartprints the warning. On the stored questions it warns for question 2 (20223.0), question 3 (29.4) and question 5 (37.4), and not for question 1 ("trade 18", "12:05"). It does not catch a fact written in words: question 4 ("your fourth trade of the day, coming after trades 15, 16 and 17") gives no warning. It also does not see a time written without a colon ("9 am") as a time, and it takes a number as a trade id only after the word "trade". The prompt's rule 13 is unchanged. - Number tracing raised a warning on a number that is not wrong. The reply was saved with the warning "not_in_record 1: could not trace 18". An item in the "cannot show" list carries only a quote and a text, never trade ids, so a trade number written in its text has nothing to be traced against. The text is "The note for trade 18 reads 'pullback to VWAP'", and 18 is the trade the walkthrough is about. It looks like a false alarm. The check is a warning only, so the reply was saved. Status: found on 2026-10-31; fixed in commit 3110291. A "cannot show" text now also traces the ids of the trades shown in the prompt (the walked trade included). Any other number in it still warns, and the "compared" and "how it went" items are unchanged: they still have to cite the trade, or the number has to be in the facts or the answers.
- A stray quote character ends a text in one evaluation reply. In case 4 the raw model output ends a "cannot show" text with an escaped quote after its last full stop, and the saved reply keeps it. Nothing checks for it.
- The model wrote a sign into a by-size comparison. In case 2 the reply says "smaller than the median of -136.48 across 7 earlier losses". The card's own sentence for the same comparison is unsigned ("the median size of 136.48"). Every row for case 2 passed, so no check looks at the sign.
- The advice, psychology and neutrality lists flagged nothing in this run. That covers the 35 rows of the evaluation and the one full walkthrough. From one sample this is evidence to leave the lists unchanged for now. It is not evidence that they are right: the false alarms and misses listed above come from the test corpus and still stand.
- The checks cannot judge fairness, and the answer key does not grade the questions. All 35 rows passed. A row checks where a claim lands, what it cites and how it is worded. Nothing in the evaluation says whether the questions were good ones.