Skip to content

Add token_json_paths: sum engine token stats from JSON worker output - #78

Open
chriscfellows wants to merge 1 commit into
NateBJones-Projects:mainfrom
chriscfellows:feat/token-json-paths
Open

chriscfellows wants to merge 1 commit into
NateBJones-Projects:mainfrom
chriscfellows:feat/token-json-paths

Conversation

@chriscfellows

Copy link
Copy Markdown

Purpose: allow for token counting and cost estimation for workers to help with LLM comparisons.

Engines whose CLIs report usage only inside a JSON document (gemini CLI --output-format json) record worker_tokens=null today: the stats carry SEVERAL models (utility router + main), each duplicating its totals under nested roles, so a single-capture token_regex either grabs one arbitrary number or double-counts — and a wrong number on the scoreboard is worse than none.

New optional [engines.] field token_json_paths (e.g. ["stats.models.*.tokens.total"]): parse_token_stats_json extracts the LAST parseable JSON object from noisy worker output (pretty-printed or compact), resolves dot-paths with * dict wildcards, and sums integer leaves (bools excluded); resolve_worker_tokens falls back to the existing token_regex whenever JSON yields nothing. Engines without the field keep byte-identical behavior.

Stdlib only. 11 new tests in tests/test_token_json_paths.py (fixture is a real gemini CLI capture); full suite shows no new failures vs local baseline. Sample config documents the field on a gemini example.

Engines whose CLIs report usage only inside a JSON document (gemini CLI
--output-format json) record worker_tokens=null today: the stats carry
SEVERAL models (utility router + main), each duplicating its totals under
nested roles, so a single-capture token_regex either grabs one arbitrary
number or double-counts — and a wrong number on the scoreboard is worse
than none.

New optional [engines.<name>] field token_json_paths (e.g.
["stats.models.*.tokens.total"]): parse_token_stats_json extracts the
LAST parseable JSON object from noisy worker output (pretty-printed or
compact), resolves dot-paths with * dict wildcards, and sums integer
leaves (bools excluded); resolve_worker_tokens falls back to the existing
token_regex whenever JSON yields nothing. Engines without the field keep
byte-identical behavior.

Stdlib only. 11 new tests in tests/test_token_json_paths.py (fixture is
a real gemini CLI capture); full suite shows no new failures vs local
baseline. Sample config documents the field on a gemini example.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant