agent-tokenops 0.2.0__tar.gz → 0.3.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (126) hide show
  1. agent_tokenops-0.3.0/PKG-INFO +402 -0
  2. agent_tokenops-0.3.0/README.md +353 -0
  3. {agent_tokenops-0.2.0 → agent_tokenops-0.3.0}/pyproject.toml +18 -5
  4. agent_tokenops-0.3.0/src/agent_tokenops.egg-info/PKG-INFO +402 -0
  5. {agent_tokenops-0.2.0 → agent_tokenops-0.3.0}/src/agent_tokenops.egg-info/SOURCES.txt +9 -0
  6. {agent_tokenops-0.2.0 → agent_tokenops-0.3.0}/src/agent_tokenops.egg-info/requires.txt +5 -1
  7. {agent_tokenops-0.2.0 → agent_tokenops-0.3.0}/src/tokenops/__init__.py +1 -1
  8. {agent_tokenops-0.2.0 → agent_tokenops-0.3.0}/src/tokenops/control/__init__.py +17 -2
  9. {agent_tokenops-0.2.0 → agent_tokenops-0.3.0}/src/tokenops/control/client.py +69 -32
  10. {agent_tokenops-0.2.0 → agent_tokenops-0.3.0}/src/tokenops/control/config.py +32 -11
  11. agent_tokenops-0.3.0/src/tokenops/control/dev_plane.py +70 -0
  12. {agent_tokenops-0.2.0 → agent_tokenops-0.3.0}/src/tokenops/control/engine.py +36 -3
  13. {agent_tokenops-0.2.0 → agent_tokenops-0.3.0}/src/tokenops/control/http_store.py +12 -3
  14. {agent_tokenops-0.2.0 → agent_tokenops-0.3.0}/src/tokenops/control/ledger.py +230 -27
  15. agent_tokenops-0.3.0/src/tokenops/control/ledger_backend.py +277 -0
  16. {agent_tokenops-0.2.0 → agent_tokenops-0.3.0}/src/tokenops/control/models.py +11 -1
  17. {agent_tokenops-0.2.0 → agent_tokenops-0.3.0}/src/tokenops/control/policies/__init__.py +4 -1
  18. {agent_tokenops-0.2.0 → agent_tokenops-0.3.0}/src/tokenops/control/policies/concurrency_cap.py +1 -1
  19. {agent_tokenops-0.2.0 → agent_tokenops-0.3.0}/src/tokenops/control/policies/context_compaction.py +1 -1
  20. {agent_tokenops-0.2.0 → agent_tokenops-0.3.0}/src/tokenops/control/policies/cost_guard.py +1 -1
  21. {agent_tokenops-0.2.0 → agent_tokenops-0.3.0}/src/tokenops/control/policies/output_runaway.py +1 -1
  22. {agent_tokenops-0.2.0 → agent_tokenops-0.3.0}/src/tokenops/control/policies/pre_call_worst_case.py +1 -1
  23. {agent_tokenops-0.2.0 → agent_tokenops-0.3.0}/src/tokenops/control/policies/progress_guard.py +1 -1
  24. {agent_tokenops-0.2.0 → agent_tokenops-0.3.0}/src/tokenops/control/policies/step_cap.py +1 -1
  25. {agent_tokenops-0.2.0 → agent_tokenops-0.3.0}/src/tokenops/control/policies/tool_fix.py +1 -1
  26. {agent_tokenops-0.2.0 → agent_tokenops-0.3.0}/src/tokenops/control/policies/tool_output_cap.py +1 -1
  27. {agent_tokenops-0.2.0 → agent_tokenops-0.3.0}/src/tokenops/control/run.py +18 -3
  28. {agent_tokenops-0.2.0 → agent_tokenops-0.3.0}/src/tokenops/control/store.py +17 -3
  29. agent_tokenops-0.3.0/src/tokenops/demo.py +194 -0
  30. {agent_tokenops-0.2.0 → agent_tokenops-0.3.0}/src/tokenops/ui/theme.py +34 -26
  31. {agent_tokenops-0.2.0 → agent_tokenops-0.3.0}/src/tokenops/ui/views/dashboard.py +18 -2
  32. agent_tokenops-0.3.0/tests/test_a2a_health.py +140 -0
  33. {agent_tokenops-0.2.0 → agent_tokenops-0.3.0}/tests/test_control_plane_app.py +16 -11
  34. agent_tokenops-0.3.0/tests/test_control_plane_client.py +65 -0
  35. agent_tokenops-0.3.0/tests/test_demo.py +90 -0
  36. {agent_tokenops-0.2.0 → agent_tokenops-0.3.0}/tests/test_governance_config_cache.py +0 -4
  37. {agent_tokenops-0.2.0 → agent_tokenops-0.3.0}/tests/test_ledger.py +40 -0
  38. agent_tokenops-0.3.0/tests/test_ledger_backend_contract.py +142 -0
  39. agent_tokenops-0.3.0/tests/test_ledger_backend_mode.py +163 -0
  40. {agent_tokenops-0.2.0 → agent_tokenops-0.3.0}/tests/test_policies_wrap_integration.py +4 -0
  41. agent_tokenops-0.3.0/tests/test_policy_coordination.py +125 -0
  42. agent_tokenops-0.3.0/tests/test_reason_encoding.py +78 -0
  43. {agent_tokenops-0.2.0 → agent_tokenops-0.3.0}/tests/test_tokenops_run.py +22 -14
  44. {agent_tokenops-0.2.0 → agent_tokenops-0.3.0}/tests/test_trajectory_hint.py +12 -1
  45. {agent_tokenops-0.2.0 → agent_tokenops-0.3.0}/tests/test_trajectory_hint_e2e.py +10 -1
  46. agent_tokenops-0.2.0/PKG-INFO +0 -324
  47. agent_tokenops-0.2.0/README.md +0 -278
  48. agent_tokenops-0.2.0/src/agent_tokenops.egg-info/PKG-INFO +0 -324
  49. agent_tokenops-0.2.0/tests/test_control_plane_client.py +0 -88
  50. {agent_tokenops-0.2.0 → agent_tokenops-0.3.0}/LICENSE.txt +0 -0
  51. {agent_tokenops-0.2.0 → agent_tokenops-0.3.0}/setup.cfg +0 -0
  52. {agent_tokenops-0.2.0 → agent_tokenops-0.3.0}/src/agent_tokenops.egg-info/dependency_links.txt +0 -0
  53. {agent_tokenops-0.2.0 → agent_tokenops-0.3.0}/src/agent_tokenops.egg-info/top_level.txt +0 -0
  54. {agent_tokenops-0.2.0 → agent_tokenops-0.3.0}/src/tokenops/adapters/__init__.py +0 -0
  55. {agent_tokenops-0.2.0 → agent_tokenops-0.3.0}/src/tokenops/adapters/langchain.py +0 -0
  56. {agent_tokenops-0.2.0 → agent_tokenops-0.3.0}/src/tokenops/config/__init__.py +0 -0
  57. {agent_tokenops-0.2.0 → agent_tokenops-0.3.0}/src/tokenops/config/default.yaml +0 -0
  58. {agent_tokenops-0.2.0 → agent_tokenops-0.3.0}/src/tokenops/config/loader.py +0 -0
  59. {agent_tokenops-0.2.0 → agent_tokenops-0.3.0}/src/tokenops/control/attribution.py +0 -0
  60. {agent_tokenops-0.2.0 → agent_tokenops-0.3.0}/src/tokenops/control/boundary.py +0 -0
  61. {agent_tokenops-0.2.0 → agent_tokenops-0.3.0}/src/tokenops/control/context.py +0 -0
  62. {agent_tokenops-0.2.0 → agent_tokenops-0.3.0}/src/tokenops/control/core.py +0 -0
  63. {agent_tokenops-0.2.0 → agent_tokenops-0.3.0}/src/tokenops/control/crossing.py +0 -0
  64. {agent_tokenops-0.2.0 → agent_tokenops-0.3.0}/src/tokenops/control/governance_cache.py +0 -0
  65. {agent_tokenops-0.2.0 → agent_tokenops-0.3.0}/src/tokenops/control/http.py +0 -0
  66. {agent_tokenops-0.2.0 → agent_tokenops-0.3.0}/src/tokenops/control/instrument.py +0 -0
  67. {agent_tokenops-0.2.0 → agent_tokenops-0.3.0}/src/tokenops/control/integration.py +0 -0
  68. {agent_tokenops-0.2.0 → agent_tokenops-0.3.0}/src/tokenops/control/policies/_util.py +0 -0
  69. {agent_tokenops-0.2.0 → agent_tokenops-0.3.0}/src/tokenops/control/policies/cost_budget.py +0 -0
  70. {agent_tokenops-0.2.0 → agent_tokenops-0.3.0}/src/tokenops/control/policies/trajectory_hint.py +0 -0
  71. {agent_tokenops-0.2.0 → agent_tokenops-0.3.0}/src/tokenops/control/pricing.py +0 -0
  72. {agent_tokenops-0.2.0 → agent_tokenops-0.3.0}/src/tokenops/control/propagate.py +0 -0
  73. {agent_tokenops-0.2.0 → agent_tokenops-0.3.0}/src/tokenops/control/request_context.py +0 -0
  74. {agent_tokenops-0.2.0 → agent_tokenops-0.3.0}/src/tokenops/control/trajectory/__init__.py +0 -0
  75. {agent_tokenops-0.2.0 → agent_tokenops-0.3.0}/src/tokenops/control/trajectory/compress.py +0 -0
  76. {agent_tokenops-0.2.0 → agent_tokenops-0.3.0}/src/tokenops/control/trajectory/enqueue.py +0 -0
  77. {agent_tokenops-0.2.0 → agent_tokenops-0.3.0}/src/tokenops/control/trajectory/gates.py +0 -0
  78. {agent_tokenops-0.2.0 → agent_tokenops-0.3.0}/src/tokenops/control/trajectory/hint.py +0 -0
  79. {agent_tokenops-0.2.0 → agent_tokenops-0.3.0}/src/tokenops/control/trajectory/scope.py +0 -0
  80. {agent_tokenops-0.2.0 → agent_tokenops-0.3.0}/src/tokenops/control/trajectory/serialize.py +0 -0
  81. {agent_tokenops-0.2.0 → agent_tokenops-0.3.0}/src/tokenops/control/trajectory/worker.py +0 -0
  82. {agent_tokenops-0.2.0 → agent_tokenops-0.3.0}/src/tokenops/env.py +0 -0
  83. {agent_tokenops-0.2.0 → agent_tokenops-0.3.0}/src/tokenops/providers/__init__.py +0 -0
  84. {agent_tokenops-0.2.0 → agent_tokenops-0.3.0}/src/tokenops/providers/anthropic.py +0 -0
  85. {agent_tokenops-0.2.0 → agent_tokenops-0.3.0}/src/tokenops/providers/factory.py +0 -0
  86. {agent_tokenops-0.2.0 → agent_tokenops-0.3.0}/src/tokenops/providers/openai.py +0 -0
  87. {agent_tokenops-0.2.0 → agent_tokenops-0.3.0}/src/tokenops/providers/types.py +0 -0
  88. {agent_tokenops-0.2.0 → agent_tokenops-0.3.0}/src/tokenops/server/__init__.py +0 -0
  89. {agent_tokenops-0.2.0 → agent_tokenops-0.3.0}/src/tokenops/server/__main__.py +0 -0
  90. {agent_tokenops-0.2.0 → agent_tokenops-0.3.0}/src/tokenops/server/app.py +0 -0
  91. {agent_tokenops-0.2.0 → agent_tokenops-0.3.0}/src/tokenops/ui/__init__.py +0 -0
  92. {agent_tokenops-0.2.0 → agent_tokenops-0.3.0}/src/tokenops/ui/app.py +0 -0
  93. {agent_tokenops-0.2.0 → agent_tokenops-0.3.0}/src/tokenops/ui/run_detail.py +0 -0
  94. {agent_tokenops-0.2.0 → agent_tokenops-0.3.0}/src/tokenops/ui/store_client.py +0 -0
  95. {agent_tokenops-0.2.0 → agent_tokenops-0.3.0}/src/tokenops/ui/views/__init__.py +0 -0
  96. {agent_tokenops-0.2.0 → agent_tokenops-0.3.0}/src/tokenops/ui/views/admin.py +0 -0
  97. {agent_tokenops-0.2.0 → agent_tokenops-0.3.0}/tests/test_actuators.py +0 -0
  98. {agent_tokenops-0.2.0 → agent_tokenops-0.3.0}/tests/test_apply.py +0 -0
  99. {agent_tokenops-0.2.0 → agent_tokenops-0.3.0}/tests/test_attribution.py +0 -0
  100. {agent_tokenops-0.2.0 → agent_tokenops-0.3.0}/tests/test_attribution_ledger_policies_e2e.py +0 -0
  101. {agent_tokenops-0.2.0 → agent_tokenops-0.3.0}/tests/test_boundary.py +0 -0
  102. {agent_tokenops-0.2.0 → agent_tokenops-0.3.0}/tests/test_chronicle_boundary.py +0 -0
  103. {agent_tokenops-0.2.0 → agent_tokenops-0.3.0}/tests/test_concurrency_cap.py +0 -0
  104. {agent_tokenops-0.2.0 → agent_tokenops-0.3.0}/tests/test_config.py +0 -0
  105. {agent_tokenops-0.2.0 → agent_tokenops-0.3.0}/tests/test_context_compaction.py +0 -0
  106. {agent_tokenops-0.2.0 → agent_tokenops-0.3.0}/tests/test_cost_budget.py +0 -0
  107. {agent_tokenops-0.2.0 → agent_tokenops-0.3.0}/tests/test_cost_guard.py +0 -0
  108. {agent_tokenops-0.2.0 → agent_tokenops-0.3.0}/tests/test_cross_process_budget_gating.py +0 -0
  109. {agent_tokenops-0.2.0 → agent_tokenops-0.3.0}/tests/test_crossing_hook.py +0 -0
  110. {agent_tokenops-0.2.0 → agent_tokenops-0.3.0}/tests/test_governance_per_agent.py +0 -0
  111. {agent_tokenops-0.2.0 → agent_tokenops-0.3.0}/tests/test_integration.py +0 -0
  112. {agent_tokenops-0.2.0 → agent_tokenops-0.3.0}/tests/test_llm_boundary_precall.py +0 -0
  113. {agent_tokenops-0.2.0 → agent_tokenops-0.3.0}/tests/test_output_runaway.py +0 -0
  114. {agent_tokenops-0.2.0 → agent_tokenops-0.3.0}/tests/test_pre_call_worst_case.py +0 -0
  115. {agent_tokenops-0.2.0 → agent_tokenops-0.3.0}/tests/test_preview_mode.py +0 -0
  116. {agent_tokenops-0.2.0 → agent_tokenops-0.3.0}/tests/test_pricing.py +0 -0
  117. {agent_tokenops-0.2.0 → agent_tokenops-0.3.0}/tests/test_progress_guard.py +0 -0
  118. {agent_tokenops-0.2.0 → agent_tokenops-0.3.0}/tests/test_propagate.py +0 -0
  119. {agent_tokenops-0.2.0 → agent_tokenops-0.3.0}/tests/test_server_enforcement.py +0 -0
  120. {agent_tokenops-0.2.0 → agent_tokenops-0.3.0}/tests/test_step_cap.py +0 -0
  121. {agent_tokenops-0.2.0 → agent_tokenops-0.3.0}/tests/test_store.py +0 -0
  122. {agent_tokenops-0.2.0 → agent_tokenops-0.3.0}/tests/test_thread_safety.py +0 -0
  123. {agent_tokenops-0.2.0 → agent_tokenops-0.3.0}/tests/test_tool_fix.py +0 -0
  124. {agent_tokenops-0.2.0 → agent_tokenops-0.3.0}/tests/test_tool_output_cap.py +0 -0
  125. {agent_tokenops-0.2.0 → agent_tokenops-0.3.0}/tests/test_wrap_adapters.py +0 -0
  126. {agent_tokenops-0.2.0 → agent_tokenops-0.3.0}/tests/test_wrap_complete_chronicle.py +0 -0
