nemo_gym.core.correlation
nemo_gym.core.correlation
Read and build the correlation prefix of a Gym request path.
A Gym component that hands a model URL to a client puts the request’s identity in the path:
The segments appear in that fixed order. A path may also carry only /ng-sampling/<values>, only
/ng-trace/<traceparent>, or both.
resolve reads the prefix and encode builds it. Readers that still parse the path by hand are moving
onto this module.
An agent instance name is <agent kind>[.<n>], for example assistant, judge or debater.1.
The name never equals a segment literal or v1, so a missing name cannot swallow the next segment.
The /ng-sampling/ value is a training framework’s sampling values for the call, or null for a caller it
does not train; nemo_gym.core.model_call_sampling encodes and checks it. Like an agent instance name, it never
equals a segment literal or v1.
On a Gym server, TraceContextPathMiddleware, the outermost layer that reads the path, resolves it and
shares the result through scope["state"]; inner middleware reads it there instead of parsing again.
resolve reads only the path.
Module Contents
Classes
Functions
Data
API
The identity a request path carries.
capture_key is None for a path without a rollout prefix. agent_instance is None when the path
names no agent instance, as in a single-agent episode. model_sampling is the /ng-sampling/ value, or
None when the path carries none.
Bases: ValueError
A request path carries a malformed correlation prefix. Servers answer it with 404.
Return the agent kind of an agent instance name: the part before the dot.
Build the path prefix for context; "" when it carries nothing.
Split path into the context its prefix carries and the remaining path.
Return None when path starts with no correlation segment, or, unless allow_empty_rest,
when nothing follows the prefix. Raise CorrelationPathError for a malformed prefix:
segments out of order or repeated, a missing value, an invalid agent instance name or traceparent.
Store result as the resolution of the scope’s current path.
A middleware that rewrites the path after resolving it calls this, so inner middleware reading the rewritten path finds the context without parsing it again.
Return the context a request’s path carries and the remaining path, or None without a prefix.
Resolve once per request: the result is stored in scope["state"] for the path it was read from,
and a later call for the same path returns it. The cache is keyed by path, so resolve must read only
the path. Raise CorrelationPathError for a malformed prefix.
Return name if it is a valid agent instance name; raise ValueError otherwise.