feat(llm): normalized context_tokens and public resolve_model - #136
Merged
Merged
Conversation
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).
Merged
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.
cache_write_tokens(it double-counted input in usage records). Cached input iscache_read_tokens;prompt_tokensstays the uncached share.context_tokens = prompt_tokens + cache_read + cache_write, the full input size of a call, computed once inllm.luawith the same field precedence astrack_usage(shared helper).llm.resolve_model(model)is public (resolver contract, name, class,class:syntax).Tests: mapper tests assert the correct cache semantics;
llm_testcoverscontext_tokens(contract and provider field names) andresolve_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 exceptgpt-5-minireturning 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).