# Copyright (c) 2026 CLSA contributors # SPDX-License-Identifier: MIT """Figure 2: architecture and Algorithm 1 flow for one worked decision. The decision is the canonical irreversible payment: a screenshot and an email thread disagree on the amount. """ from __future__ import annotations import matplotlib.patches as mpatches import matplotlib.pyplot as plt from matplotlib.patches import FancyArrowPatch from common import load, save, style, try_load def main() -> None: style() fig, ax = plt.subplots(figsize=(7.4, 4.6)) ax.set_xlim(0, 12) ax.set_ylim(0, 7.4) ax.axis("off") nodes = [ ("s_t = [z_t, b_t, e_t]\nscreenshot + email", 1.3, 6.3, "#d6e4f0"), ("LM proposes A_t\n(candidates only)", 1.3, 4.9, "#e8f4ea"), ("rollout p_phi(.|do(a), s_t)\nfor every a in A_t", 5.2, 6.3, "#b7d3ec"), ("RiskHead: p_hat, c_hat, rho", 5.2, 4.9, "#fdf2e9"), ("J(a) = -E[U] + gamma p_hat c_hat", 5.2, 3.5, "#f4ecf7"), ("calibrated gate\nSelectiveRisk <= alpha", 9.0, 5.6, "#8fb8dd"), ("certificate\nG, Fork, E, Bound", 9.0, 3.9, "#6396c9"), ("execute, clarify or abstain", 9.0, 2.2, "#3f6f9f"), ] pos = {} for label, x, y, colour in nodes: box = mpatches.FancyBboxPatch( (x, y - 0.55), 2.9, 1.05, boxstyle="round,pad=0.04,rounding_size=0.09", linewidth=0.8, edgecolor="#2c3e50", facecolor=colour, ) ax.add_patch(box) ax.text(x + 1.45, y, label, ha="center", va="center", fontsize=7.3) pos[label] = (x + 1.45, y) def arrow(a, b, text=None, style_="-|>"): (x1, y1), (x2, y2) = pos[a], pos[b] ax.add_patch( FancyArrowPatch( (x1, y1 - 0.58), (x2, y2 + 0.58), arrowstyle=style_, mutation_scale=10, lw=0.9, color="#2c3e50", connectionstyle="arc3,rad=0.06", ) ) if text: ax.text((x1 + x2) / 2 + 0.1, (y1 + y2) / 2, text, fontsize=6.4, color="#566573") keys = [n[0] for n in nodes] arrow(keys[0], keys[1]) arrow(keys[1], keys[2]) arrow(keys[2], keys[3]) arrow(keys[3], keys[4]) arrow(keys[4], keys[5], "in band -> simulate") arrow(keys[5], keys[6]) arrow(keys[6], keys[7]) ax.text( 1.3, 0.5, "Worked case: email says GBP 40, invoice screenshot reads GBP 67. " "e_t flags cross-modal conflict, so the mode is verify/acquire before execute.", fontsize=6.8, style="italic", color="#34495e", ) save(fig, "fig2_algorithm") # Figure 3 depends on E2 existing; skip silently if not yet run. e2 = try_load("e2_world_model") if e2 is None: print("fig3 skipped: no e2 results yet") return if __name__ == "__main__": main()