Skip to navigation

nemo_gym.server_runtime.episode_tokens

View as MarkdownOpen in Claude

Tokens that let an agent call one episode’s tools on an Environment Server.

Module Contents

Classes

NameDescription
EpisodeTokenClaimsThe episode a token names, and the nonce that makes the token unguessable.
EpisodeTokensMint and read the tokens an Environment Server grants for one episode’s tools.

Functions

NameDescription
episode_token_secretThe random secret that signs this server run’s episode tokens.

Data

EPISODE_TOKEN_HEADER

EPISODE_TOKEN_SECRET_ENV

_EPISODE_TOKEN_SALT

API

class nemo_gym.server_runtime.episode_tokens.EpisodeTokenClaims(
nonce: str
)
Dataclass

The episode a token names, and the nonce that makes the token unguessable.

episode_id
EpisodeId
nonce
str

Whether other names the same episode with the same nonce, compared in constant time.

class nemo_gym.server_runtime.episode_tokens.EpisodeTokens(
secret: str
)

Mint and read the tokens an Environment Server grants for one episode’s tools.

A rollout ID is predictable (<task index>-<rollout index> unless the caller sets one), so each token carries a random nonce. The server accepts a token only while it holds the same claims for that episode (EpisodeTokenClaims.matches): the nonce is what authenticates a call. The signature, with a random secret for each server run (episode_token_secret), keeps the claims intact, and lets a worker that does not hold the episode read which episode a token names.

_serializer
nemo_gym.server_runtime.episode_tokens.EpisodeTokens.mint(

A new token for episode_id, and the claims the server keeps to check it.

nemo_gym.server_runtime.episode_tokens.EpisodeTokens.read(
token: str

The claims of a token this server signed, or None for any other string. It never raises.

nemo_gym.server_runtime.episode_tokens.episode_token_secret() -> str

The random secret that signs this server run’s episode tokens.

The first call in a process without the secret makes one and sets it in EPISODE_TOKEN_SECRET_ENV. A multi-worker server builds its server object in the main process before uvicorn starts the workers, so every worker inherits the same secret and reads tokens that another worker minted.

nemo_gym.server_runtime.episode_tokens.EPISODE_TOKEN_HEADER = 'X-NeMo-Gym-Episode-Token'
nemo_gym.server_runtime.episode_tokens.EPISODE_TOKEN_SECRET_ENV = 'NEMO_GYM_EPISODE_TOKEN_SECRET'
nemo_gym.server_runtime.episode_tokens._EPISODE_TOKEN_SALT = 'nemo-gym-episode-token'