The Budget Contract: Five Runtime Guardrails That Keep Production Agent Costs Predictable

Treat agent cost as an SLO. Encode five runtime guardrails—loop limits, tool-call caps, token budgets, timeouts, and tenant ceilings—so production agents stay useful without runaway spend.

Mapki

Mapki

Nov 27, 2026•6 min read
Share:
Mapki
Custom Agents

Why Cost Is Now a Reliability Metric

A single agent run is no longer one model call. It is a sequence of planning steps, tool executions, reflections, and retries. Each step re-sends growing context. The result is that a task that looks cheap on a spreadsheet can cost 30× more in production, and a looping agent can exhaust a monthly budget in hours.

Traditional monthly provider alerts arrive after the money is gone. Per-request gateways miss the multi-step run where most of the spend actually occurs. The practical response is to treat the agent the way you treat any other production service: give it a budget contract, the same way you give a service an SLO.

This post lays out five runtime guardrails that implement that contract. They are enforced before the next model or tool call, not after the invoice arrives.

The Five Guardrails

These come from practitioner write-ups on agent unit economics and from production patterns that separate prototypes from systems that can be left running overnight.

1. Loop / Step Limit

Cap the number of planning, reflection, or verification cycles inside one run.

  • What it stops: Agents that keep re-planning because a tool returned an ambiguous result or the model decided the previous step was insufficient.
  • Typical values: 8–15 steps for interactive tasks; higher only for explicitly long-running research jobs.
  • Behavior on hit: Escalate to a human, ask a clarifying question, or return the best partial answer with a clear status. Do not silently continue.

Without this, a single ambiguous tool result can trigger an unbounded retry loop.

2. Tool-Call Cap

Limit the total number of paid tool actions per run, with stricter sub-caps for expensive tools (web search, large retrieval, external APIs).

  • What it stops: Agents that issue dozens of searches or database queries while exploring.
  • Typical values: 10–20 total tool calls; 3–5 for search-heavy tools.
  • Behavior on hit: Summarize what has already been gathered and finish, or route to a cheaper path.

Context replay makes every extra tool call more expensive than the last. A hard cap forces the agent to be selective.

3. Token Budget

Enforce a per-run ceiling on input + output tokens across all model calls. Prefer summarizing history over re-sending full transcripts.

  • What it stops: Quadratic cost growth from repeated context.
  • Typical values: Set from measured p95 of successful runs for that agent type, then add a modest buffer. Soft-cap at 80 % by injecting a system message that asks for shorter reasoning; hard-cap at 100 %.
  • Behavior on hit: Soft: continue with compressed context. Hard: stop and return partial work plus a reason.

Token counts alone are incomplete because model prices differ. Pair the token ceiling with a dollar ceiling checked before each call when possible.

4. Wall-Clock Timeout

Keep interactive flows responsive. Push long work into explicit background jobs that report status.

  • What it stops: Agents that appear stuck while burning tokens on slow tools or deep reflection.
  • Typical values: 30–60 seconds for chat-style agents; minutes only for background research agents that surface progress.
  • Behavior on hit: Return current best answer and a job ID if the work continues asynchronously.

Users retry when they see silence. Each retry multiplies the cost of the original incomplete run.

5. Tenant / Concurrency Budgets

Limit blast radius with per-tenant, per-user, or per-team ceilings and concurrency caps.

  • What it stops: One noisy customer or one runaway session from consuming the entire pool.
  • Typical values: Daily or monthly dollar/token budgets per tenant; concurrency limits that match expected parallel work.
  • Behavior on hit: Queue, degrade to a cheaper model, or return a clear “budget exceeded” with a reset time.

These five together form the contract. They are most effective when checked at the gateway or orchestrator boundary before every model or tool call.

Implementation Pattern

A practical structure looks like this (Python-style pseudocode for the check that runs before each call):

class BudgetContract:
def __init__(self, max_steps=12, max_tool_calls=15, max_tokens=150_000, max_seconds=45, tenant_daily_usd=50):
self.max_steps = max_steps
self.max_tool_calls = max_tool_calls
self.max_tokens = max_tokens
self.max_seconds = max_seconds
self.tenant_daily_usd = tenant_daily_usd

def check(self, run):
if run.steps >= self.max_steps:
return "escalate", "step limit"
if run.tool_calls >= self.max_tool_calls:
return "summarize_and_finish", "tool-call cap"
if run.tokens >= self.max_tokens * 0.8:
return "soft_cap", "token soft limit"
if run.tokens >= self.max_tokens:
return "hard_stop", "token hard limit"
if run.elapsed > self.max_seconds:
return "background_or_stop", "timeout"
if run.tenant_spent_today >= self.tenant_daily_usd:
return "queue_or_reject", "tenant budget"
return "continue", None

Wire the result into the agent loop so the decision happens before the next expensive call. Log the reason and the current spend so later reviews can see which guardrail fired.

Soft Caps vs Hard Stops

Hard stops waste partial work and often cause user retries that re-spend the tokens you just saved. Soft caps—injecting an instruction such as “finish with what you have; keep the answer under 200 words”—preserve completion rates while still bounding cost.

Microsoft engineers working on run-scoped controls reported that steering policies (instead of pure halt) cut average spend substantially while raising the share of runs that actually completed. The same pattern appears in other production write-ups: governance that only kills work is cheaper on paper and more expensive in practice because users simply re-submit.

Measuring What Matters

Track cost per completed task, not cost per call. A cheap individual request can hide an expensive workflow that includes retries and sub-agent fan-out.

Useful signals:

  • Cost per successful outcome (resolved ticket, completed research brief, merged PR).
  • Tail of the distribution — the 20 most expensive runs of the week usually explain most of the overage.
  • Guardrail hit rate by type — if the step limit fires constantly, the agent needs a better stopping condition or a narrower tool set.

Pair these with ordinary traces so you can reconstruct why a particular run crossed a limit.

YouTube

References & Community Insights

These sources converge on the same practical point: the place to enforce the budget is inside the run, before the next call, with a mix of hard limits and soft steering so the agent still finishes useful work.

Closing

An agent without a budget contract is an open-ended process that can spend money faster than any human operator can react. The five guardrails—step limits, tool-call caps, token budgets, timeouts, and tenant ceilings—turn that open-ended process into a bounded service. They do not make the agent less capable; they make its cost predictable enough that you can leave it running.

Want to implement this in your business?

Mapki designs bespoke AI agents, custom workflow automations, and tool-agnostic integrations tailored specifically to your existing ERP, CRM, and databases.

Tags:Agent FinOpsBudget GuardrailsProduction AgentsCost ControlRuntime LimitsLLM Agents