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+ and a running control plane — TokenOps has no ledger of its
own, so every agent (even a single process) governs against one. Zero-setup taste:
python -m tokenops.demo launches a throwaway plane for you automatically. For your
own agent, start one first (see Quickdeploy below), then:
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. Needs
CONTROL_PLANE_URL (or TOKENOPS_URL) pointing at a running control plane —
see Quickdeploy.
from tokenops import ControlPlaneClient, tokenops_run
from tokenops.control import Halt, wrap_complete
from tokenops.providers import complete
client = ControlPlaneClient.from_env() # raises if CONTROL_PLANE_URL isn't set
with tokenops_run(client=client, 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, even from another process.
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 |
| A worked end-to-end example | Field guide |
| 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
One command, plane + dashboard:
git clone https://github.com/theagentplane/tokenops && cd tokenops
docker compose --profile ui up --build
Plane: localhost:7700/health · Dashboard: localhost:8501. Plane only:
docker compose up --build. Details: docs/control-plane-deploy.md.
Without Docker (make)
git clone https://github.com/theagentplane/tokenops && cd tokenops
make install
make run # control plane :7700 + Admin/Dashboard :8501
Then open localhost:8501 to see spend and governance per agent.
Multi-agent benches: watch one budget span several agents
Each is a real multi-agent stack sharing one run ledger. One target starts the plane, the agents, and the Admin UI.
| Bench | Agents | Run |
|---|---|---|
| Two-agent | Research to Summarize | make demo |
| Triad | Planner to Researcher to Writer | make demo-triad |
| Brief | Scout to Analyst to Editor (LangChain) | make demo-brief |
| Bench UI | Chat + Simulator only | make bench-ui |
cp .env.example .env first if you want them to call real models. See
examples/README.md for the bench profiles.
Pointing several processes at one plane
export TOKENOPS_URL=http://localhost:7700
export TOKENOPS_DB=tokenops.db # plane and every agent read the same file
tokenops has no ledger of its own — every process governs against the plane at
TOKENOPS_URL. There is no local-fallback env var to accidentally leave unset.
PyPI name is agent-tokenops; the import is tokenops. Extras:
pip install "agent-tokenops[examples]" for the LangChain benches,
".[dev,examples]" from source. 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-style 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 plane and the SDK split the work
TokenOps is two layers that share one artifact, the run: a control plane that registers runs and stores budgets/policies, and an in-process SDK that enforces at every boundary crossing.
flowchart LR
subgraph PLANE["Control plane (:7700)"]
R["POST /v1/runs"] --> DB[("SQLite TOKENOPS_DB<br/>registrations · budgets · policies · ledger")]
UI["Admin + Dashboard"] --> DB
end
subgraph AGENTS["Agent processes (SDK)"]
E["Entry agent<br/>tokenops_run"] -->|"register_run"| R
E -->|"X-TokenOps-Run-Id"| D["Downstream agents<br/>tokenops_run"]
E & D -->|"wrap_complete"| G["Governor<br/>pre_call → detect → decide → apply"]
E & D -->|"@boundary + crossing hook"| G
G --> L["Shared ledger<br/>(same run_id)"]
end
L --> DB
DB -->|"governance_config_for"| G
| Piece | Owns | Does not own |
|---|---|---|
Control plane (python -m tokenops.server) |
POST /v1/runs, shared SQLite, Admin/Dashboard |
Agent loops, LLM calls, tools |
| SDK (in agents) | tokenops_run, wrap_complete, ledger/policies, Chronicle crossing hook |
Ad-hoc run IDs; mounting /v1/runs when TOKENOPS_URL is set |
Chronicle records decision boundaries; TokenOps attaches as the cost/governance observer on live crossings. See Chronicle for record-and-replay, accepted at REALM (Research on Agent Language Models), a workshop at EMNLP 2026.
Environment variables
| Variable | Purpose |
|---|---|
TOKENOPS_URL (or CONTROL_PLANE_URL) |
The control plane's base URL (e.g. http://localhost:8800) — required |
TOKENOPS_CONFIG |
YAML for governance seed (core: src/tokenops/config/default.yaml) |
tokenops has no ledger or run registry of its own — ControlPlaneClient.from_env()
raises if TOKENOPS_URL/CONTROL_PLANE_URL isn't set, rather than silently falling
back to anything local. Every process talks to the same plane, so they share one
budget by construction. TOKENOPS_URL also accepts the alias
TOKENOPS_CONTROL_PLANE_URL.
Make targets
| Target | Role |
|---|---|
make install |
Editable install with dev + examples extras |
make dist / check-dist |
Build sdist+wheel / twine check |
make control-plane |
Standalone plane (python -m tokenops.server) on :7700 |
make ui |
Admin + Dashboard on :8501 |
make run |
Plane + Admin/Dashboard |
make demo-quick |
python -m tokenops.demo: no API keys, no server |
make demo / demo-triad / demo-brief |
Runnable A2A stacks |
make bench-ui |
Chat + Simulator |
make db-reset |
Clear SQLite + reseed from TOKENOPS_CONFIG |
make stop |
Kill listeners on :7700 / :8501 |
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
├── server/ # control plane (:7700, POST /v1/runs)
├── control/ # SDK: ledger, policies, wrap_complete, crossing hook
├── providers/ # OpenAI / Anthropic complete dispatch
├── config/ # default.yaml governance seed
└── ui/ # Admin + Dashboard (Streamlit)
examples/ # A2A benches (two-agent, triad, brief) + Chat/Simulator
benchmarking/ # MetaGPT / browser-use live harness
docs/ # architecture, policies, guides, product
tests/ # unit + e2e
More documentation
- Onboarding: prereqs, minimum integration, FAQ, current limits
- Field guide: a triad walked through, with screenshots
- Policies: one page per policy
- Run attribution - control plane deploy - status
- Examples - comparison - shared ledger
📰 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 0.4.1
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-0.4.1.tar.gz | 151.9 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| agent_tokenops-0.4.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 279.7 kB
Release files / agent_tokenops-0.4.1.tar.gz
| Download URL | agent_tokenops-0.4.1.tar.gz |
|---|---|
| Size | 151.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
580849e433579053147729fbfdae3fe6fae5d520d00ed47563a3753593f65fc9
|
|
BLAKE2b-256 checksum How to use checksums |
60101a728c9278f034a5fcce64af5bf190ab727fc6f16567d702cde8ffdcb553
|
| 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 Sep 30, 2026.
Transparency logRelease files / agent_tokenops-0.4.1-py3-none-any.whl
| Download URL | agent_tokenops-0.4.1-py3-none-any.whl |
|---|---|
| Size | 127.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
3342e5ae9c8c74698d9d1fd219e9316e5ee1c6b09c532cdba3f319d4df024153
|
|
BLAKE2b-256 checksum How to use checksums |
be07aa792aa580266e4930814547d5e6e37264204b86afe16125ddb07394820b
|
| 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 Sep 30, 2026.
Transparency log