System architecture · WattIQ EPM Decision Agent
One map of the whole pipeline — inputs, the grounded analysis of World Bank–ESMAP EPM outputs, the governed LLM reasoning, the browser and export layers, the self-refreshing learning loop, and the platform that ships and stores it. Follow the four coloured circuits to trace any path end to end.
Circuit 1 — runtime
Top to bottom: what happens between a planner typing a question and a decision brief rendering in their browser. The reasoning core and the analysis layer run as a loop (step 3) — the model may call data tools several times, and every figure it later states is re-derived and cited from the sheets.
/api/chat (default 20 / 60s).no-cache on the shell + scripts so a redeploy reaches testers immediately.OPENAI_BASE_URL + MODEL) reasons, decides which tools to call, then writes the brief.{ answer, charts, sources } streamed to the browser (chart first, then the narrative).ECharts (charts), marked+DOMPurify (safe markdown).pptxgenjs).jsPDF): Watt iQ cover, country header, copyright, pagination — charts rendered full-width, spotlit.Circuit 2 — learning
Every question and every served answer is captured, made durable in Azure, and fed back as provisional guidance. Nothing is trusted until it is corroborated by ≥2 agreeing answers and a human approves it — the model proposes, a human disposes.
Every question is logged as raw demand; every answer is distilled into a structured insight — skill, tools, sheets, figures-as-claims, recommendation, admitted gaps.
question_log.py · insights.pyBoth streams append through one portable interface to the durable store — two blobs in the Azure learning container.
A similar new question pulls prior insights back into the prompt as Tier 2 — it steers approach, and is barred from supplying any figure.
insights.recall_block()The corroboration gate labels each pattern validated (≥2 agree), conflicting, or provisional — a human review surface.
gen_learning_digest.py → learning-digest.mdA validated pattern is proposed as a Tier-2 heuristic; a human maintainer approves it into Tier 1 (the system prompt). The loop never edits Tier 0/1 itself.
propose-heuristic → human → Tier 1/api/question-log + /api/insight-log.
The checks — why an answer can be trusted
Core directives. Identity, the trace-before-trust chain, data guardrails, security rules. Only a human editing the prompt file can change them — the loop never can.
Approved knowledge. Scenario map, EPM model reference, workbook map, best-practice standards. Changed only through a human-approved diff.
Learned heuristics. The only region the loop may draft into — advice, lower weight, never overriding Tier 0/1.
Every figure re-derived each run from the source sheets and cited [n]. A recalled number is context, never evidence — poisoning-resistant by design.
Circuit 3 — platform & delivery
Source lives on GitHub; a commit to main builds the Docker image and auto-deploys on Render.
The learning corpus lives outside the app in Azure Blob, so the container stays stateless and the state is portable to Azure/Foundry.
git tags = releases & exact rollback pointspoc-ci tests · scheduled learning-docs refreshpython:3.11-slim + requirements.txtpoc/, the data/ EPM workbooks, the system promptuvicorn; .dockerignore keeps .env outbuildFilter ignores docs/**/api/health probe.env is git- & docker-ignored
Reference
The walk-through list — group by group, what each part is and does.
data/*.xlsx) — the single source of truth for every figure.gpt-5.5.SourceLedger — ties every figure to workbook · sheet · row and numbers it [n].