nemo_gym.token_id_capture.external_capture
nemo_gym.token_id_capture.external_capture
Backend strategies for framework-owned token capture.
Module Contents
Classes
Functions
Data
API
Prepare and finalize one backend-specific external capture call.
Commit lineage from the final API representation served to the client.
Attach capture instructions to an admitted engine request.
Retain the worker acknowledgement and remove capture-only response fields.
Model servers must call this for every completion the worker returns,
even one whose acknowledgement is missing. It marks the request as
having received a worker completion, and finalize_response commits
or poisons the call only when that mark is present. Skipping it for a
real completion would leave the call merely uncommitted instead of
failing closed with worker_response_missing_commit_coordinates.
Completions the model server synthesizes itself (the sequential
reasoning guard, or a backend context-limit error converted into an
empty completion) never pass through here, so they stay uncommitted.
Bases: _BaseExternalCaptureHandler
Commit lineage after a Megatron Inference worker durably stages a canonical delta.
Bases: _BaseExternalCaptureHandler
Commit lineage after a vLLM worker durably stages the token delta.
Own the lifecycle shared by external capture backends.
Validate the worker acknowledgement and commit lineage for an admitted response.
This path operates only on shared Gym contracts (CommitCoords,
CallRecord, CaptureLedgerCommit); backends differ only in how
_prepare_admitted_request asks the engine to stage tokens.
The ordering invariant the external sink requires — a call must not
become a lineage parent until its staged record is durable — holds
structurally: the worker stages before acknowledging, so the ledger
row (which is what makes the call resolvable) is written only after
the coordinates arrive. Custody fields were already stripped from the
engine response by prepare_response.
Attach backend-specific fields after shared admission checks.
Validate the retained acknowledgement and record the served response.
served_payload is the JSON form of the response returned to the
client, after conversion succeeded. Fingerprints are computed from that
representation so the next turn’s echoed history resolves its parent.
Attach capture instructions to an engine-bound request.
An unadmitted call (UNRESOLVED — already poisoned in the ledger)
is forwarded as plain traffic: the backend captures nothing and the
completion still serves the agent.
Strip transport fields and retain the acknowledgement until API conversion finishes.
Lineage is published from the final Chat, Responses, or Messages
representation (see finalize_response), so the worker coordinates
are parked on the request-scoped capture context and the internal
engine response is scrubbed of token data immediately.
Keep token IDs, logprobs, routes, and coordinates off the agent hop.
Create the external capture strategy selected by typed configuration.