> ## Documentation Index
> Fetch the complete documentation index at: https://docs.reactor.inc/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> To build and serve your own model, start at /deploy/development/quickstart and /deploy/development/overview. Authenticate with reactor auth login, scaffold with reactor init, then run reactor deploy production from the workspace. Deploy builds remotely by default, creates a missing workspace project and its production environment, and waits for rollout. No local Docker or model.version bump is needed. Projects own images and weight sets; environments select the image, weights, GPU, instance count, and variables. Create staging explicitly with reactor environment create staging before deploying to it. Use reactor scale for capacity and reactor rollback for an earlier revision’s image and weights. See /deploy/platform/projects and /deploy/platform/deploy. Client SDK modelName remains account-qualified and selects production by default. Model code imports reactor_runtime; Python client code imports reactor_sdk. Local testing is optional; /deploy/development/local-testing covers reactor run, which needs Docker.
> Reactor hosts multiple models, each with its own connect slug (modelName) and command/event schema. The video model catalog — slug, typed SDK package, and links to its schema — is at /model-api-reference/overview. Robotics policy documentation starts at /robotics/overview; The launch policies are Cosmos Nano DROID (/robotics/cosmos/nano-policy-droid/), DreamZero DROID (/robotics/dreamzero/droid/), and FLUX Action DROID (/robotics/flux-action/droid/), organized by model family and embodiment. Some models expose one slug per experience (e.g. HappyOyster); always take the slug from the model's own pages, never guess it.
> Fastest path to a working app: `npx create-reactor-app my-app --model=<slug>` scaffolds a complete app with secure auth wired up. Typed TypeScript SDKs are published as @reactor-models/<model>; Python uses the base reactor-sdk package.
> Auth: exchange an API key (rk_...) for a JWT via POST https://api.reactor.inc/tokens from your server. Never put the API key in client-side code.
> Append .md to any docs URL for clean Markdown. Search these docs via the MCP server at https://docs.reactor.inc/mcp.

# Cosmos3 Policy DROID model walkthrough

> The files, contract, loading, and prediction step of the Cosmos3 Policy DROID model on Reactor Runtime.

