In the first article of this series, Tokenomics for Coding Agents, we looked at the mechanics of controlling token consumption: leaner context, smarter model routing, caching, disciplined tool usage, and explicit budgets.
But there is a deeper question that appears as soon as coding agents move from experiments into daily engineering work:
What does one successfully completed software task actually cost?
That question changes the optimization target. Counting tokens is useful, but tokens are only an input to the economics of an agentic workflow. A cheaper run that fails, retries, or creates review work may be less efficient than a more expensive run that produces a correct change on the first attempt.
This second article in the series moves from token optimization to unit economics.
Why Token Count Alone Is Not Enough
Two coding-agent sessions can consume the same number of tokens and create very different outcomes. One may produce a tested pull request in a few iterations. Another may spend the same budget exploring irrelevant files, repeating tool calls, and generating a patch that requires substantial human repair.
Recent research on agentic coding workloads reinforces this point: input/context consumption can dominate output generation, token usage can vary dramatically between runs, and higher token consumption does not automatically translate into better task success. citeturn0academia17turn0academia18
So the more useful metric is not:
tokens per task
It is closer to:
success-adjusted cost = total agent cost / successfully completed tasks
For engineering teams, an even broader metric is:
economic value = engineering time saved - AI operating cost - remediation cost
The exact formula will vary by organization, but the principle is stable: measure the outcome, not just the meter.
1. Define the Unit of Work
Before measuring economics, define what a successful unit of work means.
For coding agents, possible units include:
- a completed bug fix with passing tests
- a merged pull request
- a successfully generated test suite
- a completed refactoring task
- a production incident investigation that reaches an accepted resolution
A useful team-level definition is successful task: the requested change is completed, validation passes, and the result requires no unexpected rework beyond the team's normal review process.
Once the unit is defined, every optimization can be evaluated against it.
2. Build a Cost Ledger for Every Agent Run
Do not treat the model invoice as the complete cost ledger. Capture the components that explain why a session became expensive.
- Input tokens: fresh context sent to the model.
- Cached input: repeated context that receives provider-specific cache treatment.
- Output tokens: generated responses, reasoning, and edits where billed.
- Tool calls: shell, search, retrieval, test, browser, and external service operations.
- Retries: repeated model or tool execution after failure.
- Model tier: which model handled each step.
- Latency: how long the workflow took.
- Human remediation: engineering effort required after the agent's result.
This is where agent observability becomes part of cost management. Current tooling and platform guidance increasingly expose cache behavior, prompt composition, tool overhead, and per-session token usage because those details explain where the budget is actually going. citeturn0search0turn0search2
3. Measure Context Carry Cost
One of the most important concepts in agent economics is that a tool result can affect more than the turn that generated it.
If an agent reads a large file early in a long session, that information may remain in the working context for many later turns. Even when prompt caching reduces the marginal price of repeated input, the context still occupies window capacity and can influence latency and future inference cost.
That means the expensive event is not always the largest tool call. It can be the tool call that introduces unnecessary context early and then gets carried through the rest of the session.
A practical observability metric is:
carried context cost = context introduced × number of later turns that retain it
This is especially useful when investigating long-running coding sessions.
4. Treat Prompt Caching as an Economic Lever, Not a License to Grow Context
Caching changes the economics of repeated context. Stable system instructions, tool definitions, repository guidance, and other repeated prefixes can become substantially cheaper when the provider supports prompt caching. Current platform documentation and engineering reports show caching being used specifically to reduce repeated inference work and cost. citeturn0search2turn0search3
But there is an important distinction:
cached does not mean free.
A high cache-hit rate can coexist with a very large context window. One recent open-source measurement of coding-agent sessions found that most prompt tokens were cache reads while the session still carried hundreds of thousands of tokens per turn. That is a single-machine measurement rather than a universal benchmark, but it illustrates the architectural point: caching discounts repeated context; it does not automatically eliminate context growth. citeturn0search0
So monitor both:
- cache hit rate
- absolute context size
Optimizing only the first metric can hide problems in the second.
5. Make Model Routing Part of the Cost Model
Model routing should be measured as a portfolio decision rather than a simple rule that says “always use the cheapest model.”
For each task class, track:
- cost per attempt
- success rate
- average retries
- latency
- human remediation time
Then compare the total economics of different routes.
route cost = model cost + retry cost + remediation cost
A lower-priced model can be economically attractive for routine transformations but less attractive for tasks where an incorrect result triggers expensive debugging. Conversely, using a frontier model for every formatting or boilerplate task can waste budget.
The practical design is a routing ladder: start with the least expensive capable route, validate aggressively, and escalate when the evidence says the task needs more capability.
6. Tool Calls Need Their Own Budget
In an agentic system, tools are not just implementation details. They are part of the cost surface.
Consider a workflow that performs:
- repository search
- full-file reads
- dependency inspection
- test execution
- log retrieval
- another full-file read
- another test run
Even if each action seems reasonable, the combined context and iteration overhead can dominate the actual code generation.
Measure tool calls per successful task and break them down by tool type. Look for repeated reads, oversized command output, redundant searches, and tests that could have been narrowed.
The objective is not “fewer tool calls.” The objective is fewer unnecessary tool calls per successful outcome.
7. Add a Cost-per-PR or Cost-per-Change Metric
For engineering organizations, task-level economics becomes much more actionable when connected to delivery artifacts.
For example:
cost per merged PR = AI inference cost + tool cost + remediation cost
Track this alongside:
- cycle time
- review time
- change failure rate
- rollback or repair frequency
- developer acceptance rate
This avoids a common trap: celebrating lower AI spend while quietly increasing human review and repair effort.
8. Create a Small Agent Cost Dashboard
You do not need a massive FinOps platform to start. A simple dashboard can answer most early questions.
- Total AI spend: daily and weekly.
- Cost per successful task: by repository or team.
- Tokens per successful task: input, cached input, and output.
- Cache hit rate: by model and workflow.
- Tool calls per task: with the highest-volume tools identified.
- Retry rate: percentage of runs requiring additional attempts.
- Model distribution: percentage of work routed to each model tier.
- Human remediation: estimated minutes after agent completion.
The dashboard should answer one operational question quickly:
Where did the last dollar of agent spend go, and did it produce useful engineering work?
9. Optimize With A/B Experiments
Do not assume that every token-saving technique produces a lower bill.
Recent research has found cases where reducing raw tool-output tokens did not reliably reduce provider-billed cost, and aggressive compression could damage task completion. citeturn0academia18
That suggests a better optimization loop:
- Record a baseline.
- Change one part of the agent harness.
- Run a representative task set.
- Measure cost, latency, and success rate.
- Measure remediation effort.
- Keep the change only if success-adjusted economics improve.
This is the same discipline used for performance engineering: measure first, change second, benchmark third.
10. Build a Budget Policy That Escalates Intelligently
Once the metrics exist, budgets can become dynamic rather than static.
For example:
if task_cost < warning_budget: continue if validation_failed and retry_count < retry_limit: retry_with_same_route() if retry_limit_exceeded: escalate_to_stronger_model() if critical_budget_exceeded: stop_and_request_human_review()
The exact thresholds should be tuned to the workload. The important idea is that cost control becomes part of the agent's runtime policy instead of a monthly surprise on an invoice.
What This Means for Engineering Leaders
The economics of coding agents will increasingly look less like simple API consumption and more like cloud infrastructure economics.
Teams will need visibility into consumption, routing, efficiency, reliability, and business value. Recent enterprise reporting points in the same direction: organizations are paying more attention to AI observability, budget controls, and outcome-based measurement as agentic workloads scale. citeturn0news12turn0news15
The goal should not be to minimize AI spending in isolation. A team that spends slightly more on inference but cuts developer cycle time substantially may have better economics than a team that minimizes inference while increasing manual remediation.
A Practical Scorecard
For a production coding-agent program, start with these eight numbers:
- Cost per successful task
- Tokens per successful task
- Cache hit rate
- Average context size
- Tool calls per task
- Retry rate
- Human remediation minutes
- Time saved per successful task
Together, these metrics turn tokenomics into an engineering management system.
What Comes Next in This Series
The first article focused on how to reduce waste. This article focused on how to measure the economics of that waste.
The next logical step is the runtime architecture behind those controls: how to build a cost-aware coding-agent gateway that performs model routing, budgets, caching, tool governance, and observability automatically.
That is where tokenomics stops being a developer habit and becomes an engineering platform.
Final Takeaway
Token counts are useful telemetry, but they are not the final business metric.
For coding agents, the meaningful unit is the successful software outcome. Measure what the agent consumed, what it produced, how often it failed, how much context it carried, and how much human effort remained.
Then optimize for success-adjusted cost rather than raw token reduction.
That shift—from tokens to outcomes—is the foundation of sustainable agentic engineering.
Comments
0To comment, choose whether you want to register or continue as a guest.