Skip to content

Phase 2b: surface OpenRouter token usage in knowledge enrich CostUsage#22

Merged
Svaag merged 1 commit into
mainfrom
chore/enrich-token-usage
Jun 29, 2026
Merged

Phase 2b: surface OpenRouter token usage in knowledge enrich CostUsage#22
Svaag merged 1 commit into
mainfrom
chore/enrich-token-usage

Conversation

@Svaag

@Svaag Svaag commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

Completes the knowledge CostUsage fidelity: enrichment now emits real token counts (and
USD when OpenRouter returns it), not just provider/model.

  • llm.py: call_openrouter returns (content, usage) and sends "usage": {"include": true}
    so OpenRouter includes cost.
  • enrich.py: enrich_target captures usage and emits CostUsage (input/output/total
    tokens + usd) on the live path. Emission moved here from cmd_enrich, so the
    knowledge-loop batch path is covered too; dry-run does not emit.
  • agent_core_trace.emit_enrich_cost: accepts usage, maps prompt/completion/total → tokens
    and cost → usd.
  • cli.py: drops the now-redundant cmd_enrich emit call.

Safety

  • Still off by default (HYRULE_KNOWLEDGE_AGENT_CORE_TRACE); enrich_target's return is
    unchanged (still Path), so loop callers are unaffected. call_openrouter has a single
    caller (enrich.py) and no test calls it directly.
  • Local gate green: ruff clean, mypy --strict src clean (36 files), pytest 97 passed
    (enrich-cost test asserts token/USD mapping).

🤖 Generated with Claude Code

…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>
@Svaag Svaag merged commit 95b5b90 into main Jun 29, 2026
1 check passed
@Svaag Svaag deleted the chore/enrich-token-usage branch June 29, 2026 02:32
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