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

# Direct Control

> Let an LLM drive a robot: attach DirectControl to an endpoint so the agent gets the `move` tool, then point a tool-calling agent at it.

This guide outlines how to let an LLM drive a robot. `DirectControl` serves an embodiment's parts as one MCP `move` tool, following [Direct Control](https://docs.rua.hud.ai/interfaces/direct-control.md). The steps serve one arm, and a [later section](#two-arms) serves two.

**1. Write a single-env bridge**

Direct control drives single-env sims. The action needs a control kind, `names`, and bounds, as the `PointArm` bridge in [Writing a bridge](https://docs.rua.hud.ai/guides/writing-a-bridge.md#a-bridge) has.

**2. Attach DirectControl to the endpoint**

```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()
```

`ContractEmbodiment` builds the arm and gripper parts from the contract alone, with the arm in the contract's own space (`space=` picks `ee_delta` for a hand-pose contract), so it has no model of the arm's reach or collisions. It checks the contract's limits and the speeds you give it. A robot with its own embodiment can veto more. `sim.capabilities()` now returns `robot` and `control`, an `mcp` capability.

**3. Point a tool-calling agent at it**

Any agent that opens `control` and calls its tools works:

```python theme={"dark"}
control = await run.client.open("control")
tools = await control.list_tools()
result = await control.call_tool(
    "move",
    {
        "keyframes": [{"t": 2.0, "arm": {"x": 0.5}}],
        "note": "the gripper is left of the goal",
    },
)
```

## Two arms

A robot with several arms is served the same way. `contract_arms` builds one `ContractEmbodiment` per arm from a contract whose action columns are named `<arm>.<column>`, and `Composite` joins them into one robot with the parts `left_arm`, `left_hand`, `right_arm` and `right_hand`. Save the bridge as `sim.py`:

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

from rua.sim import RobotBridge

NAMES = ["left.x", "left.y", "left.grip", "right.x", "right.y", "right.grip"]

CONTRACT = {
    "control_rate": 10,
    "features": {
        "observation/image": {"role": "observation", "type": "rgb"},
        "observation/state": {"role": "observation", "names": NAMES},
        "action": {
            "role": "action",
            "type": "ee_abs",
            "names": NAMES,
            "stats": {"min": [-1.0, -1.0, 0.0] * 2, "max": [1.0, 1.0, 1.0] * 2},
        },
    },
}

HOME = np.array([0.0, 0.3, 0.0, 0.0, -0.3, 0.0])


class TwoArms(RobotBridge):
    """Two grippers that track their commands. Success is both at x >= 0.5, closed."""

    def __init__(self) -> None:
        super().__init__()
        self.contract = CONTRACT
        self.state = HOME.copy()

    def reset(self, **task_args) -> str:
        self.state = HOME.copy()
        self.success = False
        return "move both grippers to x = 0.5, then close them"

    def step(self, action) -> None:
        self.state = np.asarray(action[0], dtype=np.float64)
        arms = self.state.reshape(2, 3)
        self.success = bool(np.all(arms[:, 0] >= 0.5) and np.all(arms[:, 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])
```

In `env.py`, the embodiment is the only change. The hooks and the template are the same, with `TwoArms` in place of `PointArm`:

```python env.py theme={"dark"}
from rua.direct import DirectControl
from rua.embodiments.composite import contract_arms
from rua.sim import RobotEndpoint
from sim import CONTRACT, TwoArms

sim = RobotEndpoint(TwoArms).attach(env)
robot = contract_arms(CONTRACT, gripper=(0.0, 1.0), max_speed={"position": 0.5, "grip": 2.0})
DirectControl(robot).attach(sim)
```

One keyframe can now move both arms, and every part shares its clock:

```python theme={"dark"}
result = await control.call_tool(
    "move",
    {
        "keyframes": [
            {"t": 2.0, "left_arm": {"x": 0.5}, "right_arm": {"x": 0.5}},
            {"t": 3.0, "left_hand": 1.0, "right_hand": 1.0},
        ],
        "note": "both grippers reach x = 0.5, then close",
    },
)
```

The reply lists all four parts. Its status is `ended`, because the task succeeds while the second keyframe plays.

`contract_arms` checks each arm on its own, so nothing vetoes one arm hitting the other. Say in the task prompt that the arms can collide. An env can opt in to `hand_clearance=` to keep the hands apart. Arms in different spaces, and the other options, are in the [reference](https://docs.rua.hud.ai/reference/direct-control.md#composite).

The agent now has `move` and replies as described in the [reference](https://docs.rua.hud.ai/reference/direct-control.md). Every played tick also streams to the rollout's trace when `HUD_API_KEY` is set in the environment's process.


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