Day 71: Token Budgets per PR and per Engineer

Day 71: Token Budgets per PR and per Engineer

If engineers never see the bill next to the diff, agents will maximize tokens by default. Publish per-PR and per-engineer token budgets in the PR UI and fail soft/hard when exceeded.

⚡ TL;DR: Attribute tokens to pr, user, run_id. Show cost estimate on the PR. Soft-warn at 80%, hard-stop at 100% of budget.

Attribution

# metering.py
def record(usage: dict):
    emit_metric("AgentTokens", usage["total_tokens"], dims={
        "pr": usage["pr"],
        "user": usage["user"],
        "model": usage["model"],
    })
// pr comment
export function budgetComment(used: number, cap: number, usd: number) {
  const pct = Math.round((used / cap) * 100);
  return `Agent budget: ${used}/${cap} tokens (~$${usd.toFixed(2)}) — ${pct}%`;
}

Soft vs hard

def enforce(used: int, cap: int):
    if used >= cap:
        raise RuntimeError("hard_budget")
    if used >= int(cap * 0.8):
        warn("soft_budget")

❌ Unlimited agent retries on a WIP PR with no owner-visible meter.

Closing checklist

  • [ ] Attribute tokens to PR + engineer
  • [ ] Comment budgets on PRs
  • [ ] Soft warn + hard stop
  • [ ] Monthly engineer rollups
  • [ ] Separate budgets for eval CI vs interactive

Series navigation

Day 70: Project: Secure Coding-Agent Sandbox on ECS Fargate · Day 72: Prompt Caching Pitfalls

Last updated September 11, 2026


Discover more from CheatCoders

Subscribe to get the latest posts sent to your email.

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply