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.control import Halt, wrap_complete
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
├── control/               # the governors: ledger, policies, wrap_complete, Chronicle hook
├── 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 1.0.1

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 1.0.1
File Size Uploaded
agent_tokenops-1.0.1.tar.gz 108.8 kB Details

Built distribution (wheel)

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

Total release size: 198.8 kB

Release files / agent_tokenops-1.0.1.tar.gz

Download URL agent_tokenops-1.0.1.tar.gz
Size 108.8 kB
Tags Source
SHA-256 checksum
How to use checksums
41ba7bad8def81436951bdd42694dac1aef2811f81932c52dfece407294c8109
BLAKE2b-256 checksum
How to use checksums
16ce3e624cd5753f0382d393ff79427eb9422c4e191e7d317c83b759e8febb3c
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

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

Download URL agent_tokenops-1.0.1-py3-none-any.whl
Size 90.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c9e9290a35018ae59efd65b660fcd7e4ec3d4181151b8926750cbbc1d4da9884
BLAKE2b-256 checksum
How to use checksums
5b51e2a12f844461aa95bd7b640734a83b4db122875b27b43f4067a175ec0db0
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

Release history Release notifications | RSS feed

2.0.1

2 release files

2.0.0

2 release files

1.1.0

2 release files

This release

1.0.1 This release

2 release files

1.0.0

2 release files

0.4.1

2 release files

0.4.0

2 release files

0.3.0

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

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