Skip to main content

TokenOps control plane and SDK for run-aware agent token governance

Project description

TokenOps

Run-aware token governance for multi-agent systems.
Cap spend and steer behavior across a whole agent workflow — not per request — with a shared ledger and in-path enforcement.

CI PyPI Python License: MIT Status Stars


TokenOps Dashboard: governance halt when worst-case cost exceeds remaining run budget

TokenOps is a control plane + SDK for agent stacks. Entry agents register a run; every LLM and tool crossing shares one run_id and one ledger. Policies can halt, mutate, or inject before the next call executes — so a research → summarize → review pipeline stays inside a single budget even across processes.

Why · Architecture · Install · Quick start · Demos · Comparison · Make targets · Roadmap

Why TokenOps

  • Govern the run, not the request. One run_id spans every model, tool, and A2A hop in a workflow.
  • Shared ledger across processes. Spend, inflight, and halt live in SQLite so multi-agent stacks cannot each burn the full cap locally.
  • In-path enforcement. wrap_complete runs detect → decide → apply before the next LLM call; Chronicle @boundary + a crossing hook ingest tool spend.
  • Steer or stop. Actuators: HALT · MUTATE · INJECT · reject/queue — not just post-hoc analytics.
  • Batteries included. Control plane (:7700), Admin + Dashboard UI, ten seeded policies, and runnable A2A benches (two-agent, triad, LangChain brief).

Architecture

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/>entry_task_run_scope"] -->|"register_run"| R
        E -->|"X-TokenOps-Run-Id"| D["Downstream agents"]
        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) wrap_complete, ledger/policies, Chronicle crossing hook, run propagation 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.

Install

pip install agent-tokenops

# With example / bench extras (LangChain, ddgs):
pip install "agent-tokenops[examples]"

# From source (development):
pip install -e ".[dev,examples]"

Requires Python 3.10+. PyPI name is agent-tokenops; import is still tokenops (same pattern as Chronicle). See RELEASING.md for releases.

Quick start

make install
cp .env.example .env   # optional API keys for demos / your agents

make db-reset          # optional: clean SQLite + seed governance from default.yaml
make run               # control plane :7700 + Admin/Dashboard :8501

Wire governance into an agent: register the run at the entry, wrap the LLM, and install the Chronicle crossing hook for tools.

from tokenops import ControlPlaneClient
from tokenops.control import (
    wrap_complete,
    entry_task_run_scope,
    governance_scope,
    install_crossing_hook,
)
from tokenops.providers import complete

install_crossing_hook()  # once per process; Chronicle on_crossing → Governor.observe

client = ControlPlaneClient.from_env()  # TOKENOPS_URL or embedded Store

# Entry agent: UI omits run_id; entry opens the run on the plane
with entry_task_run_scope(store, headers=headers, payload=payload, service="planner"):
    with governance_scope(governor, attr, provider=..., model=...):
        governed = wrap_complete(
            governor, controls, attr,
            provider=provider, model=model,
            dispatch=complete, service="planner",
        )
        run_agent(..., complete_fn=governed)

Point agents at the plane and share one DB:

export TOKENOPS_URL=http://localhost:7700
export TOKENOPS_DB=tokenops.db   # plane + all agents
make control-plane               # :7700
make ui                          # Admin + Dashboard :8501

Full integration checklist: .cursor/skills/integrate-tokenops/SKILL.md · field guide: docs/guides/field-guide-add-tokenops.md.

Demos

Each bench is a multi-agent stack with a shared run ledger. Start the plane, agents, and Admin UI with one make target.

Demo Agents Run
Two-agent Research → Summarize make demo
Triad Planner → Researcher → Writer make demo-triad
Brief Scout → Analyst → Editor (LangChain) make demo-brief
Bench UI Chat + Simulator only make bench-ui
make demo              # plane + research/summarize + Admin UI
make demo-triad        # plane + planner/researcher/writer
make demo-brief        # plane + scout/analyst/editor

Docker:

docker compose up --build
# optional UI: docker compose --profile ui up --build
# two-agent stack:
docker compose -f docker-compose.examples.yml up --build

See examples/README.md and docs/control-plane-deploy.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 (stateful) Request Trace (observe)
Multi-agent workflow as one unit Yes No Manual stitch
Budget enforcement in-path Yes (run-aware) Yes (key/team) No (analytics)
Steer next call (mutate / inject) Yes Routing / fallbacks No
Shared ledger across agent processes Yes N/A N/A

What this does not do: replace your LLM gateway, replace Chronicle-style record-and-replay, or host a SaaS control plane for you. Fail-closed integrity (refuse on missing registration) is optional and upcoming.

Longer table with logos: docs/product/comparison.md.

Make targets

Command reference
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 / 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

Environment variables

Variable Purpose
TOKENOPS_URL Remote plane base URL (e.g. http://localhost:7700) → HTTP register_run
TOKENOPS_EMBEDDED Set to 1 to force in-process Store (tests / single-process)
TOKENOPS_DB SQLite path shared by plane + agents
TOKENOPS_CONFIG YAML for governance seed (core: src/tokenops/config/default.yaml)

Production / multi-process: set TOKENOPS_URL; agents must not mount /v1/runs. Tests: TOKENOPS_EMBEDDED=1 (or omit URL).

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

Roadmap

TokenOps is early (0.x). Near-term:

  • User/tag segment-scoped budgets (machinery exists; seed is run-only today).
  • Optional fail-closed mode on missing registration or exceeded budget.
  • Remote observe / decide (fatter plane) for multi-host stacks.
  • Documentation site.

Status of each control-plane job: CONTROL_PLANE.md. Ideas welcome via GitHub issues.

Documentation

Contributing

Issues and PRs are welcome. Dev setup:

make install
python -m pytest -q

Contributors

Thanks to everyone who has contributed.

Contributors


If TokenOps saves you a runaway agent bill, please ⭐ star the repo so more people can find it.

Built by Susheem Koul and Tisha Chawla

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

agent_tokenops-0.1.0.tar.gz (91.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

agent_tokenops-0.1.0-py3-none-any.whl (92.4 kB view details)

Uploaded Python 3

File details

Details for the file agent_tokenops-0.1.0.tar.gz.

File metadata

  • Download URL: agent_tokenops-0.1.0.tar.gz
  • Upload date:
  • Size: 91.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for agent_tokenops-0.1.0.tar.gz
Algorithm Hash digest
SHA256 7b9ce8f99d25fe2687e069065d98abd2c4d24b7b714d401555acccdde29bb78f
MD5 d7f7cd8545923f599a77f67de9e59b27
BLAKE2b-256 a23c7f7f4ce1ab325ae762b958aaa8ce81aa6241d61bfdf3629e6e23b14e3df3

See more details on using hashes here.

Provenance

The following attestation bundles were made for agent_tokenops-0.1.0.tar.gz:

Publisher: release.yml on theagentplane/tokenops

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file agent_tokenops-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: agent_tokenops-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 92.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for agent_tokenops-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e142c6036d7c00b4bd23f7369c7e79748173fd965f471b21ecaf526bc7a99565
MD5 f4818bebbf5896dbb661949f96ec625d
BLAKE2b-256 ef6ddc55ac16e587ecf9602021261a5391b349d2ed7f18a8f6e4598da2f353ad

See more details on using hashes here.

Provenance

The following attestation bundles were made for agent_tokenops-0.1.0-py3-none-any.whl:

Publisher: release.yml on theagentplane/tokenops

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page