nemo_gym.trajectory.model_call_record
nemo_gym.trajectory.model_call_record
One model call as a rollout records it: token counts, cache use, tool calls, and totals across calls.
Module Contents
Classes
Functions
API
Bases: BaseModel
Observability record derived from one captured model-server exchange.
Bases: NamedTuple
Whether captured response evidence can establish a tool request.
Cache hit/miss + cached-token count, from usage cache fields (OpenAI / Anthropic).
Return the whole prompt size, with cached tokens counted exactly once.
Usage formats disagree on whether the prompt count includes the cache:
prompt_tokens(Chat Completions) includes it. It wins whenever present, also when a gateway adds Anthropic-stylecache_*fields beside it.input_tokenswith top-levelcache_read_input_tokensorcache_creation_input_tokens(Anthropic Messages) excludes it, so the cache counts are added.input_tokensalone (Responses) includes it.
The OpenAI *_tokens_details cache read and write counts are subsets of the prompt count and are never added.
Structured tool calls (name, arguments, call_id) and reasoning text, across all three shapes.
Return the first valid token count across equivalent provider detail shapes.
Aggregate token and latency values from model-call records.
Map one captured exchange and its transport metadata into an observability record.
Normalize token totals across Responses, Chat Completions, and Anthropic Messages usage.
tokens_in is the whole prompt size (see _prompt_size); cache creation is also reported
separately as cache_creation_tokens. A count the provider did not report stays None, never 0.
tokens_in is a prompt-size metric, not a cost proxy: providers price cache-read (~0.1x) and
cache-creation (~1.25x) differently from base input, so cost-accurate consumers should weight
cached_tokens and cache_creation_tokens separately rather than summing tokens_in.
Classify request evidence consistently for normalization and canonical decoding.
Omitted payloads may retain an independently resolved association with a verification gap. Malformed payloads and explicit failed responses cannot establish a requesting call.