Skip to main content

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.

PyPI Downloads License: MIT GitHub stars LinkedIn GitHub Discussions

Featured by Microsoft Developer Featured by Command Line Featured by AI Engineer World's Fair

Built by Susheem Koul and Tisha Chawla

TokenOps: one budget for one whole agent run, enforced before every model call

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.

TokenOps core features: enforced pre-call, run-scoped budget, shared across processes, steers not just stops, tool calls count too, ten policies included

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

TokenOps demo: the same task run twice - ungoverned, it completes over budget; governed, TokenOps halts it within the cap - then the Dashboard shows spend and governance per agent

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
├── 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

📰 Talks & press

🛟 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.

Contributors


Saved you tokens? ⭐ Star the repo.

Metadata

Release files for agent-tokenops 2.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for agent-tokenops 2.1.0
File Size Uploaded Provenance Actions
agent_tokenops-2.1.0.tar.gz 141.2 kB With provenance Details for agent_tokenops-2.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for agent-tokenops 2.1.0
File Interpreter ABI Platform Actions
agent_tokenops-2.1.0-py3-none-any.whl Python 3 none any Details for agent_tokenops-2.1.0-py3-none-any.whl

Total release size: 265.8 kB

Release files / agent_tokenops-2.1.0.tar.gz

Download URL agent_tokenops-2.1.0.tar.gz
Size 141.2 kB
Tags Source
SHA-256 checksum
How to use checksums
e847b265ac4072fc7a134c79cf8329e198d876e2c00410c890cc62fc5b8d6631
BLAKE2b-256 checksum
How to use checksums
dc4eaea051128e01647bf2a91bb802ecd1a20a5a8f639b6b5bc4bf904c7ec106
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 7, 2026.

Transparency log

Release files / agent_tokenops-2.1.0-py3-none-any.whl

Download URL agent_tokenops-2.1.0-py3-none-any.whl
Size 124.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7688baec192864d1ed21d070656bcedb4a674d580022e902172062a39364e8df
BLAKE2b-256 checksum
How to use checksums
9beefec1f26adf6a3e922daf85c10627c77a343ecde941c7b6d8dece3c09fadf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 7, 2026.

Transparency log

Security for agent-tokenops 2.1.0

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.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for agent_tokenops-2.1.0.tar.gz

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 Nov 7, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page