Cost, Metering & FinOps
Agentic systems have an economic structure unlike any software before them: their marginal cost per request is real, variable, and potentially unbounded. An agent in a reasoning loop, fanning out to sub-agents, can quietly spend orders of magnitude more than a simple query — and a bug or an attack can turn that into catastrophe. Cost is not a finance concern to reconcile monthly; it is an engineering constraint to design for and enforce in real time.
20.1 The token economics of agents
Recall Chapter 2's multipliers: an agentic task costs many times a single completion because every loop iteration re-sends growing context, reasoning strategies multiply calls, and multi-agent fans out across many models. The dominant cost driver is tokens, and context length is the lever — which is why the context engineering of Chapter 7 (compaction, caching, selective retrieval) and the gateway caching of Chapter 6 are also your primary cost-control mechanisms. Cheaper models for easy steps (gateway routing, Ch. 6) and avoiding gratuitous multi-agent designs (Ch. 12) round out the levers.
20.2 Metering: you cannot control what you cannot measure
Every model call has a measurable cost (input + output tokens × price), already captured per span by observability (Ch. 18). Metering aggregates this into the dimensions the business needs: cost per run, per user, per tenant, per feature. This serves two ends — internal unit economics (is feature X profitable? which tenant is unprofitable?) and external billing (charging customers for usage). Dedicated metering and usage-billing systems such as Lago and OpenMeter ingest usage events and turn them into accurate per-customer cost and revenue, which is essential the moment you bill for consumption.
20.3 Budget enforcement
Measurement without enforcement is an autopsy. The platform must impose hard limits the model cannot exceed: a per-run budget (tokens/cost/iterations — the loop counter of Ch. 5 and the iteration ceiling of Ch. 2), and per-user/per-tenant quotas over time. These are checked in the control path — at the gateway (Ch. 6) and orchestrator — and tripping one halts or degrades the run rather than letting it spend without bound. This is the same control-plane discipline as guardrails and authorization: the model proposes work; the platform decides whether the budget permits it.
Meter every token at the point of use, attribute it to run/user/tenant/feature, and enforce hard budgets in real time. An agent without a spending ceiling is a financial incident waiting to happen; unit economics you compute only after the invoice arrives are unit economics you cannot manage.
The signature cost failure is an agent that loops — retrying, re-reasoning, re-spawning — without converging, or one driven into expensive behavior by injection (Ch. 16). Without an enforced iteration and budget ceiling, a single run can incur unbounded cost. The ceiling of Chapter 2 is not a nicety; it is the circuit breaker that makes autonomy financially survivable.