nemo_gym.observability.model_calls
nemo_gym.observability.model_calls
Read saved model exchanges, resolve ownership, and attach evidence to rollouts.
Module Contents
Classes
Functions
Data
API
Bases: BaseModel
Observability record derived from one captured model-server exchange.
Cache hit/miss + cached-token count, from usage cache fields (OpenAI / Anthropic).
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 model-call metrics for one rollout id.
Aggregate token and latency values from model-call records.
Wait until no claimed capture write for this rollout is outstanding.
A cancelled model call finishes its capture write detached (see the shield in
_CaptureMiddleware), so the row can land after the rollout record is snapshotted and be
missing from ng_model_call_capture while present on disk. Returns False on timeout, which
the merge turns into a model_call_capture_pending gap rather than a silent omission.
Map one captured exchange and its transport metadata into an observability record.
Remove stale per-rollout capture files for these records before dispatch.
Capture files are keyed by a deterministic rollout id (task-rollout-attempt), so without this a fresh run or a kill-shaped retry would append onto the previous attempt’s capture for the same id. The caller passes only rows about to be dispatched, after assigning any retry suffix.
Normalize token totals across Responses, Chat Completions, and Anthropic Messages usage.
For native Anthropic /v1/messages with prompt caching, input_tokens is only the uncached
remainder, so cache-read + cache-creation tokens are folded into tokens_in to reflect the true
prompt size (and cache-creation is surfaced separately as cache_creation_tokens). OpenAI /
Responses usage already includes cached tokens in input_tokens / prompt_tokens (where
cached_tokens is a subset), so it is left untouched — no double counting.
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.
Attach captured model-call observability data to a rollout record in place.
Keyed by the rollout id derived from the record’s task/rollout/attempt indices, so the attached
shape is identical for every agent harness. Adds
ng_model_call_capture = {rollout_id, metrics, calls} where calls are derived observability
records. Raw request and response payloads remain in the capture store and are omitted from the
attachment unless include_payloads is true. Capture/read/join failures are attached as
gaps. The harness output and reward are not modified.
Return the single run-wide capture directory when capture is enabled.
Return the run-wide observability_enabled flag directly, without going through capture dirs.
Read valid call records and count damaged records.
Read captured exchanges in durable append order.