How Stepwise works

Stepwise puts the method in code and treats the language model as a replaceable part. The model supplies reasoning inside narrow, structured steps; application code decides the workflow, checks every output, and records how each answer was produced.

The pieces

browser (profiles, settings, history in localStorage)
   |  one JSON request per question; progress streams back as NDJSON
   v
app/        FastAPI: pages, the streaming run API, tool APIs, security headers
   |
engine/     router -> orchestrator -> analysts (schema-validated)
   |                                     |
   |                              providers (Ollama, Anthropic, OpenAI-compatible)
library/    the library: core principles + source cards (BM25 retrieval, in process)

Workflows

A deterministic router picks one of three workflows from your wording (or you pick it):

  • Ask - retrieve guidance, then answer.
  • Review a plan - retrieve, risk-review the plan, then write a structured review.
  • Stress-test a claim - retrieve, then a risk review, which is the result.

Which steps run for a workflow is a fixed table in engine/orchestrator.py, never the model's choice.

Playbooks

A playbook (engine/playbooks.py) says whose framework to apply: Compare all three (default), Baby Steps, Financial Order of Operations, Conscious Spending, or Simple Path to Wealth. A playbook pins that framework's source cards into retrieval and adds an instruction to every prompt; under Compare all three the answer carries a "how the frameworks differ" section when they disagree.

Analysts and schemas

Each model call has one role, one governing question and one output schema (engine/schemas.py, Pydantic with extra fields forbidden). Output that doesn't validate is sent back to the model with its own validation errors, up to STEPWISE_MAX_ATTEMPTS times. For OpenAI-compatible services that don't support schema-constrained output, the request steps down to plain JSON mode and then to a prompt-only schema. Prompts are versioned files in engine/prompts/. Answers may only cite library sources they were actually shown.

Reading numbers from a description

On the Where am I?, Coast FIRE and Debt payoff pages people can describe their situation in their own words. engine/extract.py asks the model to fill a schema of facts (null when not stated, with a note for every conversion such as monthly to yearly), range-checks every value in code, and lists what's still missing. The page shows what was understood and fills in the form; the calculation itself stays plain arithmetic.

Explaining a result

Under each calculator's result, "Explain my results" sends the inputs and the computed result to engine/explain.py, which pins that tool's library cards and asks the model for a short summary, next steps and things worth knowing. The prompt forbids recomputing or inventing numbers; the model narrates, the code does the math.

Voice input

Every free-text box (and the follow-up chat) gets a microphone button from app/static/ai.js. When Whisper is available, the browser records a clip (MediaRecorder, Opus at 32 kbps, up to three minutes) and posts it to /api/transcribe; app/transcribe.py passes it to Groq's whisper-large-v3-turbo with a finance-vocabulary prompt, drops Whisper's stock "phantom" phrases on silence, and returns the text. Whose key pays: the person's own Groq connection first, else the site's GROQ_API_KEY (or the house model's key when the house model is on Groq), behind the access code and STEPWISE_VOICE_CLIPS_PER_HOUR. Without any key the page uses the browser's Web Speech API instead, one phrase at a time on phones (continuous mode repeats words there). Permissions-Policy allows the microphone for the site itself and nothing else.

Follow-up chat

After an answer, people can keep asking questions about it (engine/chat.py). Each follow-up is one schema-validated model call that receives the original report, the conversation so far and fresh library passages pinned to the same playbook. The server keeps nothing between messages; the browser sends the context each time and saves the conversation with the answer in History.

The tools

engine/steps.py (Where am I?), engine/debt.py (Debt payoff) and engine/coast.py (Coast FIRE) are pure functions: plain rules and arithmetic, fully covered by tests, no model involved. The Coast FIRE result explains itself step by step with the person's own numbers and shows how it changes at lower and higher returns.

engine/multiplier.py (Wealth multiplier) works out what $1 grows to by retirement for every age, nominal and in today's dollars, and also The Money Guy chart's own figure (10% compounded monthly) for comparison.

engine/tax_buckets.py (Fill your tax buckets) and engine/accounts.py (HSA and Kids accounts) read every contribution limit from engine/limits.py: one table keyed by tax year, each figure with its IRS source. limits_for refuses a year with no entry rather than showing last year's numbers, and a test fails on January 1 until the new year is added.

engine/stocks.py (Picking stocks) works out what a higher yearly fee costs against an index fund and applies the cited missed-best-days rates to the person's amount. The historical figures the page shows live in one EVIDENCE table with their sources. Its optional AI review of a stock idea (stock_review role) uses a schema with no field for tickers, price targets or a buy list, and a prompt that forbids picking stocks or predicting prices; the share of the person's money the idea represents is computed in code.

Stateless by design

There are no accounts and no server-side storage. A run is one streaming request: the server builds an orchestrator for your connection, streams stage events as they happen, sends the finished report (HTML, Markdown, and a summary) as the final event, and drops everything. The browser keeps the report in that profile's history. This is what makes Stepwise deployable on serverless platforms and keeps the privacy story simple: the server can't leak what it never keeps.

Extending the library

Add a Markdown file to library/finance/source_cards/ - one topic per file, first heading is the title, a ## Themes list of keywords at the end helps retrieval. No code change is needed. Framework summaries must be in our own words, attributed, and point to the original.

Tests

pip install -r requirements-dev.txt
pytest

The suite covers the router, retrieval and playbooks, the step finder and debt simulator, the orchestrator end to end with a scripted mock model, the provider adapters against a faked HTTP layer, and the web app (pages, streaming runs, connection policy, security headers).