agent-token-budget

agent-token-budget is a skill for Claude Code, Codex from MLOps-Courses/agentops-open-course. It costs 65 tokens per session (566 once invoked), scanned A, original, MIT.

A system for limiting and tracking how many tokens an AI agent uses during a session. Tokens are the small pieces of text models process.

In plain words
What is it for?
Use it to enforce per-session token ceilings, count input and output usage, expose metrics, attach usage to traces, and estimate cost from configurable prices.
Why use it?
It stops an agent loop from running indefinitely and gives a clear response when the usage limit is reached, while recording usage details.

Skill for Claude CodeCodex

Written for no agent in particular: nothing here depends on one. Also seen: mentions subagents.

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add skills/mlops-courses/agentops-open-course/agent-token-budget
Any agent
npx skills add MLOps-Courses/agentops-open-course --skill agent-token-budget
Clone the repo
git clone --depth 1 https://github.com/MLOps-Courses/agentops-open-course

Made for: Claude Code, Codex.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for agent-token-budget

README.md
[![agentmods](https://agentmods.dev/badge/skills/mlops-courses/agentops-open-course/agent-token-budget.svg)](https://agentmods.dev/skills/mlops-courses/agentops-open-course/agent-token-budget)
Your own site
<a href="https://agentmods.dev/skills/mlops-courses/agentops-open-course/agent-token-budget"><img src="https://agentmods.dev/badge/skills/mlops-courses/agentops-open-course/agent-token-budget.svg" alt="Measured on agentmods" height="20"></a>
Per session 65 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 566 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00065 $0.00566
Opus 5 $0.00032 $0.00283
Sonnet 5 $0.00013 $0.00113
Haiku 4.5 $0.00006 $0.00057

Measured 5d ago against content hash 16ae49bf3c81, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-06, from the pricing page.

Security

Grade A, and why

agent-token-budget scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 5d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

skills/agent-token-budget/SKILL.md · 37 lines

How it starts

The opening of the file, as written. The whole thing — 37 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Agent Token Budget

Every agent loop step is another model call, so cost and latency compound. Give each conversation a hard token ceiling and attribute usage to the session — bounding reasoning work, not just dollars.

When to use

  • An agentic loop or delegation chain can call the model an unbounded number of times.
  • You need to answer "how many tokens did this session use?" and "what happens at the limit?".
  • You want token/cost signals in traces and metrics without hardcoding a vendor's prices.

Steps

  1. Accumulate usage into session state. After each final model response, add input and output tokens to a running per-session total that persists across turns. Exclude streaming partials.
  2. Enforce a hard ceiling before the model call. In a before-model hook, if the session total has reached the limit, short-circuit with a clear message ("start a new session, or raise the limit") instead of a silent failure or an open-ended bill.
  3. Attribute, don't just count. Emit tokens as an OTel counter (graph throughput) and as span attributes (per-turn detail); compute cost from configurable per-1k prices that default to 0 for local models — never hardcode a provider's pricing.
  4. Make the budget cover the whole conversation. In multi-agent/delegation flows, keep the totals in shared session state so hops between sub-agents accumulate against one ceiling rather than each starting fresh.

Reference implementation

From the AgentOps Open Course, installable with npx skills add MLOps-Courses/agentops-open-course:

  • agents/go/policy/budget.go — session usage, hard ceiling, configurable cost estimate, and OTel evidence.
  • Course chapters 7.3. Costs and 3.7. Multi-Agent.

Verify

Set the ceiling to 1 token and send a turn: assert the model call is refused with the actionable message and the token counter reflects the usage; confirm a delegation chain hits one shared ceiling, not one per sub-agent.

Read the full file on GitHub · 37 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 5d ago First seen · 37 lines · 65 tokens per session scan A 16ae49bf3c81

Subscribe to this mod's changes

agent-token-budget is a skill published in the GitHub repository MLOps-Courses/agentops-open-course (2 stars, last pushed 4d ago), licensed MIT. It adds 65 tokens to every session and 566 once invoked, about $0.0003 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.

Related

Other skills, from other repositories

find-your-level

Interactive quiz that maps your AI/ML knowledge to a starting point in the 523-lesson, 20-phase AI Engineering from Scratch curriculum. Trigger phrases: "where should I start", "find my level", "what do I know", "which phase", "assess my knowledge", "placement test", "skip ahead".

rohitg00/ai-engineering-from-scratch · 71 tokens

skill-release-gate

Evaluate an Agent Skill bundle for structural integrity, trigger quality, artifact improvement, script correctness, safety, installed-tree integrity, and target-host portability before release.

rohitg00/ai-engineering-from-scratch · 36 tokens

migration-review

Review database migration files when a change adds or modifies paths under migrations/. Use it before merge to collect forward, rollback, locking, and data-safety evidence.

rohitg00/ai-engineering-from-scratch · 35 tokens

gen-test

Generate idiomatic tests for Go packages and handlers in the Meshery project.

meshery/meshery · 18 tokens

superplane-changelog

When generating a SuperPlane changelog from merged commits. Use for "what's new" summaries with new integrations, new components/triggers, improvements, security updates, and bug fixes. Output is user-focused markdown in tmp/.

superplanehq/superplane · 50 tokens

simplified-technical-english

Write user-facing and reviewer-facing technical text in ASD-STE100 Simplified Technical English style. Use when drafting PR descriptions, commit message bodies, UI copy, docs, error messages, procedures, onboarding text, or any product wording that must stay clear for non-native readers.

superplanehq/superplane · 62 tokens