Skip to content

feat(llm): normalized context_tokens and public resolve_model - #136

Merged
wolfy-j merged 2 commits into
masterfrom
feat/llm-usage-normalization
Sep 25, 2026
Merged

wolfy-j merged 2 commits into
masterfrom
feat/llm-usage-normalization

Conversation

@wolfy-j

@wolfy-j wolfy-j commented Sep 23, 2026

Copy link
Copy Markdown
Contributor
  • OpenAI, OpenAI-compatible and Google mappers no longer report the uncached share of the prompt as cache_write_tokens (it double-counted input in usage records). Cached input is cache_read_tokens; prompt_tokens stays the uncached share.
  • Normalized responses carry context_tokens = prompt_tokens + cache_read + cache_write, the full input size of a call, computed once in llm.lua with the same field precedence as track_usage (shared helper).
  • llm.resolve_model(model) is public (resolver contract, name, class, class: syntax).

Tests: mapper tests assert the correct cache semantics; llm_test covers context_tokens (contract and provider field names) and resolve_model; live OpenAI test sends one cacheable prompt twice and asserts zero cache writes and equal total input. Unit suite 1417 passed; live suite (OpenAI, Google, typesafe) passed except gpt-5-mini returning zero reasoning tokens once (unrelated, passed on the previous live run).

Part of the agent memory layer work (usage normalization is the input for model-aware compaction).

OpenAI, OpenAI-compatible and Google mappers reported the uncached share of
the prompt as cache_write_tokens, so usage counted uncached input twice.
Cached input is now reported only as cache reads; these providers have no
cache writes.

Normalized responses carry context_tokens (uncached input plus cache reads
and writes), the full input size of the call. llm.resolve_model is public so
callers can read the model card (context window, output tokens).
@wolfy-j
wolfy-j merged commit 784e730 into master Sep 25, 2026
21 checks passed
@wolfy-j
wolfy-j deleted the feat/llm-usage-normalization branch September 25, 2026 02:54
@wippy-releases wippy-releases Bot mentioned this pull request Sep 25, 2026
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.

2 participants