Mike asked: memory + learning system — show me what the AI remembers and how it gets curated. 5 memory layers (reflexion, decision corpus, wiki, training loop, knowledge chunks) with the status state-machine in the middle. The curation status is what prevents poison: only approved_for_reuse rows feed retrieval. Write paths up top, read paths bottom, stacked into the LLM context block.
| Layer | Purpose | Writer | Retrieval |
|---|---|---|---|
reflexion_log | Per-run AI observations, status-curated to prevent poison | Workflow runner (R552) | WHERE status=approved_for_reuse |
decision_corpus | (situation, action, rationale) triples from approved HITL | HITL approval handler | cosine similarity topK=5 |
llm_wiki_log + docs/SYSTEM_WIKI.md | Haiku-distilled weekly knowledge | R84 nightly cron | grep by topic |
training_loop_runs | Karpathy eval cycle — 5 questions / 4h | R259 training cron | recent-N grade trends |
knowledge_chunks (ns_knowledge) | Vectorized manifest + ADRs + guide + saved searches | Bulk ingest + nightly incremental | cosine similarity topK=8 |
Reflexion entries flow through these statuses. The status field is what makes reflexion safe: chat retrieval filters on status='approved_for_reuse'. The other states protect future runs from learning the wrong thing.
| Status | Meaning | Retrieval eligible? |
|---|---|---|
needs_review | Default on insert. Awaiting Mike's triage in proposed-actions / training UI. | No |
approved_for_reuse | Mike confirmed this is a real learning. Active in retrieval. | Yes |
rejected | Mike marked it as wrong / noise. Permanent skip. | No |
expired | Auto-archived after N days without being approved. | No |
one_time_exception | Real outcome, but not generalizable. Keep for audit; don't replay. | No |
sensitive | Contains PII / vendor cost / restricted info. Redacted in retrieval. | No |
superseded | A later, better reflexion replaced this one. Kept for history only. | No |
Every chat call runs the 5 read paths in parallel and stacks them in fixed order into the system prompt:
Each layer has a ~2k token budget; layers exceeding budget are truncated tail-first. Total memory context: ~12k tokens reserved before the user message.
| Color | Meaning |
|---|---|
| frontend | User-facing surface (chat UI, admin HTML pages) |
| backend | Worker logic / agent code / business rules |
| database | D1 table / R2 object / KV key / Vectorize index |
| cloud | External system (NetSuite, Anthropic, etc.) |
| security | Gate / policy / HITL approval / kill switch |
| messagebus | Event ledger, Queues, async fan-out |
| external | Inbound source (email, webhook, cron tick, user input) |
| → solid | Synchronous call (request → response) |
| → green | Approved / happy-path |
| → red dashed | Policy or security check |
| → grey dashed | Optional / conditional / async |