adk-tracegauge 0.1.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.
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the
45
+ purposes of this License, Derivative Works shall not include works
46
+ that remain separable from, or merely link (or bind by name) to the
47
+ interfaces of, the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including the
50
+ original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
@@ -0,0 +1,108 @@
1
+ Metadata-Version: 2.4
2
+ Name: adk-tracegauge
3
+ Version: 0.1.0
4
+ Summary: Per-invocation cost-in-USD evaluator for Google's Agent Development Kit (ADK), built on tracegauge's cost engine. Raw dollars and tokens, no calibrated bands, no fabricated numbers for unknown models.
5
+ Author-email: Gaurav Gandhi <gaurav.gandhi2411@gmail.com>
6
+ License-Expression: Apache-2.0
7
+ Project-URL: Repository, https://github.com/gaurav-gandhi-2411/adk-tracegauge
8
+ Keywords: adk,agent-development-kit,google-adk,evaluation,cost,token-efficiency
9
+ Classifier: Development Status :: 3 - Alpha
10
+ Classifier: Programming Language :: Python :: 3
11
+ Classifier: Programming Language :: Python :: 3.10
12
+ Classifier: Programming Language :: Python :: 3.11
13
+ Classifier: Programming Language :: Python :: 3.12
14
+ Classifier: Programming Language :: Python :: 3.13
15
+ Classifier: Topic :: Software Development :: Quality Assurance
16
+ Classifier: Topic :: Utilities
17
+ Classifier: Intended Audience :: Developers
18
+ Classifier: Environment :: Console
19
+ Classifier: Operating System :: OS Independent
20
+ Requires-Python: >=3.10
21
+ Description-Content-Type: text/markdown
22
+ License-File: LICENSE
23
+ Requires-Dist: google-adk[eval]<2.7.0,>=2.6.0
24
+ Requires-Dist: tracegauge<0.11.0,>=0.10.0
25
+ Dynamic: license-file
26
+
27
+ # adk-tracegauge
28
+
29
+ Per-invocation dollar cost for [Google ADK](https://github.com/google/adk-python) agent evaluations, built on [tracegauge](https://github.com/gaurav-gandhi-2411/token-efficiency-scorer)'s cost engine. ADK's own `evaluation` package reports zero cost or token-efficiency data on any built-in metric — this fills exactly that gap, nothing more.
30
+
31
+ [![License: Apache-2.0](https://img.shields.io/badge/License-Apache--2.0-blue.svg)](LICENSE)
32
+ [![Python 3.10+](https://img.shields.io/badge/python-3.10%2B-blue.svg)](https://pypi.org/project/adk-tracegauge/)
33
+
34
+ ---
35
+
36
+ ## Required: wrap your agent in an App with the plugin
37
+
38
+ **This is a hard requirement, not a caveat.** ADK's `Invocation` objects — what an evaluator normally receives — never carry token usage or model identity; ADK strips that down to author+content before an evaluator ever sees it. The real data lives on the `LlmResponse` passed to `BasePlugin.after_model_callback` during inference. That part fires for any real ADK run, App or not — but ADK's **eval harness specifically** (`LocalEvalService`, which `AgentEvaluator` and the `adk eval` CLI both sit on top of) only pulls plugins from `app.plugins` when you pass it an `App`. Evaluate against a bare `root_agent` with no `App`, and `LocalEvalService` builds its Runner with only its own internal eval plugins — **your plugins, including this one, are silently never included.** This package will report `no usage captured` for every single invocation, not an error.
39
+
40
+ ```python
41
+ from adk_tracegauge import TraceGaugeUsagePlugin
42
+ from google.adk.apps import App
43
+
44
+ app = App(name="my_app", root_agent=root_agent, plugins=[TraceGaugeUsagePlugin()])
45
+ ```
46
+
47
+ `App`'s constructor requires `name` — there's no default, and there's no `agent=` alias for `root_agent=`, easy typos to make since other ADK APIs use `agent`. Then reference `adk_tracegauge_cost_usd` as a `metric_name` in your eval config, and make sure `AgentEvaluator` picks up this `app` (it looks for an `app` attribute in your agent module automatically).
48
+
49
+ ## Install
50
+
51
+ ```bash
52
+ pip install "adk-tracegauge"
53
+ ```
54
+
55
+ `google-adk[eval]` and `tracegauge` are pulled in as dependencies. The `[eval]` extra on `google-adk` is not optional here even though this package doesn't use any of what it gates (pandas, jinja2, rouge-score, gepa, Vertex AI eval) — `google-adk`'s own `metric_evaluator_registry.py` unconditionally imports every one of its built-in evaluators at module import time, including the Vertex AI facade, which needs those packages just to import cleanly. Without the extra, `import adk_tracegauge` fails with `ModuleNotFoundError: No module named 'pandas'` — an ADK packaging quirk, not something this package controls.
56
+
57
+ ## What it reports, and what it deliberately doesn't
58
+
59
+ - **`score`**: raw cost in USD for the invocation, summed across every real model call within it (tool loops and sub-agent delegation can mean more than one model call per invocation). Not normalized, not calibrated, not a 0–1 quality score.
60
+ - **`rationale`** (the only other channel ADK's native reporting preserves — see "Why this metric always reports NOT_EVALUATED" below): a per-call breakdown — model, fresh/cached/output token counts, and their individual dollar costs.
61
+ - **No calibrated efficiency bands.** tracegauge's own token-economy axis compares your numbers against a baseline built from 75 Claude Code sessions. That baseline is not used here, on purpose — applying a Claude-Code-derived baseline to ADK agent behavior would be an unvalidated transfer, and a plausible-looking-but-wrong number is worse than no number. This package reports raw counts and dollars only; set your own thresholds for what "too expensive" means for your agent.
62
+ - **No trajectory-quality judging.** tracegauge's Ollama/Anthropic-based trajectory axis is out of scope for v1 — it's CC-specific tooling, unrelated to the cost story, and would add a dependency this package doesn't need.
63
+
64
+ ## Why this metric always reports `NOT_EVALUATED`
65
+
66
+ ADK's built-in pass/fail convention is `PASSED if score >= threshold else FAILED` — hardcoded, higher-is-better. Cost is lower-is-better. There is no lower-is-better or inverted-metric convention anywhere in `google.adk.evaluation` to plug into (checked directly against the source, not assumed). Silently negating the score to make the built-in gate technically "work" would misrepresent the number to anyone reading it — a `score: -0.0043` needs an explanation to even parse. So this metric doesn't participate in ADK's pass/fail gating: it always reports `eval_status=NOT_EVALUATED`, whatever threshold you configure. Read `score` directly, or write your own comparison against it.
67
+
68
+ ## Gemini pricing
69
+
70
+ `tracegauge`'s bundled price table covers Claude models only (its own domain — Claude Code sessions). ADK is Gemini-native, so this package ships and owns its own Gemini price table (`src/adk_tracegauge/data/gemini_prices.json`), passed explicitly into tracegauge's cost engine.
71
+
72
+ - Every entry carries its own `source_url` and `fetched_on` date — currently `https://ai.google.dev/gemini-api/docs/pricing`, fetched 2026-08-13. **Prices change without notice.** Verify against the source before relying on a number for a real budget decision.
73
+ - Standard tier only (no batch/flex/priority). Covers `gemini-2.5-pro`, `gemini-2.5-flash`, `gemini-2.5-flash-lite`, `gemini-2.0-flash` (deprecated, kept for historical sessions), `gemini-3.5-flash`, `gemini-3.5-flash-lite`, `gemini-3.6-flash`.
74
+ - **Known gap:** `gemini-2.5-pro` is priced at its ≤200k-token-context rate only. Gemini bills >200k-context Pro calls at roughly double that rate; this table has no per-call tiered-pricing logic, so long-context Pro invocations will be under-priced. Not silently wrong — documented here and in the price table's own per-entry `note` field.
75
+ - Cache-read discount is `0.1x` the model's fresh input rate for every model (verified against the published rate for each model individually, not assumed from tracegauge's Claude convention — it happens to match). Cache-*write* multipliers are `0.0`: Gemini's default automatic caching has no write-time surcharge and no `cache_creation` token field in its usage metadata at all, unlike Anthropic's explicit cache-write billing.
76
+
77
+ **An invocation whose model isn't in this table is never priced with a fallback rate.** `score` reports `None`, and the rationale names exactly which model string didn't resolve and lists every model this package knows how to price. A cost number for the wrong model is worse than no number, so this package doesn't produce one.
78
+
79
+ ### Staleness — what happens when Gemini's prices change and the table doesn't
80
+
81
+ A per-entry `source_url`/`fetched_on` date is provenance, not a freshness guarantee — nothing stops the table from silently aging out unless something actually checks it. Two independent things do:
82
+
83
+ - **At use time**: every `ResolvedModel.is_stale` check compares `fetched_on` against today; past 180 days (`STALE_THRESHOLD_DAYS` in `_pricing.py`), a priced result's `rationale` gets a `PRICE TABLE STALE` line naming the model and threshold, and a real `warnings.warn(...)` fires alongside it — visible to anyone watching logs, not only whoever reads that one invocation's output. Staleness never blocks the number; it warns and still reports it, on the position that a flagged-possibly-wrong number beats no number for something you already computed.
84
+ - **In CI**: `test_bundled_table_is_not_currently_stale` (`tests/test_pricing.py`) re-checks every bundled entry against the same 180-day threshold on every run. Once the table crosses it, this test starts failing on its own — not only when someone happens to notice a suspicious dollar figure.
85
+
86
+ **Updating the price table**: edit `src/adk_tracegauge/data/gemini_prices.json` — update `input_usd_per_mtok`/`output_usd_per_mtok` against the current values at the `source_url` already on each entry, and bump `fetched_on` to today. Run `pytest tests/test_pricing.py` to confirm the staleness test goes green and nothing else broke, then open a PR. There's no automated price-scraping here by design — a human should look at the actual pricing page before a dollar figure changes.
87
+
88
+ ## Compatibility risk
89
+
90
+ Registration uses `google.adk.evaluation.metric_evaluator_registry`, which google-adk marks `@experimental`: "may change or be removed... at any time," with no SemVer guarantee. This package pins `google-adk[eval]>=2.6.0,<2.7.0` accordingly — narrow, re-validated deliberately on each bump, not left open-ended.
91
+
92
+ If the registry API breaks in a future google-adk release, registration happens at import time as a side effect, so the failure mode is a loud, immediate `AttributeError`/`TypeError` on `import adk_tracegauge` — not a silent no-op or a subtly wrong result. That's a favorable failure mode worth naming explicitly: you'll know immediately, not after a bad number reaches a dashboard.
93
+
94
+ A scheduled CI job (`.github/workflows/pypi-canary.yml`) installs the *latest* `google-adk[eval]` release (ignoring the pin) and runs the full test suite weekly, so a break surfaces on a schedule rather than via a user bug report.
95
+
96
+ The plugin half of this package (`BasePlugin.after_model_callback`) sits on firmer ground — it isn't marked `@experimental` anywhere in `google-adk`. If the registry API breaks, the usage-capture half likely still works; only evaluator registration needs a patch.
97
+
98
+ ## Relationship to tracegauge
99
+
100
+ This package depends on `tracegauge`'s `tes.cost` module (`compute_session_cost` and its digest types) as a library. `tracegauge` overall is AGPL-3.0-only, but `tes/cost.py` and `tes/_digest.py` specifically are additionally available under Apache-2.0 — see [tracegauge's license note](https://github.com/gaurav-gandhi-2411/token-efficiency-scorer#license) — which is what lets this package stay Apache-2.0 itself. Every other part of tracegauge (the token-economy/trajectory/waste axes, the CLI, the dashboard) remains AGPL-3.0-only and is not used here.
101
+
102
+ ## What this is not
103
+
104
+ Not a general ADK observability/tracing tool — see `traceAI-google-adk` for that. Not a statistics/confidence-interval layer for ADK evaluation results — that's a separate, harder problem ([agentgauge](https://github.com/gaurav-gandhi-2411/agentgauge)'s domain) blocked by the same `EvalMetricResult` field-stripping this package works around by using `score`+`rationale` only. Not a replacement for any of ADK's quality metrics — this reports cost alongside them, not instead of them.
105
+
106
+ ## License
107
+
108
+ [Apache-2.0](LICENSE).
@@ -0,0 +1,82 @@
1
+ # adk-tracegauge
2
+
3
+ Per-invocation dollar cost for [Google ADK](https://github.com/google/adk-python) agent evaluations, built on [tracegauge](https://github.com/gaurav-gandhi-2411/token-efficiency-scorer)'s cost engine. ADK's own `evaluation` package reports zero cost or token-efficiency data on any built-in metric — this fills exactly that gap, nothing more.
4
+
5
+ [![License: Apache-2.0](https://img.shields.io/badge/License-Apache--2.0-blue.svg)](LICENSE)
6
+ [![Python 3.10+](https://img.shields.io/badge/python-3.10%2B-blue.svg)](https://pypi.org/project/adk-tracegauge/)
7
+
8
+ ---
9
+
10
+ ## Required: wrap your agent in an App with the plugin
11
+
12
+ **This is a hard requirement, not a caveat.** ADK's `Invocation` objects — what an evaluator normally receives — never carry token usage or model identity; ADK strips that down to author+content before an evaluator ever sees it. The real data lives on the `LlmResponse` passed to `BasePlugin.after_model_callback` during inference. That part fires for any real ADK run, App or not — but ADK's **eval harness specifically** (`LocalEvalService`, which `AgentEvaluator` and the `adk eval` CLI both sit on top of) only pulls plugins from `app.plugins` when you pass it an `App`. Evaluate against a bare `root_agent` with no `App`, and `LocalEvalService` builds its Runner with only its own internal eval plugins — **your plugins, including this one, are silently never included.** This package will report `no usage captured` for every single invocation, not an error.
13
+
14
+ ```python
15
+ from adk_tracegauge import TraceGaugeUsagePlugin
16
+ from google.adk.apps import App
17
+
18
+ app = App(name="my_app", root_agent=root_agent, plugins=[TraceGaugeUsagePlugin()])
19
+ ```
20
+
21
+ `App`'s constructor requires `name` — there's no default, and there's no `agent=` alias for `root_agent=`, easy typos to make since other ADK APIs use `agent`. Then reference `adk_tracegauge_cost_usd` as a `metric_name` in your eval config, and make sure `AgentEvaluator` picks up this `app` (it looks for an `app` attribute in your agent module automatically).
22
+
23
+ ## Install
24
+
25
+ ```bash
26
+ pip install "adk-tracegauge"
27
+ ```
28
+
29
+ `google-adk[eval]` and `tracegauge` are pulled in as dependencies. The `[eval]` extra on `google-adk` is not optional here even though this package doesn't use any of what it gates (pandas, jinja2, rouge-score, gepa, Vertex AI eval) — `google-adk`'s own `metric_evaluator_registry.py` unconditionally imports every one of its built-in evaluators at module import time, including the Vertex AI facade, which needs those packages just to import cleanly. Without the extra, `import adk_tracegauge` fails with `ModuleNotFoundError: No module named 'pandas'` — an ADK packaging quirk, not something this package controls.
30
+
31
+ ## What it reports, and what it deliberately doesn't
32
+
33
+ - **`score`**: raw cost in USD for the invocation, summed across every real model call within it (tool loops and sub-agent delegation can mean more than one model call per invocation). Not normalized, not calibrated, not a 0–1 quality score.
34
+ - **`rationale`** (the only other channel ADK's native reporting preserves — see "Why this metric always reports NOT_EVALUATED" below): a per-call breakdown — model, fresh/cached/output token counts, and their individual dollar costs.
35
+ - **No calibrated efficiency bands.** tracegauge's own token-economy axis compares your numbers against a baseline built from 75 Claude Code sessions. That baseline is not used here, on purpose — applying a Claude-Code-derived baseline to ADK agent behavior would be an unvalidated transfer, and a plausible-looking-but-wrong number is worse than no number. This package reports raw counts and dollars only; set your own thresholds for what "too expensive" means for your agent.
36
+ - **No trajectory-quality judging.** tracegauge's Ollama/Anthropic-based trajectory axis is out of scope for v1 — it's CC-specific tooling, unrelated to the cost story, and would add a dependency this package doesn't need.
37
+
38
+ ## Why this metric always reports `NOT_EVALUATED`
39
+
40
+ ADK's built-in pass/fail convention is `PASSED if score >= threshold else FAILED` — hardcoded, higher-is-better. Cost is lower-is-better. There is no lower-is-better or inverted-metric convention anywhere in `google.adk.evaluation` to plug into (checked directly against the source, not assumed). Silently negating the score to make the built-in gate technically "work" would misrepresent the number to anyone reading it — a `score: -0.0043` needs an explanation to even parse. So this metric doesn't participate in ADK's pass/fail gating: it always reports `eval_status=NOT_EVALUATED`, whatever threshold you configure. Read `score` directly, or write your own comparison against it.
41
+
42
+ ## Gemini pricing
43
+
44
+ `tracegauge`'s bundled price table covers Claude models only (its own domain — Claude Code sessions). ADK is Gemini-native, so this package ships and owns its own Gemini price table (`src/adk_tracegauge/data/gemini_prices.json`), passed explicitly into tracegauge's cost engine.
45
+
46
+ - Every entry carries its own `source_url` and `fetched_on` date — currently `https://ai.google.dev/gemini-api/docs/pricing`, fetched 2026-08-13. **Prices change without notice.** Verify against the source before relying on a number for a real budget decision.
47
+ - Standard tier only (no batch/flex/priority). Covers `gemini-2.5-pro`, `gemini-2.5-flash`, `gemini-2.5-flash-lite`, `gemini-2.0-flash` (deprecated, kept for historical sessions), `gemini-3.5-flash`, `gemini-3.5-flash-lite`, `gemini-3.6-flash`.
48
+ - **Known gap:** `gemini-2.5-pro` is priced at its ≤200k-token-context rate only. Gemini bills >200k-context Pro calls at roughly double that rate; this table has no per-call tiered-pricing logic, so long-context Pro invocations will be under-priced. Not silently wrong — documented here and in the price table's own per-entry `note` field.
49
+ - Cache-read discount is `0.1x` the model's fresh input rate for every model (verified against the published rate for each model individually, not assumed from tracegauge's Claude convention — it happens to match). Cache-*write* multipliers are `0.0`: Gemini's default automatic caching has no write-time surcharge and no `cache_creation` token field in its usage metadata at all, unlike Anthropic's explicit cache-write billing.
50
+
51
+ **An invocation whose model isn't in this table is never priced with a fallback rate.** `score` reports `None`, and the rationale names exactly which model string didn't resolve and lists every model this package knows how to price. A cost number for the wrong model is worse than no number, so this package doesn't produce one.
52
+
53
+ ### Staleness — what happens when Gemini's prices change and the table doesn't
54
+
55
+ A per-entry `source_url`/`fetched_on` date is provenance, not a freshness guarantee — nothing stops the table from silently aging out unless something actually checks it. Two independent things do:
56
+
57
+ - **At use time**: every `ResolvedModel.is_stale` check compares `fetched_on` against today; past 180 days (`STALE_THRESHOLD_DAYS` in `_pricing.py`), a priced result's `rationale` gets a `PRICE TABLE STALE` line naming the model and threshold, and a real `warnings.warn(...)` fires alongside it — visible to anyone watching logs, not only whoever reads that one invocation's output. Staleness never blocks the number; it warns and still reports it, on the position that a flagged-possibly-wrong number beats no number for something you already computed.
58
+ - **In CI**: `test_bundled_table_is_not_currently_stale` (`tests/test_pricing.py`) re-checks every bundled entry against the same 180-day threshold on every run. Once the table crosses it, this test starts failing on its own — not only when someone happens to notice a suspicious dollar figure.
59
+
60
+ **Updating the price table**: edit `src/adk_tracegauge/data/gemini_prices.json` — update `input_usd_per_mtok`/`output_usd_per_mtok` against the current values at the `source_url` already on each entry, and bump `fetched_on` to today. Run `pytest tests/test_pricing.py` to confirm the staleness test goes green and nothing else broke, then open a PR. There's no automated price-scraping here by design — a human should look at the actual pricing page before a dollar figure changes.
61
+
62
+ ## Compatibility risk
63
+
64
+ Registration uses `google.adk.evaluation.metric_evaluator_registry`, which google-adk marks `@experimental`: "may change or be removed... at any time," with no SemVer guarantee. This package pins `google-adk[eval]>=2.6.0,<2.7.0` accordingly — narrow, re-validated deliberately on each bump, not left open-ended.
65
+
66
+ If the registry API breaks in a future google-adk release, registration happens at import time as a side effect, so the failure mode is a loud, immediate `AttributeError`/`TypeError` on `import adk_tracegauge` — not a silent no-op or a subtly wrong result. That's a favorable failure mode worth naming explicitly: you'll know immediately, not after a bad number reaches a dashboard.
67
+
68
+ A scheduled CI job (`.github/workflows/pypi-canary.yml`) installs the *latest* `google-adk[eval]` release (ignoring the pin) and runs the full test suite weekly, so a break surfaces on a schedule rather than via a user bug report.
69
+
70
+ The plugin half of this package (`BasePlugin.after_model_callback`) sits on firmer ground — it isn't marked `@experimental` anywhere in `google-adk`. If the registry API breaks, the usage-capture half likely still works; only evaluator registration needs a patch.
71
+
72
+ ## Relationship to tracegauge
73
+
74
+ This package depends on `tracegauge`'s `tes.cost` module (`compute_session_cost` and its digest types) as a library. `tracegauge` overall is AGPL-3.0-only, but `tes/cost.py` and `tes/_digest.py` specifically are additionally available under Apache-2.0 — see [tracegauge's license note](https://github.com/gaurav-gandhi-2411/token-efficiency-scorer#license) — which is what lets this package stay Apache-2.0 itself. Every other part of tracegauge (the token-economy/trajectory/waste axes, the CLI, the dashboard) remains AGPL-3.0-only and is not used here.
75
+
76
+ ## What this is not
77
+
78
+ Not a general ADK observability/tracing tool — see `traceAI-google-adk` for that. Not a statistics/confidence-interval layer for ADK evaluation results — that's a separate, harder problem ([agentgauge](https://github.com/gaurav-gandhi-2411/agentgauge)'s domain) blocked by the same `EvalMetricResult` field-stripping this package works around by using `score`+`rationale` only. Not a replacement for any of ADK's quality metrics — this reports cost alongside them, not instead of them.
79
+
80
+ ## License
81
+
82
+ [Apache-2.0](LICENSE).
@@ -0,0 +1,87 @@
1
+ [build-system]
2
+ requires = ["setuptools>=70", "wheel"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "adk-tracegauge"
7
+ version = "0.1.0"
8
+ description = "Per-invocation cost-in-USD evaluator for Google's Agent Development Kit (ADK), built on tracegauge's cost engine. Raw dollars and tokens, no calibrated bands, no fabricated numbers for unknown models."
9
+ authors = [{ name = "Gaurav Gandhi", email = "gaurav.gandhi2411@gmail.com" }]
10
+ requires-python = ">=3.10"
11
+ readme = "README.md"
12
+ license = "Apache-2.0"
13
+ license-files = ["LICENSE"]
14
+ classifiers = [
15
+ "Development Status :: 3 - Alpha",
16
+ "Programming Language :: Python :: 3",
17
+ "Programming Language :: Python :: 3.10",
18
+ "Programming Language :: Python :: 3.11",
19
+ "Programming Language :: Python :: 3.12",
20
+ "Programming Language :: Python :: 3.13",
21
+ "Topic :: Software Development :: Quality Assurance",
22
+ "Topic :: Utilities",
23
+ "Intended Audience :: Developers",
24
+ "Environment :: Console",
25
+ "Operating System :: OS Independent",
26
+ ]
27
+ keywords = ["adk", "agent-development-kit", "google-adk", "evaluation", "cost", "token-efficiency"]
28
+ dependencies = [
29
+ # [eval] is required, not optional: google-adk's own
30
+ # metric_evaluator_registry.py unconditionally imports every built-in
31
+ # evaluator at module import time, including the Vertex AI eval facade,
32
+ # which transitively needs pandas/jinja2/rouge-score/tabulate/gepa --
33
+ # gated behind this extra. Without it, `import adk_tracegauge` fails
34
+ # with ModuleNotFoundError: No module named 'pandas', even though this
35
+ # package uses none of those libraries itself. Confirmed by reading
36
+ # google-adk's own pyproject.toml requires list.
37
+ "google-adk[eval]>=2.6.0,<2.7.0",
38
+ "tracegauge>=0.10.0,<0.11.0",
39
+ ]
40
+
41
+ [dependency-groups]
42
+ dev = [
43
+ "ruff>=0.15,<1",
44
+ "mypy>=1.14,<2",
45
+ "pytest>=8.3,<9",
46
+ "pytest-asyncio>=0.25,<1",
47
+ "pytest-cov>=6.0,<7",
48
+ "pytest-mock>=3.14,<4",
49
+ ]
50
+
51
+ [project.urls]
52
+ Repository = "https://github.com/gaurav-gandhi-2411/adk-tracegauge"
53
+
54
+ [tool.setuptools.packages.find]
55
+ where = ["src"]
56
+ include = ["adk_tracegauge*"]
57
+
58
+ [tool.setuptools.package-data]
59
+ "adk_tracegauge" = ["data/gemini_prices.json"]
60
+
61
+ [tool.ruff]
62
+ line-length = 100
63
+ target-version = "py311"
64
+ src = ["src"]
65
+
66
+ [tool.ruff.lint]
67
+ select = ["E", "F", "I", "UP", "B", "SIM"]
68
+ ignore = ["E501"]
69
+
70
+ [tool.mypy]
71
+ python_version = "3.12"
72
+ strict = true
73
+ ignore_missing_imports = true
74
+ warn_unused_ignores = true
75
+
76
+ [tool.pytest.ini_options]
77
+ testpaths = ["tests"]
78
+ asyncio_mode = "auto"
79
+ addopts = "-v"
80
+ pythonpath = [".", "src"]
81
+
82
+ [tool.coverage.run]
83
+ omit = ["tests/*"]
84
+
85
+ [tool.coverage.report]
86
+ fail_under = 0
87
+ exclude_lines = ["pragma: no cover", "if TYPE_CHECKING:"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,40 @@
1
+ """adk-tracegauge — per-invocation cost-in-USD evaluator for the Agent Development Kit.
2
+
3
+ Importing this package registers the "adk_tracegauge_cost_usd" metric into
4
+ google-adk's DEFAULT_METRIC_EVALUATOR_REGISTRY as a side effect, matching
5
+ the registration pattern google-adk itself documents for third-party
6
+ metrics. If google-adk's @experimental registry API has changed
7
+ incompatibly, this import-time call fails loudly (AttributeError/TypeError)
8
+ rather than silently doing nothing -- see README, "Compatibility risk".
9
+
10
+ Required setup (not optional -- see README for why):
11
+
12
+ from adk_tracegauge import TraceGaugeUsagePlugin
13
+ app = App(agent=root_agent, plugins=[TraceGaugeUsagePlugin()])
14
+
15
+ Then reference "adk_tracegauge_cost_usd" as a metric_name in your eval_config.json.
16
+ """
17
+
18
+ from __future__ import annotations
19
+
20
+ from google.adk.evaluation.metric_evaluator_registry import DEFAULT_METRIC_EVALUATOR_REGISTRY
21
+
22
+ from ._plugin import TraceGaugeUsagePlugin
23
+ from ._store import DEFAULT_USAGE_STORE, UsageStore
24
+ from .evaluator import _METRIC_INFO, METRIC_NAME, CostEfficiencyEvaluator
25
+
26
+ DEFAULT_METRIC_EVALUATOR_REGISTRY.register_evaluator(
27
+ metric_info=_METRIC_INFO,
28
+ evaluator=CostEfficiencyEvaluator,
29
+ )
30
+
31
+ __version__ = "0.1.0"
32
+
33
+ __all__ = [
34
+ "CostEfficiencyEvaluator",
35
+ "TraceGaugeUsagePlugin",
36
+ "UsageStore",
37
+ "DEFAULT_USAGE_STORE",
38
+ "METRIC_NAME",
39
+ "__version__",
40
+ ]
@@ -0,0 +1,92 @@
1
+ """adk_tracegauge/_adapter.py — Maps captured ADK usage data onto tracegauge's digest shape.
2
+
3
+ tracegauge's tes.cost.compute_session_cost operates on a tes._digest.SessionDigest
4
+ (a list of TurnDigest, one per AI turn). One ADK invocation can involve more
5
+ than one real model call, so it maps onto a SessionDigest with one TurnDigest
6
+ per captured call -- summed cost across the whole invocation, same as
7
+ tracegauge sums cost across a whole Claude Code session.
8
+
9
+ Model resolution happens here, once, before any TurnDigest is built. A call
10
+ whose model_version doesn't match the Gemini price table makes the whole
11
+ adaptation fail closed (see AdaptResult.unresolved_model) rather than
12
+ producing a partially-priced or silently-approximate result.
13
+ """
14
+
15
+ from __future__ import annotations
16
+
17
+ from dataclasses import dataclass
18
+
19
+ from tes._digest import SessionDigest, TurnDigest
20
+
21
+ from ._pricing import known_model_keys, resolve_model
22
+ from ._store import CapturedCall
23
+
24
+
25
+ @dataclass
26
+ class AdaptResult:
27
+ """Either a ready-to-price digest, or the model that blocked pricing."""
28
+
29
+ digest: SessionDigest | None
30
+ unresolved_model: str | None
31
+
32
+ @property
33
+ def ok(self) -> bool:
34
+ return self.digest is not None
35
+
36
+
37
+ def build_session_digest(invocation_id: str, calls: list[CapturedCall]) -> AdaptResult:
38
+ """Builds a SessionDigest from captured calls, or reports the blocking model.
39
+
40
+ Every call's model_version must resolve against the Gemini price table.
41
+ On the first unresolved model, adaptation stops and returns it -- no
42
+ partial digest, no fallback pricing.
43
+ """
44
+ turns: list[TurnDigest] = []
45
+
46
+ for index, call in enumerate(calls):
47
+ resolved = resolve_model(call.model_version)
48
+ if resolved is None:
49
+ return AdaptResult(digest=None, unresolved_model=call.model_version)
50
+
51
+ turns.append(
52
+ TurnDigest(
53
+ turn_index=index,
54
+ role="ai",
55
+ tool_names=[],
56
+ content_snippet="",
57
+ token_count_input=call.prompt_token_count,
58
+ token_count_output=call.candidates_token_count,
59
+ cache_read=call.cached_content_token_count,
60
+ h2_duplicate=False,
61
+ cache_creation=0,
62
+ model=resolved.model_key,
63
+ )
64
+ )
65
+
66
+ digest = SessionDigest(
67
+ session_id=invocation_id,
68
+ domain="adk_invocation",
69
+ resolved=True,
70
+ total_tokens=sum(c.prompt_token_count + c.candidates_token_count for c in calls),
71
+ turn_count=len(turns),
72
+ h2_duplicate_count=0,
73
+ cache_hit_rate=0.0,
74
+ p25_token_ratio=0.0,
75
+ output_tokens_available=True,
76
+ task_description="",
77
+ turns=turns,
78
+ )
79
+ return AdaptResult(digest=digest, unresolved_model=None)
80
+
81
+
82
+ def unknown_model_message(model_version: str) -> str:
83
+ known = ", ".join(known_model_keys())
84
+ return (
85
+ f"cost not computed: model '{model_version}' is not in the "
86
+ f"adk-tracegauge Gemini price table (known: {known}). "
87
+ "Check https://ai.google.dev/gemini-api/docs/pricing for a new or "
88
+ "renamed model, or open an issue if this model should be added."
89
+ )
90
+
91
+
92
+ __all__ = ["AdaptResult", "build_session_digest", "unknown_model_message"]