nemo_gym.models.token_capture.lineage_scope
nemo_gym.models.token_capture.lineage_scope
Scope an episode’s captured calls by agent instance and model server, and attribute failures to them.
A lineage scope is the calls of one agent instance on one model server. Parent search, retry grouping and terminal selection never cross a lineage scope, so a judge whose prompt embeds the assistant’s transcript never continues the assistant’s chain, and two agent instances with identical first prompts are never retries of each other. The calls of a single-agent episode form one lineage scope.
Outcomes are per agent instance: a failure or a pending call belongs to the agent instance that made the call. A failure is episode-wide when nothing about its identity is known, or when the episode names its agent instances and the failure names none. Delivery and the manifest both use these helpers, so they agree on every attribution.
Module Contents
Classes
Functions
Data
API
Which agent instances an episode’s failures and pending calls belong to.
agent_instances holds every agent instance with its own failure or pending call; the unnamed agent
is None. episode_wide is set by a failure with no known identity, or with no agent instance in an
episode that names them: it masks every agent instance.
Attribute one failed or pending call.
In an episode that names its agent instances, a call without a name cannot be placed and is episode-wide. In a single-agent episode it belongs to the unnamed agent.
Partition items by key(item)[0], the agent instance of their lineage scope, in first-appearance order.
Partition entries by lineage scope, in first-appearance order.
Return each ledger row’s identity columns, inheriting them from its call’s intent row when it has none.
A row whose call has no named agent instance, on the row or on its intent, keeps whatever identity it
has. is_episode_wide decides from those columns whether the row applies to the whole episode: it does
when they are empty, or when the episode names its agent instances and they name none.
Whether a failed or lost call applies to the whole episode rather than to one agent instance.
It does when nothing about its identity is known, or when the episode names its agent instances but this call’s agent instance is unknown. A mark that names no model call, which the model server writes for a request it could not classify, belongs to the agent instance that made the request when that is known.
The lineage scope of a call made with identity.
The agent instance whose result is the episode’s top-level result.
assistant when the episode has one; otherwise the unnamed agent; otherwise the only agent instance.
assistant comes first, so an unnamed caller beside it, such as a helper or a judge that does not
name itself, never takes the scored response. Raise LookupError when none of these exists.
The lineage scope of a ledger row, or of a wire record such as CallRecord or ManifestFailure.
Whether other is the same agent instance served by a different model server.