MDPs and POMDPs
The Bellman equation over beliefs: act now, or pay to learn more first
Takeaway
At % sure a refund claim is valid, deciding straight away costs $32.00 per claim in expected mistakes. Checking first, about 2.7 times on average, cuts that to $7.54.
Change the blue number. Every figure on this page updates with it.
Why care
Every agent step is a choice between acting on what it knows and finding out more.
An agent can call another tool, read another document, or ask the user a clarifying question, and each of those costs time and money. Acting too early makes avoidable mistakes; checking too much wastes effort and annoys users. Markov decision processes (MDPs) are the standard model of acting step by step; partially observable MDPs (POMDPs) add the realistic twist that the agent never sees the true situation, only evidence about it. Solving one tells you exactly when evidence is worth gathering, and how many times.
The intuition
A doctor who is 99% sure of a diagnosis treats. One who is 50% sure orders a test. Somewhere in between is a confidence level where the test stops being worth its cost, and where that line sits depends on three things: how costly each kind of mistake is, how much the test costs, and how reliable it is.
The agent's confidence is its belief. Every piece of evidence moves the belief up or down by Bayes' rule. The solution of a POMDP is a map from belief to action, and for decisions like this one it has a simple shape: act one way when confident enough in one direction, act the other way when confident enough in the other, and look up more in between. The width of the middle band is what the math decides.
The math
An MDP picks actions to maximize value, using the Bellman equation:
In a POMDP the state is hidden, so the agent works with its belief \(b\), the probability of each state, and updates it with Bayes' rule after each observation \(o\):
For a two-way decision with an evidence lookup, the minimum expected cost from belief \(b\) (probability the claim is valid) is
- \(b\)
- belief: current probability that the claim is valid
- \(L_A,\ L_D\)
- cost of wrongly approving a fraudulent claim, and of wrongly denying a valid one
- \(c\)
- cost of one lookup: a tool call, a database check, a question to the user
- \(q\)
- reliability of a lookup: chance it points the right way
- \(b_o\)
- belief after seeing lookup result \(o\)
- Value of information: looking up is worth it when \(J_{\text{act}}(b) - J(b) > 0\). The calculator shows this gap at every belief.
- Threshold policy: the solution is "deny below a lower threshold, approve above an upper one, look up in between", like Wald's sequential test.
- Value iteration solves it: start with "act now" costs and apply the equation repeatedly until it stops changing. The calculator does exactly this on 1,001 belief points.
Where each of these comes from is worked through in Derivations at the end of the page.
Interactive calculator
Set the costs of each mistake, what a lookup costs and how reliable it is. The calculator solves the POMDP by value iteration and shows the best action at every belief.
The curve is stepped because each lookup shifts the odds by a fixed factor, so the number of results needed to leave the band jumps as the starting belief moves.
Worked example: a refund agent
A support agent decides refund claims. From history, 80% of claims are valid. Wrongly approving a fraudulent claim costs about $200; wrongly denying a valid one costs about $40 in goodwill and escalations. A lookup (order history, delivery scan, photo request) costs about $2 in time and tokens, and points the right way 85% of the time.
Deciding immediately, the agent should deny everything: at 80% valid, denying costs \(0.8 \times 40 = \$32\) a claim in expected mistakes and approving costs \(0.2 \times 200 = \$40\). Neither is good. Solving the POMDP gives a different policy: look up until the belief leaves the band from 11% to 98%, then decide. Because a wrong approval is five times as costly as a wrong denial, the band is lopsided: the agent needs to be very sure before approving.
| Policy | Lookups per claim | Expected cost per claim |
|---|---|---|
| Decide immediately (deny) | 0 | $32.00 |
| Always look up once, then decide | 1 | $12.80 |
| Optimal policy | 2.7 on average | $7.54 |
| Optimal, if a lookup cost $10 (human review) | 1 | $20.80 |
| Optimal, if lookups were only 70% reliable | 4.4 on average | $17.79 |
The optimal policy cut expected cost per claim by more than three-quarters, and the table shows what drives it. When lookups get expensive, the band narrows to 61–91% and the agent checks at most once. When lookups get unreliable, it checks more often and still ends up worse off: improving the evidence source was worth more than any tuning of the agent itself.
Assumptions and where it breaks
- Lookups are assumed independent. Checking the same source twice usually returns the same answer. Model distinct sources as distinct actions, each with its own cost and reliability.
- The costs must be real. The policy is only as good as \(L_A\), \(L_D\) and \(c\). Put a price on user friction, latency and errors with the business, even roughly; the thresholds follow from the ratios.
- The prior must match traffic. If fraud spikes, 80% valid is wrong and so is the starting point. Re-estimate it, or let earlier signals in the conversation set it per case.
- Real problems have many states. Exact POMDP solutions become intractable quickly. Agents use approximations: myopic value of information (look one step ahead), sampling-based planners, or an LLM prompted with the costs and its own confidence.
- The agent's belief must be calibrated. A model that says 90% when it is right 70% of the time will act too early. Calibrate its confidences against outcomes (see M16).
How to apply it
- Name the decision and its two kinds of mistake. Put a cost on each, and on each information-gathering action.
- Measure each evidence source: how often it points the right way, and what it costs.
- Solve for the thresholds with the calculator or the code below, and give them to the agent as explicit rules: "approve only above 98% confidence; deny below 11%; otherwise check".
- Track the belief explicitly. Have the agent state its confidence before and after each lookup, and log it, so you can check calibration.
- Revisit when costs change. A cheaper lookup, a new fraud pattern or a new policy moves the thresholds.
How to explain it to a stakeholder
"The agent checks before it decides, but only while checking is worth it. Because approving a fraud costs five times more than wrongly denying, it needs to be 98% sure before it approves, and it will deny outright only when it's fairly sure the claim is bad. In between, it looks things up."
Related models and patterns
For coding agents
A machine-readable summary and a reference implementation. The same spec is embedded in this page as <script type="application/json" id="model-spec">, and the whole series is listed in models.json.
id: mdp-pomdp
number: M14
name: MDPs and POMDPs (act or gather information)
family: planning
answers: "When should an agent gather more information instead of acting?"
formula:
bellman: "V(s) = max_a [R(s,a) + gamma * sum_s' P(s'|s,a) V(s')]"
belief_update: "b'(s) proportional to P(o|s) * b(s)"
act_or_look: "J(b) = min{(1-b)*L_A, b*L_D, c + sum_o P(o|b) J(b_o)}"
value_of_information: "J_act(b) - J(b)"
inputs:
b: {type: float, meaning: belief the favorable state holds}
L_A: {type: float, meaning: cost of wrongly acting yes}
L_D: {type: float, meaning: cost of wrongly acting no}
c: {type: float, meaning: cost of one lookup}
q: {type: float, meaning: lookup reliability}
assumptions:
- lookups independent given the true state
- costs and prior known
- belief calibrated
use_when:
- deciding how many tool calls or clarifying questions to allow
- setting confidence thresholds for irreversible actions
related_patterns: [react, human-in-the-loop, budget-aware-planning, agentic-rag]import numpy as np
def solve(L_A=200, L_D=40, c=2, q=0.85, grid=2001, tol=1e-10):
"""Value iteration over belief b = P(valid). Returns beliefs, cost J, action per belief."""
b = np.linspace(0, 1, grid)
approve, deny = (1 - b) * L_A, b * L_D
p_yes = b * q + (1 - b) * (1 - q) # lookup says "valid"
b_yes = b * q / np.maximum(p_yes, 1e-12)
b_no = b * (1 - q) / np.maximum(1 - p_yes, 1e-12)
J = np.minimum(approve, deny)
while True:
look = c + p_yes * np.interp(b_yes, b, J) + (1 - p_yes) * np.interp(b_no, b, J)
J_new = np.minimum(np.minimum(approve, deny), look)
if np.max(np.abs(J_new - J)) < tol:
break
J = J_new
action = np.argmin(np.vstack([approve, deny, look]), axis=0) # 0 approve, 1 deny, 2 look
band = b[action == 2]
return b, J, action, (band.min(), band.max()) if band.size else None
if __name__ == "__main__":
b, J, action, band = solve()
i = int(0.8 * 2000)
print(round(J[i], 2), band) # 7.54, look up between about 0.11 and 0.98Derivations
For the math-curious: where each result in The math comes from. Nothing above depends on reading this.
The Bellman equation and value iteration
The value of a state is the best you can do from it: take the best action, collect its reward, and continue optimally from wherever you land. Writing that sentence as an equation gives Bellman's. Value iteration turns it into an update, \(V_{k+1} = \mathcal{T}V_k\). With discounting (\(\gamma < 1\)), or as here with every look-up costing \(c > 0\) so that endless looking is never optimal, the update is a contraction: each pass shrinks the distance to the true solution, so repeated passes converge to it from any starting point.
Belief updates
Before a lookup the agent believes the claim is valid with probability \(b\). The lookup says "valid" with probability \(q\) if the claim is valid and \(1-q\) if not, so \(P(\text{"valid"}) = bq + (1-b)(1-q)\). Bayes' rule gives the new belief \(b_{\text{yes}} = bq / P(\text{"valid"})\), and similarly \(b_{\text{no}} = b(1-q)/P(\text{"fraud"})\). In odds form each "valid" result multiplies the odds by \(q/(1-q)\), and each "fraud" result divides them by it: at \(q = 0.85\), by 5.7.
Why the policy has two thresholds
The cost of deciding now, \(\min\{(1-b)L_A,\ bL_D\}\), is a tent: two straight lines meeting at \(b^* = L_A/(L_A+L_D)\), where the agent is most torn. The cost of looking up first is a concave function of \(b\) (an average of the best achievable costs after each result), plus a constant \(c\). It sits below the tent only in a band around \(b^*\), where deciding is most likely to be wrong; near 0 and 1 the tent is close to zero and no lookup can beat it. The band's edges are the two thresholds. This is the same structure as Wald's sequential probability ratio test.
One lookup, or many
The "exactly one lookup" readout uses a single update and then the best immediate decision: \(c + \sum_o P(o\mid b)\min\{(1-b_o)L_A,\ b_oL_D\}\). Looking only one step ahead like this is called myopic value of information, and it understates the value of looking when one result alone cannot settle the decision. The full solution accounts for the option to keep looking, which is why it can justify a first lookup even when a single one would not be worth it.
References
- Kaelbling, L. P., Littman, M. L. and Cassandra, A. R. (1998). Planning and acting in partially observable stochastic domains. Artificial Intelligence 101(1–2), 99–134. The standard introduction to POMDPs and belief states.
- Sutton, R. S. and Barto, A. G. (2018). Reinforcement Learning: An Introduction, 2nd edition. MIT Press. Chapters 3–4 cover MDPs and value iteration; free online.
- Wald, A. (1945). Sequential tests of statistical hypotheses. Annals of Mathematical Statistics 16(2), 117–186. The two-threshold rule for deciding when to stop gathering evidence.