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.
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.
Fail closed when a Megatron capture request carries media or audio parts.
The Megatron adapter stages no media geometry, so a multimodal prompt would commit token rows whose lengths disagree with the expanded engine prompt. Until multimodal staging lands, refuse the request rather than train on it.
Keep token IDs, logprobs, routes, and coordinates off the agent hop.
Create the external capture strategy selected by typed configuration.