[{"data":1,"prerenderedAt":1042},["ShallowReactive",2],{"\u002Farticles\u002Fagent-hitl-two-phase-commit":3},{"id":4,"title":5,"body":6,"date":1027,"description":1028,"extension":1029,"head":1030,"image":1031,"meta":1032,"navigation":431,"ogImage":1030,"path":1033,"rating":195,"readingTime":1034,"robots":1030,"schemaOrg":1030,"seo":1035,"sitemap":1036,"stem":1037,"tags":1038,"__hash__":1041},"articles_en\u002Farticles\u002Fagent-hitl-two-phase-commit.md","Why an AI Agent's \"Commit\" Decision Can't Be Left to the LLM — Production-Grade HITL with Two-Phase Interception and Four Lines of Defense",{"type":7,"value":8,"toc":1016},"minimark",[9,25,30,33,36,47,53,57,72,145,155,158,259,264,274,278,281,303,306,310,317,335,342,352,389,393,399,406,412,458,463,524,531,537,540,543,625,629,635,641,647,656,662,669,689,692,772,776,783,793,823,843,850,854,969,976,980,1006,1012],[10,11,12],"note",{},[13,14,15,16,20,21,24],"p",{},"The thesis in one sentence: ",[17,18,19],"strong",{},"in an agent whose actions have irreversible consequences, the decision of \"should this actually be executed\" cannot be left to the LLM."," Using a production marketing agent (an assistant for a \"referral reward campaign\") as the example, this post explains why you need a \"confirmation intercept\" outside the LLM, how the two-phase commit is implemented, and the ",[17,22,23],{},"four lines of defense that are really running"," behind it. To avoid leaking implementation details, I use role-based names in place of real module names, and the code is reduced to a few pieces of pseudocode that carry the point.",[26,27,29],"h2",{"id":28},"_1-start-with-a-bug","1. Start with a bug",[13,31,32],{},"A merchant has chatted with the bot for a few turns on an IM channel and has pulled up a preview of a \"referral reward campaign\". The bot asks: \"Would you like to adjust the tier-two reward a bit more?\" The merchant replies: \"OK.\"",[13,34,35],{},"What does that \"OK\" mean? Is it \"OK, I want to change tier two\", or \"OK, go ahead and submit it as is\"?",[13,37,38,39,42,43,46],{},"If you hand this judgment to the LLM, there is a decent chance it guesses wrong. And the cost of guessing wrong is ",[17,40,41],{},"asymmetric",": guess \"change\" and the worst case is one extra question; guess \"submit\" and you have just ",[17,44,45],{},"pushed a campaign the merchant hadn't finished thinking through straight to production"," — an irreversible write.",[13,48,49,50],{},"That is the core question of this post: ",[17,51,52],{},"in human-AI collaboration (HITL, Human-in-the-Loop), should the \"commit\" decision be left to the LLM at all?",[26,54,56],{"id":55},"_2-background-what-kind-of-agent-is-this","2. Background: what kind of agent is this",[13,58,59,60,63,64,71],{},"It is a marketing assistant running on IM channels. The merchant talks to it in plain natural language, and it helps the merchant ",[17,61,62],{},"create \u002F edit \u002F enable"," a \"referral reward\" campaign. Technically it is a ReAct agent built on ",[17,65,66,67],{},"LangGraph's ",[68,69,70],"code",{},"create_react_agent",", with 6 tools attached (listed by responsibility):",[73,74,75,88],"table",{},[76,77,78],"thead",{},[79,80,81,85],"tr",{},[82,83,84],"th",{},"Tool (by responsibility)",[82,86,87],{},"Read \u002F Write",[89,90,91,100,107,114,126,133],"tbody",{},[79,92,93,97],{},[94,95,96],"td",{},"Recommend a plan (based on past campaigns + available coupons)",[94,98,99],{},"Read",[79,101,102,105],{},[94,103,104],{},"Look up the coupon library (attached coupons can only come from here, so the LLM cannot invent coupon IDs)",[94,106,99],{},[79,108,109,112],{},[94,110,111],{},"Look up member types \u002F levels",[94,113,99],{},[79,115,116,121],{},[94,117,118],{},[17,119,120],{},"Create campaign",[94,122,123],{},[17,124,125],{},"Write",[79,127,128,131],{},[94,129,130],{},"Look up existing campaigns (the status determines what can be edited)",[94,132,99],{},[79,134,135,141],{},[94,136,137,140],{},[17,138,139],{},"Modify \u002F enable campaign"," (one tool, three operations)",[94,142,143],{},[17,144,125],{},[13,146,147,148,151,152],{},"The key point: \"create\" and \"modify \u002F enable\" are ",[17,149,150],{},"write operations"," that really do create or change a live campaign in the backend. That is completely different from a read-only agent that \"checks the weather\" or \"summarizes a paragraph\" — ",[17,153,154],{},"a wrong read can be retried; a wrong write is an incident.",[13,156,157],{},"The whole agent is strictly split into three layers, with deterministic code and the LLM each owning their own stretch:",[159,160,165],"pre",{"className":161,"code":162,"language":163,"meta":164,"style":164},"language-mermaid shiki shiki-themes github-light github-dark github-dark","flowchart TD\n  U([\"Merchant · IM channel\"]):::entry --> RT[\"Intent routing layer\u003Cbr>classification · sticky session · command short-circuit\"]:::det\n  RT --> SK[\"① I\u002FO orchestration layer\u003Cbr>lock · restore session · confirmation intercept · wrap-up\"]:::det\n  SK --> IC{\"Pending preview exists\u003Cbr>and this turn looks like a confirmation?\"}:::det\n  IC -->|Yes| ITC[\"Confirmation intercept (deterministic)\u003Cbr>4-way classification → commit directly\"]:::det\n  IC -->|No| RA[\"② ReAct orchestration layer\u003Cbr>create_react_agent\"]:::llm\n  RA --> TOOLS[\"③ Business tools (6)\u003Cbr>preview: assemble \u002F validate \u002F stash\"]:::llm\n  ITC --> BE[(\"Backend · campaign write API\")]:::ext\n  TOOLS --> BE\n  SK \u003C--> RDS[(\"Session store (Redis)\")]:::store\n  classDef entry fill:#DBEAFE,stroke:#2563EB,color:#1E3A8A\n  classDef det fill:#DCFCE7,stroke:#16A34A,color:#14532D\n  classDef llm fill:#FEF3C7,stroke:#D97706,color:#78350F\n  classDef ext fill:#E5E7EB,stroke:#6B7280,color:#374151\n  classDef store fill:#EDE9FE,stroke:#7C3AED,color:#4C1D95\n","mermaid","",[68,166,167,175,181,187,193,199,205,211,217,223,229,235,241,247,253],{"__ignoreMap":164},[168,169,172],"span",{"class":170,"line":171},"line",1,[168,173,174],{},"flowchart TD\n",[168,176,178],{"class":170,"line":177},2,[168,179,180],{},"  U([\"Merchant · IM channel\"]):::entry --> RT[\"Intent routing layer\u003Cbr>classification · sticky session · command short-circuit\"]:::det\n",[168,182,184],{"class":170,"line":183},3,[168,185,186],{},"  RT --> SK[\"① I\u002FO orchestration layer\u003Cbr>lock · restore session · confirmation intercept · wrap-up\"]:::det\n",[168,188,190],{"class":170,"line":189},4,[168,191,192],{},"  SK --> IC{\"Pending preview exists\u003Cbr>and this turn looks like a confirmation?\"}:::det\n",[168,194,196],{"class":170,"line":195},5,[168,197,198],{},"  IC -->|Yes| ITC[\"Confirmation intercept (deterministic)\u003Cbr>4-way classification → commit directly\"]:::det\n",[168,200,202],{"class":170,"line":201},6,[168,203,204],{},"  IC -->|No| RA[\"② ReAct orchestration layer\u003Cbr>create_react_agent\"]:::llm\n",[168,206,208],{"class":170,"line":207},7,[168,209,210],{},"  RA --> TOOLS[\"③ Business tools (6)\u003Cbr>preview: assemble \u002F validate \u002F stash\"]:::llm\n",[168,212,214],{"class":170,"line":213},8,[168,215,216],{},"  ITC --> BE[(\"Backend · campaign write API\")]:::ext\n",[168,218,220],{"class":170,"line":219},9,[168,221,222],{},"  TOOLS --> BE\n",[168,224,226],{"class":170,"line":225},10,[168,227,228],{},"  SK \u003C--> RDS[(\"Session store (Redis)\")]:::store\n",[168,230,232],{"class":170,"line":231},11,[168,233,234],{},"  classDef entry fill:#DBEAFE,stroke:#2563EB,color:#1E3A8A\n",[168,236,238],{"class":170,"line":237},12,[168,239,240],{},"  classDef det fill:#DCFCE7,stroke:#16A34A,color:#14532D\n",[168,242,244],{"class":170,"line":243},13,[168,245,246],{},"  classDef llm fill:#FEF3C7,stroke:#D97706,color:#78350F\n",[168,248,250],{"class":170,"line":249},14,[168,251,252],{},"  classDef ext fill:#E5E7EB,stroke:#6B7280,color:#374151\n",[168,254,256],{"class":170,"line":255},15,[168,257,258],{},"  classDef store fill:#EDE9FE,stroke:#7C3AED,color:#4C1D95\n",[10,260,261],{},[13,262,263],{},"Color legend (shared by all diagrams below): 🟩 green = deterministic code (orchestration \u002F interception \u002F gates) | 🟨 yellow = LLM \u002F agent \u002F tools | 🟪 purple = state storage | ⬜ gray = external backend | 🟦 blue = entry point",[13,265,266,267,269,270,273],{},"One implementation detail worth spelling out: the main reasoning runs on LangGraph's ",[68,268,70],{},"; deciding \"is this a confirmation\" uses ",[17,271,272],{},"the same LLM configuration, just as a \"lightweight call\" with the output token limit squeezed very low"," — it is not a different, cheaper model, only a cap on output length.",[26,275,277],{"id":276},"_3-why-the-naive-approach-doesnt-work","3. Why the naive approach doesn't work",[13,279,280],{},"The most intuitive approach: give the LLM a \"submit\" tool and let it judge for itself when the merchant has \"confirmed\", then call it. Three problems:",[282,283,284,291,297],"ol",{},[285,286,287,290],"li",{},[17,288,289],{},"Semantic ambiguity."," \"OK \u002F fine \u002F sure \u002F that's it\" can mean opposite things in different contexts. The very same \"confirm\" means \"change\" when it follows \"do you want to change X\", and only means \"submit\" when it follows \"here is the preview, do you confirm?\".",[285,292,293,296],{},[17,294,295],{},"Asymmetric cost."," A false submit is far worse than a missed submit (a live campaign gets created in the backend out of thin air). But the LLM's loss function has no such asymmetry — it is just \"trying to guess right\".",[285,298,299,302],{},[17,300,301],{},"Not reproducible."," The same sentence may be guessed differently next time, so when something goes wrong it is hard to reproduce and hard to attribute.",[13,304,305],{},"In one sentence: handing a decision where \"one mistake is an incident\" to a probabilistic black box is not a good idea.",[26,307,309],{"id":308},"_4-core-design-take-commit-out-of-the-llms-hands-dry_run-commit-two-phase","4. Core design: take \"commit\" out of the LLM's hands (dry_run \u002F commit two-phase)",[13,311,312,313,316],{},"Split the flow into two calls that go down ",[17,314,315],{},"different code paths",":",[318,319,320,326],"ul",{},[285,321,322,325],{},[17,323,324],{},"dry_run (preview) belongs to the LLM."," Every time the LLM calls the \"create\" tool it is a dry_run: it interprets natural language into a structured config, assembles it, validates it, generates a preview (text + PDF), and stashes the pending content in the session. If this phase gets something wrong, the preview is merely inaccurate, and regenerating fixes it.",[285,327,328,331,332],{},[17,329,330],{},"commit belongs to deterministic code."," Only that code can actually send the stashed content to the backend. ",[17,333,334],{},"The LLM never holds the right to commit.",[13,336,337,338,341],{},"This iron rule lands on a single ",[17,339,340],{},"boolean switch"," in the tool's input: it is off by default, and its field description says so to the LLM directly — \"never touch this field; only the system's confirmation intercept sets it to true\". The tool branches on it internally: only when the switch is true, the stash exists, and the name matches the stash does it really call the backend write API; otherwise it always takes the preview path and never touches the backend.",[13,343,344,345,348,349,316],{},"The most counterintuitive, and most important, point: ",[17,346,347],{},"the interception happens before the LLM."," For every incoming message, first check whether the session has a \"pending preview\"; if so, first decide whether this turn is a confirmation, and if it is, commit directly — ",[17,350,351],{},"without ever entering the ReAct loop",[159,353,357],{"className":354,"code":355,"language":356,"meta":164,"style":164},"language-py shiki shiki-themes github-light github-dark github-dark","# Message entry point: intercept before ReAct (pseudocode)\nintercepted = confirm_intercept(session, text)\nif intercepted is not None:\n    result = intercepted          # confirmation hit → commit directly, skip the LLM\nelse:\n    result = run_react_turn(state)  # only otherwise go through ReAct\n","py",[68,358,359,364,369,374,379,384],{"__ignoreMap":164},[168,360,361],{"class":170,"line":171},[168,362,363],{},"# Message entry point: intercept before ReAct (pseudocode)\n",[168,365,366],{"class":170,"line":177},[168,367,368],{},"intercepted = confirm_intercept(session, text)\n",[168,370,371],{"class":170,"line":183},[168,372,373],{},"if intercepted is not None:\n",[168,375,376],{"class":170,"line":189},[168,377,378],{},"    result = intercepted          # confirmation hit → commit directly, skip the LLM\n",[168,380,381],{"class":170,"line":195},[168,382,383],{},"else:\n",[168,385,386],{"class":170,"line":201},[168,387,388],{},"    result = run_react_turn(state)  # only otherwise go through ReAct\n",[26,390,392],{"id":391},"_5-how-to-decide-is-this-a-confirmation-whitelist-4-way-classification-safety-bias","5. How to decide \"is this a confirmation\": whitelist + 4-way classification + safety bias",[394,395,396],"blockquote",{},[13,397,398],{},"Wait — doesn't deciding \"is this a confirmation\" still require the LLM?",[13,400,401,402,405],{},"Yes, but it is used differently: we don't let the LLM \"decide whether to commit\", we only let it do a ",[17,403,404],{},"narrow, well-defined classification",", and we hard-code \"which side to fall toward when unsure\".",[13,407,408,411],{},[17,409,410],{},"Step one: a hard-rule fast path."," Strict affirmative phrases (a whitelist plus a length guard); a hit is classified as SUBMIT immediately, without even calling the LLM:",[159,413,415],{"className":354,"code":414,"language":356,"meta":164,"style":164},"# Pseudocode\nSTRICT_CONFIRM = {\"确认创建\", \"确认提交\", \"confirm create\", ...}\n\ndef is_strict_confirm(text):\n    t = text.strip().lower().rstrip(\"。.!?~ \")\n    if not t or len(t) > 25:     # anything over 25 characters is never a \"crisp confirmation\"\n        return False\n    return t in STRICT_CONFIRM\n",[68,416,417,422,427,433,438,443,448,453],{"__ignoreMap":164},[168,418,419],{"class":170,"line":171},[168,420,421],{},"# Pseudocode\n",[168,423,424],{"class":170,"line":177},[168,425,426],{},"STRICT_CONFIRM = {\"确认创建\", \"确认提交\", \"confirm create\", ...}\n",[168,428,429],{"class":170,"line":183},[168,430,432],{"emptyLinePlaceholder":431},true,"\n",[168,434,435],{"class":170,"line":189},[168,436,437],{},"def is_strict_confirm(text):\n",[168,439,440],{"class":170,"line":195},[168,441,442],{},"    t = text.strip().lower().rstrip(\"。.!?~ \")\n",[168,444,445],{"class":170,"line":201},[168,446,447],{},"    if not t or len(t) > 25:     # anything over 25 characters is never a \"crisp confirmation\"\n",[168,449,450],{"class":170,"line":207},[168,451,452],{},"        return False\n",[168,454,455],{"class":170,"line":213},[168,456,457],{},"    return t in STRICT_CONFIRM\n",[13,459,460],{},[17,461,462],{},"Step two: only ambiguous cases go through a lightweight LLM classifier, which picks one of four:",[73,464,465,478],{},[76,466,467],{},[79,468,469,472,475],{},[82,470,471],{},"Class",[82,473,474],{},"Meaning",[82,476,477],{},"Action",[89,479,480,491,502,513],{},[79,481,482,485,488],{},[94,483,484],{},"SUBMIT",[94,486,487],{},"Confirms submitting the preview already shown",[94,489,490],{},"Commit",[79,492,493,496,499],{},[94,494,495],{},"PREVIEW_AGAIN",[94,497,498],{},"Regenerate the preview with the latest changes",[94,500,501],{},"Unlock, regenerate",[79,503,504,507,510],{},[94,505,506],{},"CHANGE",[94,508,509],{},"Yet another new modification",[94,511,512],{},"Stay locked, accumulate, no preview",[79,514,515,518,521],{},[94,516,517],{},"OTHER",[94,519,520],{},"Greeting \u002F cancel \u002F question \u002F off-topic",[94,522,523],{},"Stay locked, reply normally",[13,525,526,527,530],{},"The classifier uses ",[17,528,529],{},"the bot's previous reply"," to disambiguate — a \"confirm\" that follows \"a proposed direction for changes\" is PREVIEW_AGAIN, and only one that follows \"a review request for a preview already shown\" is SUBMIT. And the most important principle is written into the classification prompt, explicitly encoding the \"asymmetric cost\" as a preference:",[532,533,534],"warning",{},[13,535,536],{},"When unsure, prefer PREVIEW_AGAIN over SUBMIT — the cost of a false submit is far greater than generating one more preview.",[13,538,539],{},"Only a SUBMIT result commits; only PREVIEW_AGAIN unlocks regeneration, while CHANGE \u002F OTHER always stay locked and accumulate. This turns \"asymmetric cost\" from a slogan into a hard bias in the code.",[13,541,542],{},"The full decision flow of the confirmation intercept:",[159,544,546],{"className":161,"code":545,"language":163,"meta":164,"style":164},"flowchart TD\n  IN([\"New message arrives\"]):::entry --> HAS{\"Pending preview exists?\"}:::det\n  HAS -->|No| RUN[\"Normal ReAct path\"]:::llm\n  HAS -->|Yes| STRICT{\"Strict affirmative phrase?\u003Cbr>确认创建 \u002F confirm create\"}:::det\n  STRICT -->|Yes| SUBMIT[\"Verdict = SUBMIT\"]:::det\n  STRICT -->|No| LLM[\"Lightweight LLM 4-way classification\u003Cbr>disambiguated by the previous reply\"]:::llm\n  LLM --> CLS{\"Classification result\"}:::det\n  CLS -->|SUBMIT| SUBMIT\n  CLS -->|PREVIEW_AGAIN| UNLOCK[\"Unlock → regenerate preview\"]:::llm\n  CLS -->|CHANGE \u002F OTHER| LOCK[\"Stay locked → accumulate \u002F chat\"]:::llm\n  SUBMIT --> DISP{\"Which pending item is non-empty?\u003Cbr>modify takes priority\"}:::det\n  DISP -->|Modify| CM[\"Commit: modify \u002F enable\"]:::det\n  DISP -->|Create| CC[\"Commit: create\"]:::det\n  classDef entry fill:#DBEAFE,stroke:#2563EB,color:#1E3A8A\n  classDef det fill:#DCFCE7,stroke:#16A34A,color:#14532D\n  classDef llm fill:#FEF3C7,stroke:#D97706,color:#78350F\n",[68,547,548,552,557,562,567,572,577,582,587,592,597,602,607,612,616,620],{"__ignoreMap":164},[168,549,550],{"class":170,"line":171},[168,551,174],{},[168,553,554],{"class":170,"line":177},[168,555,556],{},"  IN([\"New message arrives\"]):::entry --> HAS{\"Pending preview exists?\"}:::det\n",[168,558,559],{"class":170,"line":183},[168,560,561],{},"  HAS -->|No| RUN[\"Normal ReAct path\"]:::llm\n",[168,563,564],{"class":170,"line":189},[168,565,566],{},"  HAS -->|Yes| STRICT{\"Strict affirmative phrase?\u003Cbr>确认创建 \u002F confirm create\"}:::det\n",[168,568,569],{"class":170,"line":195},[168,570,571],{},"  STRICT -->|Yes| SUBMIT[\"Verdict = SUBMIT\"]:::det\n",[168,573,574],{"class":170,"line":201},[168,575,576],{},"  STRICT -->|No| LLM[\"Lightweight LLM 4-way classification\u003Cbr>disambiguated by the previous reply\"]:::llm\n",[168,578,579],{"class":170,"line":207},[168,580,581],{},"  LLM --> CLS{\"Classification result\"}:::det\n",[168,583,584],{"class":170,"line":213},[168,585,586],{},"  CLS -->|SUBMIT| SUBMIT\n",[168,588,589],{"class":170,"line":219},[168,590,591],{},"  CLS -->|PREVIEW_AGAIN| UNLOCK[\"Unlock → regenerate preview\"]:::llm\n",[168,593,594],{"class":170,"line":225},[168,595,596],{},"  CLS -->|CHANGE \u002F OTHER| LOCK[\"Stay locked → accumulate \u002F chat\"]:::llm\n",[168,598,599],{"class":170,"line":231},[168,600,601],{},"  SUBMIT --> DISP{\"Which pending item is non-empty?\u003Cbr>modify takes priority\"}:::det\n",[168,603,604],{"class":170,"line":237},[168,605,606],{},"  DISP -->|Modify| CM[\"Commit: modify \u002F enable\"]:::det\n",[168,608,609],{"class":170,"line":243},[168,610,611],{},"  DISP -->|Create| CC[\"Commit: create\"]:::det\n",[168,613,614],{"class":170,"line":249},[168,615,234],{},[168,617,618],{"class":170,"line":255},[168,619,240],{},[168,621,623],{"class":170,"line":622},16,[168,624,246],{},[26,626,628],{"id":627},"_6-more-than-interception-four-lines-of-defense-that-really-run","6. More than interception: four lines of defense that really run",[13,630,631,632,316],{},"Interception alone is not enough. In production there are several more scenarios where \"stale state gets submitted by mistake\", so multiple layers of defense are stacked on top. I only list the ones that ",[17,633,634],{},"the code really executes",[13,636,637,640],{},[17,638,639],{},"Defense ① Confirmation intercept + 4-way classification"," (covered above) — guards against \"an ambiguous reply being treated as a submit\". It is the only one that uses the LLM, and a \"constrained LLM\" at that.",[13,642,643,646],{},[17,644,645],{},"Defense ② Closure gate + accumulation lock."," Both are deterministic gates, and both return before any write or state change. Once a preview exists, each change the merchant makes does not trigger an immediate regeneration; it is accumulated first: as long as the merchant \"hasn't explicitly closed out\" or \"this turn was classified as a change \u002F small talk\", preview generation is turned back directly — no new preview, and certainly no backend call — until the merchant plainly says \"that's it\".",[13,648,649,652,653],{},[17,650,651],{},"Defense ③ Triple commit condition + name check."," Even if the LLM oversteps and flips that commit switch, the commit only happens when \"the stash exists + the name matches the stash\"; otherwise it degrades to a preview. ",[17,654,655],{},"The only legitimate entry point that triggers a commit is the deterministic confirmation intercept.",[13,657,658,661],{},[17,659,660],{},"Defense ④ Cold-start guard on switching."," When the conversation switches back from another scenario, any leftover pending preview is cleared; otherwise an offhand \"restart-like phrase\" from the merchant could be misjudged and push a stale preview left over from the previous scenario to production.",[13,663,664,665,668],{},"Plus one state-integrity constraint: ",[17,666,667],{},"the \"create\" and \"modify\" pending contents are mutually exclusive"," — writing either new preview clears the other, otherwise the confirmation intercept wouldn't know which one to commit (inside the intercept, modify takes priority, then create).",[670,671,672],"caution",{},[13,673,674,677,678,681,682,685,686],{},[17,675,676],{},"An honest engineering detail (design intent ≠ what shipped)."," The code also has a \"message sequence number\" field that was meant to be a fifth line of defense, the intent being \"use the message sequence number to judge an old preview as expired and refuse to commit it\". But I went through every reference to it in the code, one by one: ",[17,679,680],{},"it is only ever written, never read or compared",", so this defense ",[17,683,684],{},"is currently not actually wired up and not in effect",". Staleness is in practice covered by the mechanisms above: \"the CHANGE lock accumulates without committing + closing out rebuilds a new preview (the old one is discarded) + cleanup on switching\". I'm writing this down to make a point: ",[17,687,688],{},"to judge whether a defense holds, look at whether the code actually reads it, not at how well the field is named.",[13,690,691],{},"The session state machine (state lives in an external cache, remembering across turns \"what was previewed last turn\"):",[159,693,695],{"className":161,"code":694,"language":163,"meta":164,"style":164},"stateDiagram-v2\n  [*] --> Idle\n  Idle --> PendingCreate: create preview (dry_run)\n  Idle --> PendingModify: modify preview (dry_run)\n  PendingCreate --> PendingCreate: CHANGE accumulates, preview rebuilt\n  PendingModify --> PendingModify: CHANGE accumulates, preview rebuilt\n  PendingCreate --> Committed: confirmation intercept SUBMIT\n  PendingModify --> Committed: confirmation intercept SUBMIT\n  Committed --> Idle: clear pending, record \"last committed\"\n  PendingCreate --> Idle: cleared on switch\n  PendingModify --> Idle: cleared on switch\n  note right of PendingModify\n    Create \u002F modify pending items are mutually exclusive\n    writing a new preview clears the other\n  end note\n",[68,696,697,702,707,712,717,722,727,732,737,742,747,752,757,762,767],{"__ignoreMap":164},[168,698,699],{"class":170,"line":171},[168,700,701],{},"stateDiagram-v2\n",[168,703,704],{"class":170,"line":177},[168,705,706],{},"  [*] --> Idle\n",[168,708,709],{"class":170,"line":183},[168,710,711],{},"  Idle --> PendingCreate: create preview (dry_run)\n",[168,713,714],{"class":170,"line":189},[168,715,716],{},"  Idle --> PendingModify: modify preview (dry_run)\n",[168,718,719],{"class":170,"line":195},[168,720,721],{},"  PendingCreate --> PendingCreate: CHANGE accumulates, preview rebuilt\n",[168,723,724],{"class":170,"line":201},[168,725,726],{},"  PendingModify --> PendingModify: CHANGE accumulates, preview rebuilt\n",[168,728,729],{"class":170,"line":207},[168,730,731],{},"  PendingCreate --> Committed: confirmation intercept SUBMIT\n",[168,733,734],{"class":170,"line":213},[168,735,736],{},"  PendingModify --> Committed: confirmation intercept SUBMIT\n",[168,738,739],{"class":170,"line":219},[168,740,741],{},"  Committed --> Idle: clear pending, record \"last committed\"\n",[168,743,744],{"class":170,"line":225},[168,745,746],{},"  PendingCreate --> Idle: cleared on switch\n",[168,748,749],{"class":170,"line":231},[168,750,751],{},"  PendingModify --> Idle: cleared on switch\n",[168,753,754],{"class":170,"line":237},[168,755,756],{},"  note right of PendingModify\n",[168,758,759],{"class":170,"line":243},[168,760,761],{},"    Create \u002F modify pending items are mutually exclusive\n",[168,763,764],{"class":170,"line":249},[168,765,766],{},"    writing a new preview clears the other\n",[168,768,769],{"class":170,"line":255},[168,770,771],{},"  end note\n",[26,773,775],{"id":774},"_7-two-error-proofing-details-the-same-deterministic-philosophy","7. Two \"error-proofing\" details: the same deterministic philosophy",[13,777,778,779,782],{},"Converge the \"error-prone spots\" into a ",[17,780,781],{},"single point"," in deterministic code, rather than scattering them everywhere, and certainly rather than handing them to the LLM — the same thinking shows up in two places in the data modeling:",[13,784,785,788,789,792],{},[17,786,787],{},"① Unit conversion happens exactly once."," The backend stores points in units of 0.01, and the frontend stores \"input value ×100\". So internally everything uses integers from the merchant's point of view, with ×100 applied uniformly at ",[17,790,791],{},"the one place where the outbound payload is assembled",", and \u002F\u002F100 applied uniformly when reading back from the backend. The benefit: interpretation, preview, and validation all use human-readable integers, and there is no ×100 sprinkled around waiting to be missed.",[13,794,795,806,807,809,810,812,813,815,816,819,820,316],{},[17,796,797,798,801,802,805],{},"② The ",[68,799,800],{},"None"," vs ",[68,803,804],{},"0"," sentinel."," Optional numeric values use ",[68,808,800],{}," to tell \"not passed\" apart from \"passed as 0\": ",[68,811,800],{}," = \"the LLM didn't pass it\" → fall back to the default; ",[68,814,804],{}," = \"the merchant explicitly said no reward on this side\" → keep 0. So the check has to be ",[68,817,818],{},"is None",", not ",[68,821,822],{},"not x",[159,824,826],{"className":354,"code":825,"language":356,"meta":164,"style":164},"# Pseudocode: the fallback only happens when \"not passed\"; an explicit 0 is respected\nif cfg.get(\"points\") is None:\n    cfg[\"points\"] = DEFAULT_POINTS\n",[68,827,828,833,838],{"__ignoreMap":164},[168,829,830],{"class":170,"line":171},[168,831,832],{},"# Pseudocode: the fallback only happens when \"not passed\"; an explicit 0 is respected\n",[168,834,835],{"class":170,"line":177},[168,836,837],{},"if cfg.get(\"points\") is None:\n",[168,839,840],{"class":170,"line":183},[168,841,842],{},"    cfg[\"points\"] = DEFAULT_POINTS\n",[13,844,845,846,849],{},"With an ordinary ",[68,847,848],{},"= default",", you can't tell \"didn't say\" from \"said no\".",[26,851,853],{"id":852},"_8-one-complete-round","8. One complete round",[159,855,857],{"className":161,"code":856,"language":163,"meta":164,"style":164},"sequenceDiagram\n  autonumber\n  actor M as Merchant\n  participant S as Orchestration layer (deterministic)\n  participant A as ReAct Agent (LLM)\n  participant B as Backend\n  M->>A: \"50 points for inviting 3 people\"\n  A->>A: dry_run - assemble + validate + stash\n  A-->>M: Preview + PDF (please confirm)\n  M->>S: \"Raise tier two to 300\"\n  Note over S: 4-way classification = CHANGE → stay locked, accumulate\n  S-->>M: \"Got it, anything else to change?\"\n  M->>S: \"That's it\"\n  Note over S: Close out → regenerate preview (old one discarded)\n  S->>A: dry_run (closure=True)\n  A-->>M: New preview\n  M->>S: \"confirm create\"\n  Note over S: Strict affirmative phrase → SUBMIT (bypasses the LLM)\n  S->>B: Commit\n  B-->>S: ok\n  S-->>M: Created ✅ (draft state)\n",[68,858,859,864,869,874,879,884,889,894,899,904,909,914,919,924,929,934,939,945,951,957,963],{"__ignoreMap":164},[168,860,861],{"class":170,"line":171},[168,862,863],{},"sequenceDiagram\n",[168,865,866],{"class":170,"line":177},[168,867,868],{},"  autonumber\n",[168,870,871],{"class":170,"line":183},[168,872,873],{},"  actor M as Merchant\n",[168,875,876],{"class":170,"line":189},[168,877,878],{},"  participant S as Orchestration layer (deterministic)\n",[168,880,881],{"class":170,"line":195},[168,882,883],{},"  participant A as ReAct Agent (LLM)\n",[168,885,886],{"class":170,"line":201},[168,887,888],{},"  participant B as Backend\n",[168,890,891],{"class":170,"line":207},[168,892,893],{},"  M->>A: \"50 points for inviting 3 people\"\n",[168,895,896],{"class":170,"line":213},[168,897,898],{},"  A->>A: dry_run - assemble + validate + stash\n",[168,900,901],{"class":170,"line":219},[168,902,903],{},"  A-->>M: Preview + PDF (please confirm)\n",[168,905,906],{"class":170,"line":225},[168,907,908],{},"  M->>S: \"Raise tier two to 300\"\n",[168,910,911],{"class":170,"line":231},[168,912,913],{},"  Note over S: 4-way classification = CHANGE → stay locked, accumulate\n",[168,915,916],{"class":170,"line":237},[168,917,918],{},"  S-->>M: \"Got it, anything else to change?\"\n",[168,920,921],{"class":170,"line":243},[168,922,923],{},"  M->>S: \"That's it\"\n",[168,925,926],{"class":170,"line":249},[168,927,928],{},"  Note over S: Close out → regenerate preview (old one discarded)\n",[168,930,931],{"class":170,"line":255},[168,932,933],{},"  S->>A: dry_run (closure=True)\n",[168,935,936],{"class":170,"line":622},[168,937,938],{},"  A-->>M: New preview\n",[168,940,942],{"class":170,"line":941},17,[168,943,944],{},"  M->>S: \"confirm create\"\n",[168,946,948],{"class":170,"line":947},18,[168,949,950],{},"  Note over S: Strict affirmative phrase → SUBMIT (bypasses the LLM)\n",[168,952,954],{"class":170,"line":953},19,[168,955,956],{},"  S->>B: Commit\n",[168,958,960],{"class":170,"line":959},20,[168,961,962],{},"  B-->>S: ok\n",[168,964,966],{"class":170,"line":965},21,[168,967,968],{},"  S-->>M: Created ✅ (draft state)\n",[13,970,971,972,975],{},"One more real detail: committing a \"create\" always ",[17,973,974],{},"saves a draft only"," — the AI never sets a campaign live directly; going live has to go through the \"modify \u002F enable\" path, which means passing through \"preview → confirm\" once more. One more layer of irreversibility, one more confirmation.",[26,977,979],{"id":978},"_9-transferable-design-principles","9. Transferable design principles",[282,981,982,988,994,1000],{},[285,983,984,987],{},[17,985,986],{},"Irreversible actions need a gate that doesn't go through the LLM."," The LLM handles \"understanding intent and generating content\"; \"should this really be executed\" is left to deterministic code.",[285,989,990,993],{},[17,991,992],{},"Let the LLM classify, don't let it decide."," Narrow the open question (should we commit?) into a tight classification, and write \"fall toward the safe side when unsure\" into the prompt.",[285,995,996,999],{},[17,997,998],{},"Back state with external storage + deterministic checks."," Keeping the cross-turn \"pending preview\" in an external cache, combined with gates \u002F mutual exclusion \u002F cleanup on switching, is far more robust than \"hoping the LLM remembers the context\".",[285,1001,1002,1005],{},[17,1003,1004],{},"Judge a defense by \"whether the code actually reads it\"."," A field with \"guard\" in its name is not necessarily guarding anything — the unwired \"message sequence number\" in this post is the reminder: a declared defense and a shipped defense are two different things.",[1007,1008,1009],"tip",{},[13,1010,1011],{},"In one sentence: an agent is not \"the LLM wraps everything\", but a division of labor where \"the LLM handles ambiguity and code handles the irreversible\". The more production-grade the agent, the sharper that dividing line.",[1013,1014,1015],"style",{},"html .light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html.light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}",{"title":164,"searchDepth":177,"depth":177,"links":1017},[1018,1019,1020,1021,1022,1023,1024,1025,1026],{"id":28,"depth":177,"text":29},{"id":55,"depth":177,"text":56},{"id":276,"depth":177,"text":277},{"id":308,"depth":177,"text":309},{"id":391,"depth":177,"text":392},{"id":627,"depth":177,"text":628},{"id":774,"depth":177,"text":775},{"id":852,"depth":177,"text":853},{"id":978,"depth":177,"text":979},"2026-06-09","In an agent whose actions have irreversible consequences, the decision to actually execute cannot be left to the LLM. Using a production marketing agent as the example, this post covers confirmation interception, the dry_run \u002F commit two-phase design, and the four lines of defense that really run.","md",null,"\u002Farticles\u002Fagent-hitl-two-phase-commit.svg",{},"\u002Farticles\u002Fagent-hitl-two-phase-commit","10",{"title":5,"description":1028},{"loc":1033},"articles\u002Fagent-hitl-two-phase-commit",[1039,1040],"LLM Apps","Agent","2uBETKQwy7wIH_z39mh-uyyID8xRAdmjBq3GcHPRSag",1795761652118]