Cosmos3 Policy DROID serves NVIDIA's policy as a Reactor model. This page explains how the
[cookbook model](https://github.com/reactor-team/reactor-cookbook/tree/main/models/cosmos3-policy-droid) is built: what
each file does, how the model loads, and what happens in each prediction step.
[Deploy Cosmos3 Policy DROID](https://docs.reactor.inc/deploy/development/robotics/cosmos3-policy-droid) deploys these files unchanged.

The code on this page is simplified to show how the model works. The full files add logging, metrics, and input
validation.

## Files

The model has 2 classes. The runtime drives the model class, and the model class calls the policy class, which runs the
weights. This is the split that [Model Structure](https://docs.reactor.inc/deploy/development/reactor-app/application-and-model.md)
describes.

* `cosmos3_policy_droid_types.py` declares the contract: the 3 video tracks, the commands, and the message.
* `cosmos3_policy_droid.py` holds the model class, `Cosmos3PolicyDroid`. It decides when to predict and sends each
  chunk.
* `cosmos3_policy_droid_model.py` holds the policy class, `Cosmos3PolicyModel`. It is plain Python with no Reactor
  imports. It loads the weights and predicts 1 chunk at a time.
* `cosmos3_policy_droid_assets.py` clones the NVIDIA source and downloads the checkpoint.
* `cosmos3_policy_droid.yaml` sets the checkpoint, the NVIDIA source revision, and the sampler settings.

The 2 classes exchange 2 dataclasses: `PolicyInput` goes to the policy, and `PolicyResult` comes back.

## Contract

The contract is everything a client can send or receive:

```python cosmos3_policy_droid_types.py (simplified) theme={"theme":{"light":"github-light","dark":"github-dark-high-contrast"}}
class PolicyMedia(MediaInput):
    wrist_view: Video
    exterior_view_1: Video
    exterior_view_2: Video


class PolicyState(InputState):
    task_description: str = InputField(default="", max_length=300, moderate=True)
    proprio_json: str = InputField(default="")
    executed_step_json: str = InputField(default="")

    _last_executed: int = -1
    _predicted: int = -1


class ActionPrediction(ModelMessage):
    action: list[list[float]] = MessageField(default=None)
    step: int = MessageField(default=0)
```

* **Video tracks:** `PolicyMedia` declares the 3 inbound tracks. The attribute names are the track names that the client
  publishes on.
* **Commands:** each `InputField` on `PolicyState` creates a command named `set_<field>`. For example,
  `set_task_description` writes `task_description`. The runtime checks `max_length` before the model reads the value.
  `moderate=True` asks the deployment to moderate the task text.
* **Counters:** `_last_executed` and `_predicted` track the prediction loop. Fields that start with `_` create no
  command, the client cannot see them, and they reset when a session ends.
* **Message:** `ActionPrediction` is the `action_prediction` message. It holds the `(32, 8)` action array and the chunk
  number.

The model class also declares the `reset` command with `@event`.

## Loading

The runtime calls `load()` once per process, before the first session:

```python cosmos3_policy_droid.py (simplified) theme={"theme":{"light":"github-light","dark":"github-dark-high-contrast"}}
def load(self, config_path):
    self.policy = Cosmos3PolicyModel()
    self.policy.load(config_path, get_weights_path())
```

`config_path` is `cosmos3_policy_droid.yaml`, set by `runtime.config` in `reactor.yaml`. `get_weights_path()` returns the
folder that holds the NVIDIA source and the weights, set by `runtime.weights_path`.

`Cosmos3PolicyModel.load()` then does 4 things:

1. Reads `cosmos3_policy_droid.yaml`.
2. Clones the NVIDIA source at the pinned revision, if it is not in the weights folder.
3. Builds NVIDIA's policy service, which downloads the checkpoint and tokenizer into the weights folder.
4. Runs 2 warmup predictions, so the first compilation, about 20 seconds, happens before the first session.

## Prediction step

The runtime runs the model in a loop of steps. Each step calls 3 methods in order:

![Each step calls three methods in order. process\_input() checks the inputs and returns a PolicyInput, or skips the step when an input is missing. generate() passes the PolicyInput to the policy, which returns a PolicyResult. process\_output() sends the chunk to the client as action\_prediction.](https://mintcdn.com/reactortechnologiesinc/AFS5VXMUwc0tUo4V/diagrams/cosmos3-prediction-step.svg?fit=max\&auto=format\&n=AFS5VXMUwc0tUo4V\&q=85\&s=b9eedf6c3d8f21868abb3901310dfe45)

[The step loop](https://docs.reactor.inc/deploy/development/reactor-app/step-loop.md) explains this loop for every model.

### Check the inputs

`process_input()` decides whether the model can predict now. It raises `ApplicationError` when an input is missing. The
runtime then skips the step without calling `generate()`, and calls `process_input()` again on the next step:

```python cosmos3_policy_droid.py (simplified) theme={"theme":{"light":"github-light","dark":"github-dark-high-contrast"}}
async def process_input(self) -> PolicyInput:
    if not self.robot_finished_last_chunk():
        raise ApplicationError("waiting for the executed step")

    frames = self.new_camera_frames()
    if len(frames) < 3:
        raise ApplicationError("waiting for a new frame from each camera")

    joints, gripper = parse_proprio(self.state.proprio_json)
    return PolicyInput(**frames, joint_position=joints, gripper_position=gripper, task=self.state.task_description)
```

The [full `process_input()`](https://github.com/reactor-team/reactor-cookbook/blob/main/models/cosmos3-policy-droid/cosmos3_policy_droid.py)
has the real logic for each check.

The checks run in this order:

1. **Executed step:** after the first chunk, `executed_step_json` must hold a `step` greater than the last one accepted.
   When it does, the model asks for a new frame from each camera.
2. **Camera frames:** each of the 3 tracks must deliver a new frame. A new frame arrives after the executed step. If the
   executed step includes `observation_time_us`, a new frame is one captured at or after that time.
3. **Robot state:** `proprio_json` must parse into rows of 7 joint values and 1 gripper value, all finite.

When all 3 checks pass, `process_input()` records the executed step and returns a `PolicyInput`. The first chunk skips
the executed-step check.

### Predict a chunk

Prediction crosses the 2 classes. The runtime calls `generate()` on the model class. That method hands the input to
`generate()` on the policy class, which runs the weights:

```python cosmos3_policy_droid.py (simplified) theme={"theme":{"light":"github-light","dark":"github-dark-high-contrast"}}
class Cosmos3PolicyDroid(ReactorApp):  # Model class: the runtime calls it
    def generate(self, input: PolicyInput) -> PolicyResult:
        return self.policy.generate(input)  # Hands off to the policy class
```

```python cosmos3_policy_droid_model.py (simplified) theme={"theme":{"light":"github-light","dark":"github-dark-high-contrast"}}
class Cosmos3PolicyModel:  # Policy class: plain Python, runs the weights
    def generate(self, input: PolicyInput) -> PolicyResult:
        obs = {
            "prompt": input.task,
            "observation/wrist_image_left": input.wrist_view,
            "observation/exterior_image_1_left": input.exterior_view_1,
            "observation/exterior_image_2_left": input.exterior_view_2,
            "observation/joint_position": input.joint_position,
            "observation/gripper_position": input.gripper_position,
        }
        actions = self.service.infer(obs)["action"]  # (32, 8)
        return PolicyResult(actions=actions)
```

The policy class maps the input to the observation names that the DROID checkpoint uses. Then it calls NVIDIA's policy
service, which returns a `(32, 8)` action array.

The policy keeps nothing between predictions. Each chunk depends only on the frames, the robot state, and the task in
its `PolicyInput`. The sampler settings, 4 steps with guidance 3.0, come from `cosmos3_policy_droid.yaml`.

### Send the chunk

`process_output()` sends the result to the client:

```python cosmos3_policy_droid.py (simplified) theme={"theme":{"light":"github-light","dark":"github-dark-high-contrast"}}
async def process_output(self, outcome: StepOutcome) -> None:
    if outcome.error is not None:
        raise outcome.error
    self.state._predicted += 1
    await self.send(
        ActionPrediction(action=outcome.result.actions.tolist(), step=self.state._predicted)
    )
```

An error from `generate()` is a GPU or checkpoint failure.
`process_output()` raises it again, and the runtime ends the session with an error that the client sees.

## Sessions and reset

* **Session start:** `@session_started` clears the stored frames and asks for a new frame from each camera.
* **Session end:** `@session_ended` clears the frames and calls `Cosmos3PolicyModel.reset()`. The policy keeps no
  state, so its reset is empty. The counters reset with the rest of the state.
* **`reset` command:** sets the counters back, so the next chunk is step `0` and needs no executed step.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.