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
2026-06-09
|
10 mins to read
|
Share article
1. Start with a bug
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."
What does that "OK" mean? Is it "OK, I want to change tier two", or "OK, go ahead and submit it as is"?
If you hand this judgment to the LLM, there is a decent chance it guesses wrong. And the cost of guessing wrong is asymmetric: guess "change" and the worst case is one extra question; guess "submit" and you have just pushed a campaign the merchant hadn't finished thinking through straight to production — an irreversible write.
That is the core question of this post: in human-AI collaboration (HITL, Human-in-the-Loop), should the "commit" decision be left to the LLM at all?
2. Background: what kind of agent is this
It is a marketing assistant running on IM channels. The merchant talks to it in plain natural language, and it helps the merchant create / edit / enable a "referral reward" campaign. Technically it is a ReAct agent built on LangGraph's create_react_agent, with 6 tools attached (listed by responsibility):
| Tool (by responsibility) | Read / Write |
|---|---|
| Recommend a plan (based on past campaigns + available coupons) | Read |
| Look up the coupon library (attached coupons can only come from here, so the LLM cannot invent coupon IDs) | Read |
| Look up member types / levels | Read |
| Create campaign | Write |
| Look up existing campaigns (the status determines what can be edited) | Read |
| Modify / enable campaign (one tool, three operations) | Write |
The key point: "create" and "modify / enable" are 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" — a wrong read can be retried; a wrong write is an incident.
The whole agent is strictly split into three layers, with deterministic code and the LLM each owning their own stretch:
One implementation detail worth spelling out: the main reasoning runs on LangGraph's create_react_agent; deciding "is this a confirmation" uses 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.
3. Why the naive approach doesn't work
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:
- Semantic ambiguity. "OK / fine / sure / 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?".
- 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".
- 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.
In one sentence: handing a decision where "one mistake is an incident" to a probabilistic black box is not a good idea.
4. Core design: take "commit" out of the LLM's hands (dry_run / commit two-phase)
Split the flow into two calls that go down different code paths:
- 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.
- commit belongs to deterministic code. Only that code can actually send the stashed content to the backend. The LLM never holds the right to commit.
This iron rule lands on a single 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.
The most counterintuitive, and most important, point: 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 — without ever entering the ReAct loop:
# Message entry point: intercept before ReAct (pseudocode)
intercepted = confirm_intercept(session, text)
if intercepted is not None:
result = intercepted # confirmation hit → commit directly, skip the LLM
else:
result = run_react_turn(state) # only otherwise go through ReAct
5. How to decide "is this a confirmation": whitelist + 4-way classification + safety bias
Wait — doesn't deciding "is this a confirmation" still require the LLM?
Yes, but it is used differently: we don't let the LLM "decide whether to commit", we only let it do a narrow, well-defined classification, and we hard-code "which side to fall toward when unsure".
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:
# Pseudocode
STRICT_CONFIRM = {"确认创建", "确认提交", "confirm create", ...}
def is_strict_confirm(text):
t = text.strip().lower().rstrip("。.!?~ ")
if not t or len(t) > 25: # anything over 25 characters is never a "crisp confirmation"
return False
return t in STRICT_CONFIRM
Step two: only ambiguous cases go through a lightweight LLM classifier, which picks one of four:
| Class | Meaning | Action |
|---|---|---|
| SUBMIT | Confirms submitting the preview already shown | Commit |
| PREVIEW_AGAIN | Regenerate the preview with the latest changes | Unlock, regenerate |
| CHANGE | Yet another new modification | Stay locked, accumulate, no preview |
| OTHER | Greeting / cancel / question / off-topic | Stay locked, reply normally |
The classifier uses 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:
Only a SUBMIT result commits; only PREVIEW_AGAIN unlocks regeneration, while CHANGE / OTHER always stay locked and accumulate. This turns "asymmetric cost" from a slogan into a hard bias in the code.
The full decision flow of the confirmation intercept:
6. More than interception: four lines of defense that really run
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 the code really executes:
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.
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 / small talk", preview generation is turned back directly — no new preview, and certainly no backend call — until the merchant plainly says "that's it".
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. The only legitimate entry point that triggers a commit is the deterministic confirmation intercept.
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.
Plus one state-integrity constraint: 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).
The session state machine (state lives in an external cache, remembering across turns "what was previewed last turn"):
7. Two "error-proofing" details: the same deterministic philosophy
Converge the "error-prone spots" into a 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:
① 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 the one place where the outbound payload is assembled, and //100 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.
② The None vs 0 sentinel. Optional numeric values use None to tell "not passed" apart from "passed as 0": None = "the LLM didn't pass it" → fall back to the default; 0 = "the merchant explicitly said no reward on this side" → keep 0. So the check has to be is None, not not x:
# Pseudocode: the fallback only happens when "not passed"; an explicit 0 is respected
if cfg.get("points") is None:
cfg["points"] = DEFAULT_POINTS
With an ordinary = default, you can't tell "didn't say" from "said no".
8. One complete round
One more real detail: committing a "create" always saves a draft only — the AI never sets a campaign live directly; going live has to go through the "modify / enable" path, which means passing through "preview → confirm" once more. One more layer of irreversibility, one more confirmation.
9. Transferable design principles
- 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.
- 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.
- Back state with external storage + deterministic checks. Keeping the cross-turn "pending preview" in an external cache, combined with gates / mutual exclusion / cleanup on switching, is far more robust than "hoping the LLM remembers the context".
- 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.