TokenOps
Cuts wasted agent spend by up to 65%, governing what the run has already spent before every call.
Toward token governance as a first-class discipline, not an afterthought.
Built by Susheem Koul and Tisha Chawla
|
|
See it stop a run mid-budget in the Quickstart below.
Core features · Quickstart · Quickdeploy · How it compares · Policies · Support · Contributing
🙌 Open to contribution
Token spend deserves the same first-class attention as compute or latency, and we are growing the community working on that. Policies, actuators, and the shared ledger are all open to extension. See CONTRIBUTING.md to get started.
✨ Core features
An AI agent's workflow can run up cost fast: dozens of small, individually cheap steps that quietly add up to a surprisingly large bill. TokenOps sets a single budget for the whole workflow and enforces it before every step, so spending never gets away from you.
Ten policies ship configured in docs/policies/, and you can
add your own.
🚀 Quickstart
Requires Python 3.10+. Zero-setup taste: python -m tokenops.demo runs a governed
agent in process, no server and no keys. For your own agent in one process, pass a
governance config; to share one budget across processes, point every agent at a
control plane (see Quickdeploy below):
1. Put it in your agent
In Claude Code, from a clone:
/integrate-tokenops
Anywhere else (Cursor, Copilot, ...), paste this:
Integrate TokenOps into this agent, following https://github.com/theagentplane/tokenops/blob/main/.claude/skills/integrate-tokenops/SKILL.md
Manual, about ten lines
Wrap your model call once, then hand the wrapped version to your agent.
from tokenops import tokenops_run
from tokenops.capabilities import wrap_complete
from tokenops.framework import Halt
from tokenops.providers import complete
GOVERNANCE = {"governance": {
"budgets": [{"id": "run_llm_cap", "limit_micros": 2_000_000, "dimension": "trace"}],
"policies": {"cost_budget": {"budget": "run_llm_cap"},
"pre_call_worst_case": {"budget": "run_llm_cap"}},
}}
with tokenops_run(config=GOVERNANCE, service="my-agent", intent="research",
provider="openai", model="gpt-4o") as bound:
governed = wrap_complete(
bound.governor, bound.controls, bound.attr,
provider="openai", model="gpt-4o",
dispatch=complete, service="my-agent",
)
try:
agent.run(..., complete_fn=governed) # <-- pass `governed`, not `complete`
except Halt as stopped:
print(f"run stopped: {stopped}")
Pass governed to your agent instead of complete; nothing else changes.
wrap_complete checks the budget before each call and raises Halt when the
run is out. With a control plane, replace config=GOVERNANCE with
client=ControlPlaneClient.from_env() (from tokenops.repositories import ControlPlaneClient); the budget then lives in the plane and is shared across processes.
2. When you need more
| You want to | Go to |
|---|---|
| Change the budget | Set the budget |
| One budget across several agent processes | Shared plane |
| FastAPI or A2A services | Instrumented app |
| Something other than stopping | The ten policies |
| Cost per agent in a dashboard | Quickdeploy |
| Coming from 0.4 | Migration |
| Everything else | Onboarding guide |
3. See it in action
|
|
Same task, run twice: ungoverned it completes over budget, governed it halts within the cap, then the Dashboard attributes cost per agent. Full video.
🐳 Quickdeploy
pip install agentplane-control-plane
control-plane serve # see its README for the Docker image and deployment
export CONTROL_PLANE_URL=http://localhost:8000
export CONTROL_PLANE_API_KEY=... # on every agent: read + ingest scopes
Put a budget there with control-plane db seed --file my.yaml, or through its API
(PUT /v1/budgets, PUT /v1/policies). Every agent pulls it, ETag cached.
PyPI name is agent-tokenops; the import is tokenops. Extras:
pip install "agent-tokenops[examples]" for the LangChain examples. Releases:
RELEASING.md.
🆚 How TokenOps compares
TokenOps is not a gateway or a tracing dashboard. It governs the run, a full agent workflow, and sits alongside the tools you already use for routing and observability.
| TokenOps | LiteLLM / Portkey / AI Gateway | Langfuse | |
|---|---|---|---|
| Primary focus | Run | Request | Trace |
| Multi-agent workflow as one unit | Yes | No | Partial |
| Budget enforcement in-path | Yes | Yes | No |
| Steer next call (mutate / inject) | Yes | Partial | No |
| Shared ledger across processes | Yes | — | — |
What this does not do: replace your LLM gateway, replace Chronicle's record-and-replay, or host a SaaS control plane for you.
Longer table with logos: docs/product/comparison.md.
Reference
Things you will want eventually, not now.
Architecture: how the control plane, Chronicle and TokenOps split the work
Three pieces share one artifact, the run, which is a Chronicle trace (trace_id):
flowchart LR
subgraph PLANE["Control plane"]
CFG[("governance config<br/>budgets · policies")]
LEDGER[("ledger<br/>spend · in-flight · halt")]
end
subgraph AGENTS["Agent processes"]
E["Entry agent<br/>tokenops_run"] -->|"traceparent"| D["Downstream agents<br/>tokenops_run"]
E & D -->|"wrap_complete + governor hook"| G["Governor<br/>pre_call → detect → decide → apply"]
end
CFG -->|"GET /v1/governance/{agent} (ETag)"| G
G -->|"precheck (reads)"| LEDGER
G -->|"events:batch (spend, complete) · admit / halt (sync)"| LEDGER
| Piece | Owns | Does not own |
|---|---|---|
| Control plane | configuration, the shared ledger, traces, the web page | the decision to stop a call |
| Chronicle | the trace, recording, replay, propagation | cost, budgets, policies |
| TokenOps (this package) | the governors: policies, pricing, the ledger view, the hook | a server, a database, a UI |
See docs/architecture.md. Chronicle is accepted at
REALM (Research on Agent Language Models), a workshop at EMNLP 2026.
Environment variables
| Variable | Purpose |
|---|---|
CONTROL_PLANE_URL |
The control plane's base URL (for example http://localhost:8000). Required for ControlPlaneClient.from_env() |
CONTROL_PLANE_API_KEY |
Bearer key (scopes read, ingest; admin to write configuration) |
CHRONICLE_CONTROL_PLANE_URL, CHRONICLE_API_KEY |
Where Chronicle saves envelopes; set the same plane |
There is no local ledger fallback. With a plane configured every process shares one budget;
without one, pass config= and the ledger lives in the process.
Make targets
| Target | Role |
|---|---|
make install |
Editable install with dev + examples extras |
make dist / check-dist |
Build sdist+wheel / twine check |
make demo-quick |
python -m tokenops.demo: no API keys, no server |
make sync-skills |
Regenerate the editor copies of the integration skill |
Project structure
Only src/tokenops/ is the installable package. Demos and benches stay under examples/.
src/tokenops/ # installable package
├── framework/ # in-process machinery: ledger, policies, pricing, governor (no network)
├── capabilities/ # tokenops_run, wrap_complete, the Chronicle hook
├── interfaces/ # instrument_app, HTTP error mapping
├── control/ # deprecated import shims (removed in 2.0)
├── repositories/ # the control-plane client and the background ledger writer
├── providers/ # OpenAI / Anthropic complete dispatch
└── config/ # packaged default governance
examples/ # A2A agent stacks (being rewritten)
docs/ # architecture, policies, ADRs, migration
tests/ # unit, contract and end-to-end (real control plane)
More documentation
- Onboarding: prerequisites, minimum integration, FAQ, current limits
- Migrating from 0.4
- Architecture - trace attribution - halt
- Policies: one page per policy - decisions
- Examples - comparison
📰 Talks & press
- Featured by Microsoft Developer: “Who spent all the tokens?” on LinkedIn and X.
- Who spent all the tokens? Real-time, run-scoped cost control for AI agents: Command Line, a Microsoft publication.
- FinOps for AI Agents: Who Spent All the Tokens?: talk at the AI Engineer World's Fair, San Francisco.
🛟 Support
| Need | Where |
|---|---|
| Bug | Open an issue |
| Security issue | SECURITY.md |
| Real-time help | Slack |
| Longer-form discussion | GitHub Discussions |
| Talk it through | Office hours |
| Talks & writing | theagentplane.github.io/media |
Contributors
Thanks to everyone who has contributed.
Saved you tokens? ⭐ Star the repo.
Metadata
Release files for agent-tokenops 1.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| agent_tokenops-1.1.0.tar.gz | 117.3 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| agent_tokenops-1.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 228.4 kB
Release files / agent_tokenops-1.1.0.tar.gz
| Download URL | agent_tokenops-1.1.0.tar.gz |
|---|---|
| Size | 117.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ba2a70757918ee98ee6123bd0f12622c1c718529a1705b885ca11364f7d2f4d1
|
|
BLAKE2b-256 checksum How to use checksums |
84a538e548c887153d311c53baca4c7aef7e0828fc811bd666dfc6b6fab9dcf0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 15, 2026.
Transparency logRelease files / agent_tokenops-1.1.0-py3-none-any.whl
| Download URL | agent_tokenops-1.1.0-py3-none-any.whl |
|---|---|
| Size | 111.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
fb41962726519228eeafb2ed835cf21a2573f450e388d92e9511497cedf083f1
|
|
BLAKE2b-256 checksum How to use checksums |
ce8e3ac885307534c7ac757b30fcd794dcc8e8d2778f5a9cc9c66efd25f559ac
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 15, 2026.
Transparency log