Skip to navigation

nemo_gym.rollouts.trajectory_builder

View as Markdown

Building a rollout’s trajectory record from its model calls and the observations its agent reported.

Module Contents

Functions

NameDescription
_attach_trajectory_record-
_build_trajectory_record-
_has_observation_gap-
_nonnegative_int-
_trajectory_identity-
_turn_contentSplit one captured model call into the turn’s question, answer, reasoning, and tool-call count.
_turns_from_model_callsBuild policy turns from captured calls for an agent that sent no trajectory.

Data

logger

API

nemo_gym.rollouts.trajectory_builder._attach_trajectory_record(
row: dict[str, typing.Any],
result: dict[str, typing.Any]
) -> None
nemo_gym.rollouts.trajectory_builder._build_trajectory_record(
row: dict[str, typing.Any],
result: dict[str, typing.Any]
nemo_gym.rollouts.trajectory_builder._has_observation_gap(
result: dict[str, typing.Any],
code: str
) -> bool
nemo_gym.rollouts.trajectory_builder._nonnegative_int(
value: typing.Any
) -> typing.Optional[int]
nemo_gym.rollouts.trajectory_builder._trajectory_identity(
row: dict[str, typing.Any]
) -> tuple[str, str]
nemo_gym.rollouts.trajectory_builder._turn_content(
request: typing.Any,
response: typing.Any
) -> tuple[typing.Any, typing.Any, typing.Any, int]

Split one captured model call into the turn’s question, answer, reasoning, and tool-call count.

Handles the three dialects the Model Server captures: Responses API output items, chat-completions messages, and Anthropic Messages content blocks.

nemo_gym.rollouts.trajectory_builder._turns_from_model_calls(
task_id: str,
rollout_id: str,
resolved: typing.Any,
verifier_invocations: collections.abc.Iterable[nemo_gym.trajectory.trajectory_record.VerifierInvocation] = (),
compactions: collections.abc.Sequence[nemo_gym.trajectory.trajectory_record.ContextCompactionObservation] = ()

Build policy turns from captured calls for an agent that sent no trajectory.

A call belongs to the invocation whose model_calls reference it. Unreferenced calls stay in the raw evidence but do not become turns: even a single-agent rollout may capture judge or auxiliary calls that do not belong to the agent. Compaction helpers remain invocation-owned calls for token accounting, but never become policy turns, even when agent ownership claims conflict. Preserve those claims for validation rather than choosing which owner is correct. Explicit verifier ownership also excludes a call from turns when an agent incorrectly references it; retain both ownership claims for validation.

nemo_gym.rollouts.trajectory_builder.logger = logging.getLogger(__name__)