Phase 2b: surface OpenRouter token usage in knowledge enrich CostUsage#22
Merged
Conversation
…hase 2b) call_openrouter now returns (content, usage) and requests usage.include so OpenRouter returns cost; enrich_target captures usage and emits agent-core CostUsage (input/output/total tokens + usd) via the flag-gated emitter. Emission moved from cmd_enrich into enrich_target so both the CLI and the knowledge-loop batch path emit, and only on the live (non-dry-run) path. Still off by default (HYRULE_KNOWLEDGE_AGENT_CORE_TRACE). ruff + mypy --strict clean; suite 97 passed. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Completes the knowledge
CostUsagefidelity: enrichment now emits real token counts (andUSD when OpenRouter returns it), not just provider/model.
llm.py:call_openrouterreturns(content, usage)and sends"usage": {"include": true}so OpenRouter includes
cost.enrich.py:enrich_targetcapturesusageand emitsCostUsage(input/output/totaltokens + usd) on the live path. Emission moved here from
cmd_enrich, so theknowledge-loop batch path is covered too; dry-run does not emit.
agent_core_trace.emit_enrich_cost: acceptsusage, maps prompt/completion/total → tokensand
cost→ usd.cli.py: drops the now-redundantcmd_enrichemit call.Safety
HYRULE_KNOWLEDGE_AGENT_CORE_TRACE);enrich_target's return isunchanged (still
Path), so loop callers are unaffected.call_openrouterhas a singlecaller (enrich.py) and no test calls it directly.
ruffclean,mypy --strict srcclean (36 files),pytest97 passed(enrich-cost test asserts token/USD mapping).
🤖 Generated with Claude Code