AI Agents Need a Decision Layer: Teaching Models to Judge Whether to Act
As LLM-powered agents gain stronger execution capabilities, the ability to judge whether an action should be taken becomes more critical than generating the action itself. This article explains why generation and decision-making should be separated in agent systems, introduces closed-option classification and calibrated probabilities as the foundation of a decision layer, and presents a practical six-layer architecture with threshold-based routing and audit logging. A Python example demonstrates the core routing logic, including risk-level thresholds, traceable input hashing, and human review as a fallback path.
Introduction: The Stronger an Agent’s Execution, the More Critical Its Judgment
Over the past two years, LLM application development has focused on expanding capability boundaries. Models evolved from completing text to reading code, calling retrieval systems, operating web pages, and orchestrating multiple tools into agentic workflows. Once these capabilities are in place, engineering teams find that the real challenge is judging whether a step should be executed—not merely generating the next step.
A few common scenarios illustrate this. In a customer service system, a model can write a polished reply, but that does not mean it has the authority to approve a refund directly. A coding assistant can produce a complete fix patch, yet that does not justify merging it into the main branch. A security monitoring system can summarize an alert clearly, but the business cost of banning an account versus continued observation differs dramatically.
Generative capability answers where candidate actions come from; decision capability answers how candidates are filtered, approved, rejected, or escalated to a human. The two have different goals and different requirements for reliability, interpretability, and auditability, so they need to be designed separately.
1. Why Generation and Decision-Making Should Be Separated
A common practice is to let a general-purpose LLM play three roles at once: author, reviewer, and approver. Teams typically add instructions like “please be strict” or “if in doubt, reject” to the prompt, hoping the model will police itself. This works reasonably well in demos, but problems surface in production.
First, the output of a single generation pass is a piece of natural language containing a conclusion, reasoning, and tone—difficult to quantify. Ask the same question with slightly different wording, and the conclusion may flip, with no way for the system to explain which result is more trustworthy.
Second, responsibility boundaries are blurred. After an erroneous approval, the team can hardly determine whether the problem lies in generation quality, judgment criteria, or threshold settings; postmortems end up relying on chat logs alone.
Third, business rules cannot be maintained independently. Refund limits, risk levels, and review policies belong to business and compliance teams. Burying them in prompts tightly couples rule changes to model versions.
Extracting the decision step brings three improvements. First, decisions take closed options as input and output probability estimates for each option, making results directly comparable and recordable. Second, probabilities and thresholds become independent configuration items that business teams can adjust without touching generation logic. Third, low-confidence or high-risk samples enter a human review queue, forming a clear fallback path.
This separation does not mean a specialized decision model can replace a general-purpose LLM. A more realistic approach is: the generation component proposes solutions, the decision component filters them, and the two are connected through structured interfaces.
2. Closed Options and Calibrated Probabilities
The input design of the decision component determines whether it can be audited. The recommended approach is to use closed options—for example, three classes such as “approve, reject, escalate to human”—each with a clear definition. Open-ended answers make results hard to categorize and error rates impossible to measure.
Calibrated probability is another key concept. Calibration means the model’s output probabilities roughly match actual accuracy. If the model assigns 0.9 confidence to a batch of samples, about 90% of them should be judged correctly. Uncalibrated probabilities are merely scores and cannot be used directly as thresholds.
Two metrics are commonly used for calibration evaluation. Expected Calibration Error (ECE) buckets predictions by probability and measures the gap between average confidence and actual accuracy within each bucket. The Brier score measures the squared error between predicted probabilities and true outcomes—the lower the better. Both can be computed from historical labeled data, so teams do not need to rely on externally advertised metrics.
3. A Practical Decision-Layer Architecture
Below is a typical layered architecture. Each layer has clear responsibilities and can be tested and replaced independently.
- Candidate generation layer: a general-purpose model or rules engine generates candidate actions along with the necessary context.
- Structured encapsulation layer: converts candidate actions into fixed fields, including action type, amount or scope of impact, risk level, and so on.
- Decision evaluation layer: outputs probabilities for the closed options and records the model version and input hash.
- Threshold routing layer: decides between automatic execution and human escalation based on the risk level.
- Human review layer: handles low-confidence and high-risk samples and records reviewer feedback.
- Audit log layer: stores the input, output, routing result, and final execution result of every decision.
The following sample code shows the core logic of threshold routing. The code illustrates structure only; thresholds must be determined from calibration data.
import hashlibimport jsonfrom datetime import datetime, timezone# Auto-execution threshold per risk level. None means this level never auto-executes.THRESHOLDS = {"low": 0.90, "medium": 0.97, "high": None}def route_decision(candidate: dict, option_probs: dict, risk_level: str) -> dict:best_option, best_prob = max(option_probs.items(), key=lambda kv: kv[1])threshold = THRESHOLDS[risk_level]if threshold is not None and best_prob >= threshold:outcome = best_optionelse:outcome = "human_review"record = {"time": datetime.now(timezone.utc).isoformat(),"input_hash": hashlib.sha256(json.dumps(candidate, sort_keys=True).encode("utf-8")).hexdigest(),"option_probs": option_probs,"risk_level": risk_level,"outcome": outcome,}return record # In production, write this to audit storage
This code embodies three design principles. First, the threshold for the high-risk level is set to null, so the system never auto-executes at that level regardless of confidence. Second, every decision produces a traceable record: the input is stored as a hash, which supports comparison while avoiding persisting sensitive data in plaintext. Third, the routing logic is a pure function, making it easy to unit test, replay, and audit in isolation.
