> ## 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.

# Quickstart

> Install rua, serve a tiny arm as a HUD environment with direct control, and play two moves on it to a graded reward.

This page builds the smallest complete robot rollout: a simulated gripper written as a bridge, a HUD environment that
serves it with [direct control](https://docs.rua.hud.ai/interfaces/direct-control.md), and a scripted agent that moves it to a reward.
Everything runs locally, with no API key and no GPU. If you already have a Gym env, you can skip the bridge:
[serving a gym env](https://docs.rua.hud.ai/guides/serving-a-gym-env.md) serves it and adds direct control.

## 1. Install

rua needs Python 3.11 or 3.12.

```bash uv theme={"dark"}
uv pip install rua
```

```bash pip theme={"dark"}
pip install rua
```

> [!NOTE]
>
> These pages describe rua 0.2.4 and later. The `rua` 0.0.1 release on PyPI holds only the
> [eval interface](https://docs.rua.hud.ai/guides/eval-interface.md). To try an unreleased commit, install
> `"rua @ git+https://github.com/hud-evals/rua.git@<sha>"`.

## 2. Write a simulator

A simulator is a `RobotBridge`: three hooks and a contract that describes the robot's action and observations.
This one is a gripper that tracks its commanded `(x, y)` exactly. It succeeds once `x` reaches 0.5 with the
gripper closed. Save it as `sim.py`:

```python sim.py theme={"dark"}
import numpy as np

from rua.sim import RobotBridge

CONTRACT = {
    "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]},
        },
    },
}


class PointArm(RobotBridge):
    """A gripper that tracks its commanded (x, y) exactly; success is x >= 0.5 with grip closed."""

    def __init__(self) -> None:
        super().__init__()
        self.contract = CONTRACT
        self.state = np.zeros(3)

    def reset(self, **task_args) -> str:
        self.state = np.zeros(3)
        self.success = False
        return "move x to 0.5, then close the gripper"

    def step(self, action) -> None:
        self.state = np.asarray(action[0], dtype=np.float64)  # [N, A] -> this env's row
        self.success = bool(self.state[0] >= 0.5 and self.state[2] >= 0.9)

    def get_observation(self):
        data = {
            "observation/image": np.zeros((1, 64, 64, 3), dtype=np.uint8),
            "observation/state": self.state[None].astype(np.float32),
        }
        return data, np.array([self.success])
```

A bridge gives you control over grading and the contract, and the [bridge guide](https://docs.rua.hud.ai/guides/writing-a-bridge.md) covers
it. A Gym env needs no bridge: [`attach_gym`](https://docs.rua.hud.ai/guides/serving-a-gym-env) serves it, and direct control needs only a short contract.

## 3. Declare the environment

`RobotEndpoint` runs the bridge in its own process. `DirectControl` serves the robot as one MCP `move` tool,
and `ContractEmbodiment` builds the robot's parts from the contract alone. The task template resets the sim,
hands the agent the sim's instruction as its prompt, and returns the sim's grade. Save it as `env.py`:

```python env.py theme={"dark"}
import math

from hud import Environment

from rua.direct import DirectControl
from rua.embodiments.contract import ContractEmbodiment
from rua.sim import RobotEndpoint
from sim import CONTRACT, PointArm

env = Environment(name="arm")
sim = RobotEndpoint(PointArm).attach(env)
speeds = {"position": 0.5, "rotation": math.pi, "joint": math.pi, "grip": 2.0}
embodiment = ContractEmbodiment(CONTRACT, gripper=(0.0, 1.0), max_speed=speeds)
DirectControl(embodiment).attach(sim)


@env.initialize
async def up() -> None:
    await sim.start()
    for capability in await sim.capabilities():
        env.add_capability(capability)


@env.shutdown
async def down() -> None:
    await sim.stop()


@env.template()
async def reach(max_ticks: int | None = 200):
    ep = await sim.reset(max_ticks=max_ticks)
    yield {"prompt": ep["prompt"]}
    yield await sim.result()
```

## 4. Move the robot

An agent is anything that opens the `control` capability and calls its tools. This one plays two fixed `move`
calls, each a list of timed keyframes. In practice the agent is a tool-calling LLM, as in
[the last section](#let-an-llm-drive-it). Save it as `run.py`:

```python run.py theme={"dark"}
import asyncio

from hud import Task
from hud.agents.base import Agent
from hud.eval.run import rollout
from hud.runtime import LocalRuntime

MOVES = [
    {"keyframes": [{"t": 2.0, "arm": {"x": 0.5}}], "note": "reach x = 0.5"},
    {"keyframes": [{"t": 1.0, "gripper": 1.0}], "note": "close the gripper"},
]


class Scripted(Agent):
    async def __call__(self, run):
        control = await run.client.open("control")
        for move in MOVES:
            result = await control.call_tool("move", move)
            print(result.content[0].text)
        run.trace.content = "done"


async def main():
    trace = await rollout(Task(env="arm", id="reach"), Scripted(), runtime=LocalRuntime("env.py"))
    print("reward:", trace.reward)


asyncio.run(main())
```

## 5. Run it

```bash theme={"dark"}
python run.py
```

```text theme={"dark"}
[env] robot listening on ws://127.0.0.1:43991
{"status": "completed", "elapsed_s": 2.0, "steps": 20, "parts": {"arm": {"frame": "base", "pose": {"x": 0.5, "y": 0.0}, "gap": {"pos_mm": 0.0}}, "gripper": {"grip": 0.0}}}
{"status": "ended", "elapsed_s": 0.9, "steps": 9, "parts": {"arm": {"frame": "base", "pose": {"x": 0.5, "y": 0.0}}, "gripper": {"grip": 0.97, "gap": 0.03}}}
[env] result: success=True total_reward=0.000
reward: 1.0
```

The second reply says `ended`, because the task succeeded while the second move played. Each spawn also prints a
harmless `RuntimeWarning` from `runpy` about `rua.sim.bridge`, left out of the output above, and warnings from
HUD, which you can silence with `python -W ignore run.py`.

Try a move that is too fast, such as `"t": 0.5` for the arm. The reply is `vetoed` and says how long the move
needs. Nothing moves.

## What just happened

1. `LocalRuntime` loaded `env.py`. `RobotEndpoint` started the bridge in its own process, and `DirectControl`
   served a `control` capability next to the `robot` wire.
2. The `reach` template called `sim.reset(...)`. The sim reset itself and returned its instruction as the prompt.
3. The agent opened `control` and called `move`. Each call was checked against the contract's limits and the
   speeds you gave `ContractEmbodiment`, then played tick by tick on the sim.
4. When the task succeeded, the template returned `sim.result()`: a score of `1.0`. The score became the reward.

With a `HUD_API_KEY` set, the same run also streams every tick's state, every `move` request and the camera
video to a trace on [hud.ai](https://hud.ai).

## Let an LLM drive it

Swap the scripted agent for a model from the HUD gateway. `create_direct_agent` builds one with the system
prompt for `move`, and needs `HUD_API_KEY`. In `run.py`, replace `Scripted()` with:

```python theme={"dark"}
from env import embodiment

from rua.direct import create_direct_agent

agent = create_direct_agent(
    "claude-sonnet-4-6",
    spec=embodiment.spec(),
    cameras=1,
    max_turns=12,
)
```

See the [direct control guide](https://docs.rua.hud.ai/guides/direct-control.md).

## Next steps

> [card] [Concepts](https://docs.rua.hud.ai/start/concepts.md)
>
> The sim process, the wire, slots and the agent loop.

> [card] [Serving a gym env](https://docs.rua.hud.ai/guides/serving-a-gym-env.md)
>
> Build args, vectorized envs, and contract files.

> [card] [Direct control](https://docs.rua.hud.ai/guides/direct-control.md)
>
> Spaces, units, settings and two arms.

> [card] [Code control](https://docs.rua.hud.ai/guides/code-control.md)
>
> Let an LLM write Python against the same checked moves.


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