Mnemo

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)
  1. In. Trades come from import_cli (a CSV in Mnemo's own format; there is no broker parser yet), from the API's POST /trades, or from seed_demo.py. Every field is validated and limited (models.py).
  2. Store. SQLite (store.py). Money is exact: Decimal in 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.
  3. Facts. All numbers come from code. patterns.py computes 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.py computes the nine wt.* 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.
  4. 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.
  5. 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.
  6. 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:

What the model writes, and what code does

The model writesCode does
Step 1: 3 to 5 open questions about one trade, each citing a fact or tradePicks 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 quoteAsks 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 historyComputes 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").

Module map

mnemo/

FileWhat it does
api.pyFastAPI app: add a trade, summary stats, the accountant export downloads. Answers only requests addressed to 127.0.0.1 or localhost. No login
coach.pyThe reflective review: system prompt, prompt building, the model call with structured output, validation, saving notes
coach_cli.pyCommand line for the review: prompt (no API call), review (calls the API), notes
coach_eval.pyEvaluates a review against an answer key; fake client by default, --real calls the API
compliance.pyThe advice and psychology-label word lists (a backstop)
csv_import.pyReads trades from Mnemo's CSV format
eval_checks.pyPure check functions, used by the review evaluation and by the reply's number tracing
export.pyThe accountant export of closed trades. Lists trades; no tax logic of any kind
export_cli.pyCommand line for the export
import_cli.pyCommand line for the CSV import
import_plan.pyDecides what an import would do without writing anything
memory_eval.pyRuns two reviews in a row and checks the second is built from the first one's notes
models.pyThe trade and note shapes, with their limits (Decimal money, field limits)
money.pyExact conversion between dollars and whole cents
neutrality.pyThe 14 judging words (a backstop)
patterns.pyHistory-wide facts computed in code, and the time-of-day buckets
pricing.pyA cost estimate from token counts (a dated price table)
settings.pyReads .env, the model name, the size limit, builds the API client, hides the key in error text
stats.pySummary statistics and half-up rounding
store.pyThe SQLite schema and the functions that read and write it
trade_card.pyThe nine facts that set one trade beside the trader's earlier history
walkthrough_ai.pyBoth AI steps of a walkthrough: prompts, schemas, calling the model, the checks
walkthrough_cli.pyCommand line for walkthroughs: start, answer, show, settings
walkthrough_eval.pyThe evaluation with planted mismatches
walkthrough_models.pyThe shapes and limits of walkthrough data
walkthrough_rows.pyWhich trades the model sees in full: the walked trade, the 15 before it, and up to 15 older ones
walkthrough_store.pySaving and reading walkthroughs, with ownership checks

tools/

FileWhat it does
make_demo_transcript.pyGenerates docs/demo_transcript.md by running the real command-line code with a fake client
mutation_check.pyBreaks 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.

From the spec, what is not decided yet:

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.