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

# Contract

> Reference for the robot contract: the env's self-description published in the robot capability, with every field rua reads and which component reads it.

The **contract** is a JSON object an env publishes as `params["contract"]` of its `robot` capability. rua
passes it through verbatim; each component reads only the fields it needs. There is no schema validation: a
missing field falls back to the defaults below, or raises where noted.

```json theme={"dark"}
{
  "robot_type": "point_arm",
  "control_rate": 10,
  "features": {
    "observation/image": {"role": "observation", "type": "rgb"},
    "observation/state": {"role": "observation", "names": ["x", "y", "grip"]},
    "action": {
      "role": "action",
      "type": "ee_abs",
      "names": ["x", "y", "grip"],
      "stats": {"min": [-1.0, -1.0, 0.0], "max": [1.0, 1.0, 1.0]}
    }
  }
}
```

## Top-level fields

| Field | Type | Read by | Meaning |
| - | - | - | - |
| `control_rate` | number | `DirectControl` (required), `GymBridge` | Control ticks per second. Sets video and plot timing and direct control's pacing. |
| `robot_type` | string | nothing | A label for the robot. rua carries it and does not read it. |
| `features` | object | everything | Feature name to feature object, in order. |

## Feature fields

A feature's name is the key its arrays travel under on the wire, such as `observation/state`.

| Field | Type | Meaning |
| - | - | - |
| `role` | `"observation"` \| `"action"` | Required. Exactly one feature should be the action; components take the first. |
| `type` | string | For observations, `rgb`, `bgr`, `gray` or `depth` marks a camera. For the action, a coarse control kind for direct control: `ee_abs`, `joint_pos` or `ee_del`. |
| `names` | list of strings | Per-element labels. Labels the trace's plots, sizes derived hold actions, and names direct-control dimensions. |
| `shape` | list of ints | The feature's shape. `hold_action` uses the action's. |
| `stats` | object | `min` / `max` statistics of the action. Direct control reads `stats.min` / `stats.max` as the action's bounds when `limits` is absent. |
| `limits` | object | `min` / `max` action bounds for direct control; wins over `stats`. |
| `state_type` | string | The action's exact control kind for direct control (`EE_ABS_POSE`, `EE_ABS_POS`, `JOINT_ABS_POS`, `EE_DEL_POSE`, `EE_DEL_POS`); wins over `type`. |
| `order` | string | `"start-end"` element range of a wire key that this feature labels; see below. |
| `camera` | object | For an `rgb` camera, where it is; see [Camera placement](#camera-placement). |

## How each component reads it

| Component | Reads |
| - | - |
| `DirectControl` | The action's `state_type` / `type`, `names`, `limits` / `stats`; `control_rate`; `rgb` cameras and their `camera`; state `names`. |
| `TraceRecorder` | Observation features' `names` and `order`, and the action's `names`, to label plots. |
| `RobotBridge.hold_action` | The action's `shape`, else the length of its `names`. |

## Derived contracts

`attach_gym` writes a minimal contract when none exists: `control_rate`, one `"type": "rgb"` feature
per camera, one feature per state vector with `names` of the form `<leaf>_<i>`, and an `action` feature with
`names` `act_0` to `act_<A-1>`. They carry no `shape` or `stats`. Edit the file to relabel; an existing
file always wins.

## Camera placement

An `rgb` camera's `camera` object says where the camera is, and the `move` tool's description puts it in words, once, after the frames. Fill it from the sim's own camera data, so the agent is told what the sim renders.

| Field | Meaning |
| - | - |
| `mount` | `"world"` for a camera fixed in the world. Otherwise the body part it moves with, in plain words: `"wrist"`, `"head"`, `"left wrist"`. |
| `pose` | For a `"world"` camera, the 4 by 4 transform from its optical frame (x right, y down, z forward) to the robot's base frame, in metres. `rua.direct.look_at_pose(eye, target)` builds it from a position and a point the camera looks at. |
| `description` | For a camera whose sim cannot say where it is: the words that follow the camera's name, in place of derived ones. |

```json theme={"dark"}
{
  "observation/front": {"role": "observation", "type": "rgb", "camera": {"mount": "world", "pose": [[0, 0, -1, 1.0], [1, 0, 0, 0], [0, -1, 0, 0.5], [0, 0, 0, 1]]}},
  "observation/wrist": {"role": "observation", "type": "rgb", "camera": {"mount": "wrist"}},
  "observation/head": {"role": "observation", "type": "rgb", "camera": {"description": "is fixed above and behind the arms, looking forward at the table."}}
}
```

becomes:

```
Cameras: `front` is fixed in the world, about 1.00 m in front of the base and 0.50 m above it, looking back toward the base, level. `wrist` moves with the wrist. `head` is fixed above and behind the arms, looking forward at the table.
```

A camera without `camera` is left out of the sentence. A `camera` object with an unknown field, a `pose` that is not rigid, a `pose` on a camera that moves, or neither `mount` nor `description` makes `DirectControl` raise a `ValueError` naming the feature when it starts. The sentence is `DirectControl.camera_text`; a subclass that rebuilds the `move` description passes it as `describe(spec, control.settings, cameras=control.camera_text)`, and the `describe_cameras` setting decides whether it is shown.

## Labels with `order`

The trace recorder labels a flat state vector from the contract. When several features whose names contain the
wire key as a dotted segment declare `order` ranges that together tile the vector, each becomes its own labelled
group on the trace. Otherwise, a feature named exactly like the key whose `names` match the vector's length labels
it whole, and failing that the vector is unlabelled.

```json theme={"dark"}
{
  "state.eef_pos": {"role": "observation", "order": "0-2", "names": ["x", "y", "z"]},
  "state.gripper": {"role": "observation", "order": "3-3", "names": ["grip"]}
}
```

> [!NOTE]
>
> A camera is marked by `"type": "rgb"`, which is what derived contracts write. Direct control returns only `rgb`
> cameras as images.


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