> This page is for version 0.4.0.
> For other versions, use one of these documentation indexes:
> - Main (default): https://docs.nvidia.com/nemo/gym/main/llms.txt
> - 0.7.0: https://docs.nvidia.com/nemo/gym/v0.7.0/llms.txt
> - 0.6.0: https://docs.nvidia.com/nemo/gym/v0.6.0/llms.txt
> - 0.5.1: https://docs.nvidia.com/nemo/gym/v0.5.1/llms.txt
> - 0.5.0: https://docs.nvidia.com/nemo/gym/v0.5.0/llms.txt
> - 0.4.0: https://docs.nvidia.com/nemo/gym/v0.4.0/llms.txt
> - 0.3.0: https://docs.nvidia.com/nemo/gym/v0.3.0/llms.txt
> - 0.2.1: https://docs.nvidia.com/nemo/gym/v0.2.1/llms.txt

> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.nvidia.com/nemo/gym/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.nvidia.com/nemo/gym/_mcp/server.

# nemo_gym.server_runtime.request_handling.rollout_context

The middleware that strips a rollout prefix from a request path and sets the current episode for the request.

Tracking the current episode lives in `nemo_gym.core.episode_context`.

## Module Contents

### Classes

| Name                                                                                                             | Description                                                                    |
| ---------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------ |
| [`RolloutContextMiddleware`](#nemo_gym-server_runtime-request_handling-rollout_context-RolloutContextMiddleware) | Strip a rollout prefix and expose it to downstream Gym calls for this request. |

### Functions

| Name                                                                                                         | Description                                                                    |
| ------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------ |
| [`scope_with_routed_path`](#nemo_gym-server_runtime-request_handling-rollout_context-scope_with_routed_path) | Copy the scope for routing and share the rewritten path with outer middleware. |

### Data

[`ROUTED_PATH_STATE_KEY`](#nemo_gym-server_runtime-request_handling-rollout_context-ROUTED_PATH_STATE_KEY)

[`__getattr__`](#nemo_gym-server_runtime-request_handling-rollout_context-__getattr__)

### API

```python
class nemo_gym.server_runtime.request_handling.rollout_context.RolloutContextMiddleware(
    app: typing.Any
)
```

Strip a rollout prefix and expose it to downstream Gym calls for this request.

**`_PREFIX`**

---

```python
nemo_gym.server_runtime.request_handling.rollout_context.RolloutContextMiddleware.__call__(
    scope: dict[str, typing.Any],
    receive: typing.Any,
    send: typing.Any
) -> None
```

async

```python
nemo_gym.server_runtime.request_handling.rollout_context.scope_with_routed_path(
    scope: dict[str, typing.Any],
    path: str
) -> dict[str, typing.Any]
```

Copy the scope for routing and share the rewritten path with outer middleware.

```python
nemo_gym.server_runtime.request_handling.rollout_context.ROUTED_PATH_STATE_KEY = 'nemo_gym.routed_path'
```

```python
nemo_gym.server_runtime.request_handling.rollout_context.__getattr__ = moved_names_getattr(__name__)
```