Architecture
From the business scenario down to the running code, top-down. The target layer is drawn first; what this demo implements of it is marked, and what it leaves out is said.
1. The target orchestration layer
flowchart TB
subgraph Channels
UI[Platform UI / assistant]
API[Decision APIs]
end
subgraph Orchestration["Governed orchestration layer"]
GW[Gateway: SSO, roles, quotas, budget]
ORCH[Orchestrator: plan, sub-agents, durable state, retry / resume]
POL[Policy engine: permissions, approval checkpoints, guardrails]
LEDGER[Execution ledger and audit]
EVAL[Evaluation: reference cases, online metrics]
MEM[Memory and context: case, knowledge, rules]
end
subgraph Registry["Governed MCP tool registry"]
T1[docs.search]
T2[data.reconcile / assumptions.diff]
T3[run.submit / run.results]
T4[results.compare]
T5[note.publish / change.review]
end
subgraph Platform
LLM[LLM gateway, multi-provider]
OBS[Observability: traces, metrics]
K8S[Kubernetes, queues, switchable environments]
end
subgraph Existing["Actuarial systems"]
ENGINE[Modeling engine]
GRID[Compute grid]
DATA[Data links]
end
UI --> GW --> ORCH
API --> GW
ORCH <--> POL
ORCH --> LEDGER
ORCH <--> MEM
ORCH --> EVAL
ORCH --> Registry
Registry --> ENGINE
Registry --> GRID
Registry --> DATA
ORCH --> LLM
Orchestration --> OBS
2. What this demo implements
| Layer component | In the demo | Left out, on purpose |
|---|---|---|
| Orchestrator | A LangGraph state graph with a SQLite checkpointer: durable state per case, an interrupt at the approval gate, resume by Command. | Sub-agents as separate graphs, retries on real failures, queues. |
| Policy engine | app/policy.py: effects (read, compute, write, publish), roles, approval requirement, compute budget, output guardrail on the note. | Externalised policy store, per-tenant rules. |
| Tool registry | app/registry.py: contracts with effect, version, owner; every call goes through policy and ledger. Served over MCP by app/mcp_server.py. | Entitlements per client, tool versioning workflow. |
| Execution ledger | app/ledger.py: append-only SQLite, live stream to the UI, export per case. | Retention policy, SIEM export. |
| Evaluation | The ledger carries everything an offline evaluation needs; the verification node is the first online check. | Reference case suite and judge. |
| LLM gateway | init_chat_model: the provider is a configuration value. Two calls per case. | Routing, caching, cost caps per tenant. |
| Actuarial systems | A deterministic simulator (app/axis_sim.py): datasets, assumptions, runs, grid cost, documentation base. | Everything real. |
| Deployment | One container behind the platform's reverse proxy, on a shared Docker network. | Kubernetes, switchable environments. |
3. The case graph
flowchart LR
S([start]) --> gather
gather --> plan
plan -->|controls ok| gate
plan -->|controls failed| E([end])
gate -->|approved| execute
gate -->|rejected| E
execute --> attribute --> draft --> verify --> E
classDef llm fill:#fde68a,stroke:#b45309,color:#111;
classDef human fill:#bfdbfe,stroke:#1d4ed8,color:#111;
class plan,draft llm;
class gate human;
Yellow nodes call the language model. The blue node is the human approval checkpoint; the graph is interrupted there and the state is saved. Every other node is deterministic code calling the registry.
4. How a case travels through the layers
- The actuary opens a case with a question. The ledger records it.
- gather calls
run.metadatatwice,data.reconcile,assumptions.diffanddocs.search. Each call is first evaluated by the policy engine (read effects pass), then recorded with its arguments, result and fingerprint. - plan gives the model the facts, not the data: it returns a structured plan restricted to the four canonical decomposition steps. The graph normalises the order.
plan.costprices it. - gate checks the budget, records an approval request and interrupts. The case holds no thread while it waits.
- The actuary approves or rejects in the UI. The decision is recorded and the graph resumes from its checkpoint.
- execute submits each run through
run.submit, the only tool with a compute effect, now allowed because the approval is on the case. - attribute calls
results.compare: the step-by-step waterfall, with the unexplained residual. - draft asks the model for the note, with the attribution, the controls and the sources. verify checks every figure and citation against the record; a note that fails stays a draft.
5. Why these choices
- LangGraph for the graph: explicit state, checkpointing and interrupts are the hard parts of an agent that waits for people; the intelligence is in the tools and in the two model calls, not in the framework.
- MCP for the tools: the registry is the stable boundary. The runtime can change; the contracts, policy and ledger stay.
- Deterministic first: reconciliation, cost, attribution and verification are code with tests. A model that counted would be a liability in a regulated context.
- Approval where the effect engages: compute, write and publish effects stop the graph; read effects do not. The actuary stays in control of every decision, and the record proves it.