@@ -0,0 +1,402 @@
1
+ Metadata-Version: 2.4
2
+ Name: agent-tokenops
3
+ Version: 0.3.0
4
+ Summary: TokenOps control plane and SDK for run-aware agent token governance
5
+ Author: Susheem Koul, Tisha Chawla
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/theagentplane/tokenops
8
+ Project-URL: Repository, https://github.com/theagentplane/tokenops
9
+ Project-URL: Issues, https://github.com/theagentplane/tokenops/issues
10
+ Project-URL: Changelog, https://github.com/theagentplane/tokenops/blob/main/CHANGELOG.md
11
+ Keywords: llm,agents,governance,token-budget,multi-agent,control-plane,cost-control
12
+ Classifier: Development Status :: 3 - Alpha
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3.10
16
+ Classifier: Programming Language :: Python :: 3.11
17
+ Classifier: Programming Language :: Python :: 3.12
18
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
19
+ Classifier: Topic :: System :: Systems Administration
20
+ Requires-Python: >=3.10
21
+ Description-Content-Type: text/markdown
22
+ License-File: LICENSE.txt
23
+ Requires-Dist: agent-chronicle>=0.3.0
24
+ Requires-Dist: openai>=1.0
25
+ Requires-Dist: anthropic>=0.40
26
+ Requires-Dist: pyyaml>=6.0
27
+ Requires-Dist: python-dotenv>=1.0
28
+ Requires-Dist: streamlit<2,>=1.38
29
+ Requires-Dist: httpx>=0.27
30
+ Requires-Dist: fastapi>=0.115
31
+ Requires-Dist: uvicorn>=0.32
32
+ Provides-Extra: dev
33
+ Requires-Dist: pytest>=8.0; extra == "dev"
34
+ Requires-Dist: pytest-asyncio>=0.24; extra == "dev"
35
+ Requires-Dist: build>=1.2; extra == "dev"
36
+ Requires-Dist: twine>=6.0; extra == "dev"
37
+ Requires-Dist: ruff>=0.8; extra == "dev"
38
+ Requires-Dist: mypy>=1.13; extra == "dev"
39
+ Requires-Dist: pre-commit>=4.0; extra == "dev"
40
+ Requires-Dist: types-PyYAML>=6.0; extra == "dev"
41
+ Provides-Extra: contract
42
+ Requires-Dist: agentplane-control-plane>=0.2.0; extra == "contract"
43
+ Provides-Extra: examples
44
+ Requires-Dist: ddgs>=9.0; extra == "examples"
45
+ Requires-Dist: langchain-core>=0.3; extra == "examples"
46
+ Requires-Dist: langchain-openai>=0.2; extra == "examples"
47
+ Requires-Dist: langchain-anthropic>=0.2; extra == "examples"
48
+ Dynamic: license-file
49
+
50
+ <div align="center">
51
+
52
+ # TokenOps
53
+
54
+ **Cuts wasted agent spend by up to `65%`, governing what the run has already spent before every call.**<br>
55
+ <sub>Toward token governance as a first-class discipline, not an afterthought.</sub>
56
+
57
+ [![PyPI](https://img.shields.io/pypi/v/agent-tokenops.svg)](https://pypi.org/project/agent-tokenops/)
58
+ [![Downloads](https://img.shields.io/pepy/dt/agent-tokenops)](https://pepy.tech/project/agent-tokenops)
59
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE.txt)
60
+ [![GitHub stars](https://img.shields.io/github/stars/theagentplane/tokenops?style=social)](https://github.com/theagentplane/tokenops/stargazers)
61
+ [![LinkedIn](https://img.shields.io/badge/LinkedIn-0A66C2?logo=linkedin&logoColor=white)](https://www.linkedin.com/company/the-agent-plane/)
62
+ [![GitHub Discussions](https://img.shields.io/badge/Discussions-24292f?logo=github&logoColor=white)](https://github.com/theagentplane/tokenops/discussions)
63
+
64
+ [![Featured by Microsoft Developer](https://img.shields.io/badge/Featured-Microsoft%20Developer-5E5E5E)](https://www.linkedin.com/posts/microsoft-developers_who-spent-all-the-tokens-tokenops-gives-activity-7499191980715982848-224b)
65
+ [![Featured by Command Line](https://img.shields.io/badge/Featured-Command%20Line-5E5E5E)](https://commandline.microsoft.com/tokenops-real-time-run-scoped-cost-control-ai-agents/)
66
+ [![Featured by AI Engineer World's Fair](https://img.shields.io/badge/Featured-AI%20Engineer%20World's%20Fair-FF0000?logo=youtube&logoColor=white)](https://www.youtube.com/watch?v=GJX19pNhmSw)
67
+
68
+ <sub>Built by <b><a href="https://www.linkedin.com/in/susheemkoul/">Susheem Koul</a></b> and <b><a href="https://www.linkedin.com/in/tisha-chawla/">Tisha Chawla</a></b></sub>
69
+
70
+ <table><tr><td>
71
+
72
+ <img src="https://raw.githubusercontent.com/theagentplane/tokenops/main/docs/assets/devto-cover.png" alt="TokenOps: one budget for one whole agent run, enforced before every model call" width="720" />
73
+
74
+ </td></tr></table>
75
+
76
+ <sub><i>See it stop a run mid-budget in the <a href="#-quickstart">Quickstart</a> below.</i></sub>
77
+
78
+ <br>
79
+
80
+ [Core features](#-core-features) · [Quickstart](#-quickstart) · [Quickdeploy](#-quickdeploy) · [How it compares](#-how-tokenops-compares) · [Policies](docs/policies/) · [Support](#-support) · [Contributing](#-open-to-contribution)
81
+
82
+ </div>
83
+
84
+ > ### 🙌 Open to contribution
85
+ >
86
+ > Token spend deserves the same first-class attention as compute or latency, and
87
+ > we are growing the community working on that. Policies, actuators, and the
88
+ > shared ledger are all open to extension. See
89
+ > **[CONTRIBUTING.md](CONTRIBUTING.md)** to get started.
90
+
91
+ ## ✨ Core features
92
+
93
+ An AI agent's workflow can run up cost fast: dozens of small, individually
94
+ cheap steps that quietly add up to a surprisingly large bill. TokenOps sets
95
+ a single budget for the whole workflow and enforces it before every step,
96
+ so spending never gets away from you.
97
+
98
+ <img src="docs/assets/core-features.svg" alt="TokenOps core features: enforced pre-call, run-scoped budget, shared across processes, steers not just stops, tool calls count too, ten policies included" width="850" />
99
+
100
+ Ten policies ship configured in [`docs/policies/`](docs/policies/), and you can
101
+ add your own.
102
+
103
+ ## 🚀 Quickstart
104
+
105
+ Requires Python 3.10+ and a running control plane — TokenOps has no ledger of its
106
+ own, so every agent (even a single process) governs against one. Zero-setup taste:
107
+ `python -m tokenops.demo` launches a throwaway plane for you automatically. For your
108
+ own agent, start one first (see [Quickdeploy](#-quickdeploy) below), then:
109
+
110
+ ### 1. Put it in your agent
111
+
112
+ > [!TIP]
113
+ > **Recommended.** Your coding assistant reads
114
+ > [`SKILL.md`](.claude/skills/integrate-tokenops/SKILL.md), wires the one
115
+ > enforcement point into your agent, and tells you what to check.
116
+
117
+ In **Claude Code**, from a clone:
118
+
119
+ ```
120
+ /integrate-tokenops
121
+ ```
122
+
123
+ Anywhere else (Cursor, Copilot, ...), paste this:
124
+
125
+ > Integrate TokenOps into this agent, following
126
+ > https://github.com/theagentplane/tokenops/blob/main/.claude/skills/integrate-tokenops/SKILL.md
127
+
128
+ <details>
129
+ <summary><b>Manual</b>, about ten lines</summary>
130
+
131
+ Wrap your model call once, then hand the wrapped version to your agent. Needs
132
+ `CONTROL_PLANE_URL` (or `TOKENOPS_URL`) pointing at a running control plane —
133
+ see [Quickdeploy](#-quickdeploy).
134
+
135
+ ```python
136
+ from tokenops import ControlPlaneClient, tokenops_run
137
+ from tokenops.control import Halt, wrap_complete
138
+ from tokenops.providers import complete
139
+
140
+ client = ControlPlaneClient.from_env() # raises if CONTROL_PLANE_URL isn't set
141
+
142
+ with tokenops_run(client=client, service="my-agent", intent="research",
143
+ provider="openai", model="gpt-4o") as bound:
144
+ governed = wrap_complete(
145
+ bound.governor, bound.controls, bound.attr,
146
+ provider="openai", model="gpt-4o",
147
+ dispatch=complete, service="my-agent",
148
+ )
149
+ try:
150
+ agent.run(..., complete_fn=governed) # <-- pass `governed`, not `complete`
151
+ except Halt as stopped:
152
+ print(f"run stopped: {stopped}")
153
+ ```
154
+
155
+ Pass `governed` to your agent instead of `complete`; nothing else changes.
156
+ `wrap_complete` checks the budget before each call and raises `Halt` when the
157
+ run is out, even from another process.
158
+
159
+ </details>
160
+
161
+ ### 2. When you need more
162
+
163
+ | You want to | Go to |
164
+ |---|---|
165
+ | Change the budget | [Set the budget](.claude/skills/integrate-tokenops/SKILL.md#set-the-budget) |
166
+ | One budget across several agent processes | [Shared plane](.claude/skills/integrate-tokenops/SKILL.md#tier-2--several-processes-one-budget) |
167
+ | FastAPI or A2A services | [Instrumented app](.claude/skills/integrate-tokenops/SKILL.md#tier-3--fastapi--a2a) |
168
+ | Something other than stopping | [The ten policies](docs/policies/) |
169
+ | Cost per agent in a dashboard | [Quickdeploy](#-quickdeploy) |
170
+ | A worked end-to-end example | [Field guide](docs/guides/field-guide-add-tokenops.md) |
171
+ | Everything else | [Onboarding guide](docs/guides/onboarding.md) |
172
+
173
+ ### 3. See it in action
174
+
175
+ <table><tr><td>
176
+
177
+ <a href="https://github.com/theagentplane/tokenops/raw/main/examples/demo-assets/videos/02_governance_on_budget_cap.webm">
178
+ <img src="https://raw.githubusercontent.com/theagentplane/tokenops/main/examples/demo-assets/videos/02_governance_on_budget_cap.gif" alt="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" width="760" />
179
+ </a>
180
+
181
+ </td></tr></table>
182
+
183
+ <sub><i>Same task, run twice: ungoverned it completes over budget, governed it halts within the cap, then the Dashboard attributes cost per agent. <a href="https://github.com/theagentplane/tokenops/raw/main/examples/demo-assets/videos/02_governance_on_budget_cap.webm">Full video</a>.</i></sub>
184
+
185
+ ## 🐳 Quickdeploy
186
+
187
+ > [!TIP]
188
+ > Every agent needs a control plane running — TokenOps has no ledger of its own.
189
+ > A single-process agent still needs one, just not the multi-process sharing this
190
+ > section is about. `python -m tokenops.server` powers the dashboard too.
191
+
192
+ One command, plane + dashboard:
193
+
194
+ ```bash
195
+ git clone https://github.com/theagentplane/tokenops && cd tokenops
196
+ docker compose --profile ui up --build
197
+ ```
198
+
199
+ Plane: `localhost:7700/health` · Dashboard: `localhost:8501`. Plane only:
200
+ `docker compose up --build`. Details: [`docs/control-plane-deploy.md`](docs/control-plane-deploy.md).
201
+
202
+ <details>
203
+ <summary><b>Without Docker</b> (make)</summary>
204
+
205
+ ```bash
206
+ git clone https://github.com/theagentplane/tokenops && cd tokenops
207
+ make install
208
+ make run # control plane :7700 + Admin/Dashboard :8501
209
+ ```
210
+
211
+ Then open `localhost:8501` to see spend and governance per agent.
212
+
213
+ </details>
214
+
215
+ <details>
216
+ <summary><b>Multi-agent benches</b>: watch one budget span several agents</summary>
217
+
218
+ Each is a real multi-agent stack sharing one run ledger. One target starts the
219
+ plane, the agents, and the Admin UI.
220
+
221
+ | Bench | Agents | Run |
222
+ |---|---|---|
223
+ | Two-agent | Research to Summarize | `make demo` |
224
+ | Triad | Planner to Researcher to Writer | `make demo-triad` |
225
+ | Brief | Scout to Analyst to Editor (LangChain) | `make demo-brief` |
226
+ | Bench UI | Chat + Simulator only | `make bench-ui` |
227
+
228
+ `cp .env.example .env` first if you want them to call real models. See
229
+ [`examples/README.md`](examples/README.md) for the bench profiles.
230
+
231
+ </details>
232
+
233
+ <details>
234
+ <summary><b>Pointing several processes at one plane</b></summary>
235
+
236
+ ```bash
237
+ export TOKENOPS_URL=http://localhost:7700
238
+ export TOKENOPS_DB=tokenops.db # plane and every agent read the same file
239
+ ```
240
+
241
+ > tokenops has no ledger of its own — every process governs against the plane at
242
+ > `TOKENOPS_URL`. There is no local-fallback env var to accidentally leave unset.
243
+
244
+ PyPI name is `agent-tokenops`; the import is `tokenops`. Extras:
245
+ `pip install "agent-tokenops[examples]"` for the LangChain benches,
246
+ `".[dev,examples]"` from source. Releases: [`RELEASING.md`](RELEASING.md).
247
+
248
+ </details>
249
+
250
+ ## 🆚 How TokenOps compares
251
+
252
+ 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.
253
+
254
+ | | TokenOps | LiteLLM / Portkey / AI Gateway | Langfuse |
255
+ |---|:---:|:---:|:---:|
256
+ | Primary focus | Run | Request | Trace |
257
+ | Multi-agent workflow as one unit | Yes | No | Partial |
258
+ | Budget enforcement in-path | Yes | Yes | No |
259
+ | Steer next call (mutate / inject) | Yes | Partial | No |
260
+ | Shared ledger across processes | Yes | — | — |
261
+
262
+ What this does **not** do: replace your LLM gateway, replace Chronicle-style record-and-replay, or host a SaaS control plane for you.
263
+
264
+ Longer table with logos: [`docs/product/comparison.md`](docs/product/comparison.md).
265
+
266
+ ## Reference
267
+
268
+ Things you will want eventually, not now.
269
+
270
+ <details>
271
+ <summary><b>Architecture: how the plane and the SDK split the work</b></summary>
272
+
273
+ 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.
274
+
275
+ ```mermaid
276
+ flowchart LR
277
+ subgraph PLANE["Control plane (:7700)"]
278
+ R["POST /v1/runs"] --> DB[("SQLite TOKENOPS_DB<br/>registrations · budgets · policies · ledger")]
279
+ UI["Admin + Dashboard"] --> DB
280
+ end
281
+
282
+ subgraph AGENTS["Agent processes (SDK)"]
283
+ E["Entry agent<br/>tokenops_run"] -->|"register_run"| R
284
+ E -->|"X-TokenOps-Run-Id"| D["Downstream agents<br/>tokenops_run"]
285
+ E & D -->|"wrap_complete"| G["Governor<br/>pre_call → detect → decide → apply"]
286
+ E & D -->|"@boundary + crossing hook"| G
287
+ G --> L["Shared ledger<br/>(same run_id)"]
288
+ end
289
+
290
+ L --> DB
291
+ DB -->|"governance_config_for"| G
292
+ ```
293
+
294
+ | Piece | Owns | Does not own |
295
+ |---|---|---|
296
+ | **Control plane** (`python -m tokenops.server`) | `POST /v1/runs`, shared SQLite, Admin/Dashboard | Agent loops, LLM calls, tools |
297
+ | **SDK (in agents)** | `tokenops_run`, `wrap_complete`, ledger/policies, Chronicle crossing hook | Ad-hoc run IDs; mounting `/v1/runs` when `TOKENOPS_URL` is set |
298
+
299
+ Chronicle records decision boundaries; TokenOps attaches as the cost/governance observer on live crossings. See [Chronicle](https://github.com/theagentplane/chronicle) for record-and-replay, accepted at [REALM](https://realm-workshop.github.io/) (Research on Agent Language Models), a workshop at EMNLP 2026.
300
+
301
+ </details>
302
+
303
+ <details>
304
+ <summary><b>Environment variables</b></summary>
305
+
306
+ | Variable | Purpose |
307
+ |---|---|
308
+ | `TOKENOPS_URL` (or `CONTROL_PLANE_URL`) | The control plane's base URL (e.g. `http://localhost:8800`) — **required** |
309
+ | `TOKENOPS_CONFIG` | YAML for governance seed (core: `src/tokenops/config/default.yaml`) |
310
+
311
+ tokenops has no ledger or run registry of its own — `ControlPlaneClient.from_env()`
312
+ raises if `TOKENOPS_URL`/`CONTROL_PLANE_URL` isn't set, rather than silently falling
313
+ back to anything local. Every process talks to the same plane, so they share one
314
+ budget by construction. `TOKENOPS_URL` also accepts the alias
315
+ `TOKENOPS_CONTROL_PLANE_URL`.
316
+
317
+ </details>
318
+
319
+ <details>
320
+ <summary><b>Make targets</b></summary>
321
+
322
+ | Target | Role |
323
+ |--------|------|
324
+ | `make install` | Editable install with dev + examples extras |
325
+ | `make dist` / `check-dist` | Build sdist+wheel / `twine check` |
326
+ | `make control-plane` | Standalone plane (`python -m tokenops.server`) on `:7700` |
327
+ | `make ui` | Admin + Dashboard on `:8501` |
328
+ | `make run` | Plane + Admin/Dashboard |
329
+ | `make demo-quick` | `python -m tokenops.demo`: no API keys, no server |
330
+ | `make demo` / `demo-triad` / `demo-brief` | Runnable A2A stacks |
331
+ | `make bench-ui` | Chat + Simulator |
332
+ | `make db-reset` | Clear SQLite + reseed from `TOKENOPS_CONFIG` |
333
+ | `make stop` | Kill listeners on `:7700` / `:8501` |
334
+ | `make sync-skills` | Regenerate the editor copies of the integration skill |
335
+
336
+ </details>
337
+
338
+ <details>
339
+ <summary><b>Project structure</b></summary>
340
+
341
+ Only `src/tokenops/` is the installable package. Demos and benches stay under `examples/`.
342
+
343
+ ```
344
+ src/tokenops/ # installable package
345
+ ├── server/ # control plane (:7700, POST /v1/runs)
346
+ ├── control/ # SDK: ledger, policies, wrap_complete, crossing hook
347
+ ├── providers/ # OpenAI / Anthropic complete dispatch
348
+ ├── config/ # default.yaml governance seed
349
+ └── ui/ # Admin + Dashboard (Streamlit)
350
+ examples/ # A2A benches (two-agent, triad, brief) + Chat/Simulator
351
+ benchmarking/ # MetaGPT / browser-use live harness
352
+ docs/ # architecture, policies, guides, product
353
+ tests/ # unit + e2e
354
+ ```
355
+
356
+ </details>
357
+
358
+ <details>
359
+ <summary><b>More documentation</b></summary>
360
+
361
+ - [Onboarding](docs/guides/onboarding.md): prereqs, minimum integration, FAQ, current limits
362
+ - [Field guide](docs/guides/field-guide-add-tokenops.md): a triad walked through, with screenshots
363
+ - [Policies](docs/policies/): one page per policy
364
+ - [Run attribution](docs/run-attribution.md) - [control plane deploy](docs/control-plane-deploy.md) - [status](docs/control-plane-status.md)
365
+ - [Examples](examples/README.md) - [comparison](docs/product/comparison.md) - [shared ledger](docs/product/shared-ledger.md)
366
+
367
+ </details>
368
+
369
+ ## 📰 Talks & press
370
+
371
+ - **Featured by Microsoft Developer**: “Who spent all the tokens?” on
372
+ [LinkedIn](https://www.linkedin.com/posts/microsoft-developers_who-spent-all-the-tokens-tokenops-gives-activity-7499191980715982848-224b) and [X](https://x.com/msdev/status/2093425027500978292).
373
+ - **[Who spent all the tokens? Real-time, run-scoped cost control for AI agents](https://commandline.microsoft.com/tokenops-real-time-run-scoped-cost-control-ai-agents/)**: *Command Line*, a Microsoft publication.
374
+ - **[FinOps for AI Agents: Who Spent All the Tokens?](https://www.youtube.com/watch?v=GJX19pNhmSw)**: talk at the **AI Engineer World's Fair**, San Francisco.
375
+ - **Selected to participate in the [GitHub Secure Open Source Fund](https://github.com/open-source/github-secure-open-source-fund)** (Session 5), GitHub Security Lab's open source security program.
376
+
377
+ ## 🛟 Support
378
+
379
+ | Need | Where |
380
+ |---|---|
381
+ | Bug | [Open an issue](https://github.com/theagentplane/tokenops/issues) |
382
+ | Security issue | [SECURITY.md](SECURITY.md) |
383
+ | Real-time help | [Slack](https://join.slack.com/t/theagentplane/shared_invite/zt-47lqx2xtc-0idr1cuLNJ_JDTgqxDiUsg) |
384
+ | Longer-form discussion | [GitHub Discussions](https://github.com/theagentplane/tokenops/discussions) |
385
+ | Talk it through | [Office hours](https://calendly.com/theagentplane/theagentplane) |
386
+ | Talks & writing | [theagentplane.github.io/media](https://theagentplane.github.io/media.html) |
387
+
388
+ ## Contributors
389
+
390
+ Thanks to everyone who has contributed.
391
+
392
+ [![Contributors](https://contrib.rocks/image?repo=theagentplane/tokenops)](https://github.com/theagentplane/tokenops/graphs/contributors)
393
+
394
+ ---
395
+
396
+ Saved you tokens? [⭐ Star the repo](https://github.com/theagentplane/tokenops).
397
+
398
+ <div align="center">
399
+
400
+ [Back to top](#tokenops)
401
+
402
+ </div>