Metadata-Version: 2.5
Name: a2a-robots
Version: 0.2.0
Summary: Expose robots as A2A agents with task-level skills and adapter-enforced safety limits
Project-URL: Repository, https://github.com/hybroai/a2a-robots
Author-email: HYBRO AI <info@hybro.ai>
License-Expression: Apache-2.0
License-File: LICENSE
Classifier: Development Status :: 2 - Pre-Alpha
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Requires-Python: >=3.11
Requires-Dist: a2a-adapter<0.5,>=0.4.1
Provides-Extra: dev
Requires-Dist: httpx>=0.26; extra == 'dev'
Requires-Dist: pytest-asyncio>=0.23; extra == 'dev'
Requires-Dist: pytest>=8; extra == 'dev'
Requires-Dist: ruff>=0.6; extra == 'dev'
Description-Content-Type: text/markdown

# a2a-robots

Expose a robot as an [A2A](https://a2a-protocol.org) agent. An agent plans the work and sends one task-level skill at a time; the adapter validates each request, enforces safety limits, runs the skill on the robot backend, and returns a fixed result format.

Built on [a2a-adapter](https://github.com/hybroai/a2a-adapter). Early development.

| Package | What it is |
| --- | --- |
| `a2a-robots` (this directory) | The core: skills, safety limits, the controller, the A2A adapter, and `FakeBackend`. |
| [`a2a-robots-lerobot`](https://github.com/hybroai/a2a-robots/tree/main/packages/a2a-robots-lerobot) | Hugging Face LeRobot arms (`SO-100`/`SO-101`, `Bi-SO`, `Koch`) via `Robot` and `RobotKinematics`. |
| [`a2a-robots-pollen`](https://github.com/hybroai/a2a-robots/tree/main/packages/a2a-robots-pollen) | Pollen Robotics Reachy 2 arms and grippers over `reachy2-sdk`. |
| [`a2a-robots-sharpa`](https://github.com/hybroai/a2a-robots/tree/main/packages/a2a-robots-sharpa) | Sharpa Wave hands, simulated in MuJoCo. |
| [`a2a-robots-ros2`](https://github.com/hybroai/a2a-robots/tree/main/packages/a2a-robots-ros2) | An allowlisted ROS 2 bridge for bring-up and debugging. Not the typed skill contract. |

## Skills

Requests are JSON, sent as a text part or a data part:

```json
{"skill": "move_to", "args": {"hand": "right", "pose": {
  "frame": "world", "units": "m",
  "position": [0.30, -0.20, 0.15],
  "orientation": {"quaternion": [1, 0, 0, 0]}}}}
```

| Skill | Args | Notes |
| --- | --- | --- |
| `observe` | none | Read only. Always allowed, even during motion. |
| `move_to` | `hand`, `pose` | `frame`, `units` (`"m"`) and a unit quaternion are required. |
| `move_path` | `hand`, `waypoints`, optional `blend_radius_m`, `speed_scale` | Advertised by backends that support full-path validation and execution. Every segment is validated for reach, safe zones, and collision before anything moves. |
| `open` | `hand` | Advertised when the robot has a gripper. |
| `close` | `hand` | `held` reports whether something is now held. Advertised when the robot has a gripper. |
| `stop` | none | Stops motion now and freezes every hand. Always allowed. |

Every skill returns the same result, as JSON text and as an `application/json` data part:

```json
{"skill": "close", "success": false, "failure_code": "slipped",
 "detail": "object slipped during the grasp",
 "final_pose": {"right": {...}}, "contact": {"right": {}}, "held": {"right": false}}
```

A skill that ran but did not succeed, or was refused before moving, is a completed A2A task with `success: false` and a `failure_code`, so the agent can observe and retry:

| `failure_code` | Meaning |
| --- | --- |
| `step_too_large` | Single `move_to` is larger than `max_step_m` or `max_step_rad`. Nothing moved; the result includes the step limits. |
| `path_too_long` | `move_path` exceeds `max_waypoints` or `max_path_length_m`. Nothing moved; the result includes the path limits. |
| `out_of_workspace` | Target pose, waypoint, or planned path exits the workspace box or violates a keep-out zone / safety plane. Nothing moved; the result includes the limits. |
| `busy` | Another skill is running, the robot is stopping, or the last motion has not stopped. Nothing moved. |
| `unreachable` | No kinematic/joint solution reaches the target (IK failed, joint limit, or excessive joint jump). Nothing moved. |
| `collision` | Planned path collides with the scene, fixtures, or robot self. Nothing moved. |
| `safety_stopped` | Controller safety state blocked or halted motion (e-stop, protective stop, fault, or controller limit revision drift). Check `safety`. |
| `stopped` | `stop` was requested during the motion. |
| `timeout` | The motion took longer than `skill_timeout_s` and was stopped. |
| `not_settled` | The command finished its settle window without reaching pose or gripper tolerances; the robot is held at its current pose. |
| `slipped` | The backend lost the grasp. |

A malformed request (unknown or unsupported skill, unknown or gripperless hand, missing or extra fields, wrong units, a frame other than the workspace frame, or a non-unit quaternion) fails the A2A task with the reason, and nothing moves. A cancelled skill ends the task canceled; see Safety for when it ends failed instead.

The agent card states the limits in a data-only [A2A extension](https://a2a-protocol.org/latest/topics/extensions/) under `capabilities.extensions`. It is not required, so clients need not activate it, and its URI is `a2a_robots.SAFETY_LIMITS_EXTENSION`:

```json
{"uri": "https://github.com/hybroai/a2a-robots/extensions/safety-limits/v2",
 "required": false,
 "params": {"source": "adapter", "path_check": "collision", "revision": null,
   "frame": "world",
   "workspace": {"min_xyz": [0.0, -0.5, 0.0], "max_xyz": [0.6, 0.5, 0.5]},
   "keep_out_zones": [], "safety_planes": [], "reduced_speed_zones": [],
   "max_step_m": 0.01, "max_step_rad": 0.05,
   "max_speed_m_s": null, "max_speed_rad_s": null,
   "max_path_length_m": null, "max_waypoints": 100,
   "skill_timeout_s": 10.0, "stop_timeout_s": 2.0}}
```

## Safety

Limits come from the robot controller via `RobotBackend.controller_limits()` (`ControllerLimits`), from `SafetyLimits` passed to `RobotAdapter`, or merged from both (adapter physical bounds can narrow controller limits, never loosen them—looser bounds fail fast at startup):

| Field | Default | Meaning |
| --- | --- | --- |
| `workspace` | required (or from controller) | An axis-aligned box in metres, in one named frame. Every pose/waypoint must use this frame. |
| `keep_out_zones` | `()` | Forbidden `BoxZone` regions inside the workspace. |
| `safety_planes` | `()` | Half-space `SafetyPlane` constraints (`dot(normal, position) <= offset_m`). |
| `reduced_speed_zones` | `()` | Optional `BoxZone` regions with a lower `max_speed_m_s`. Advertised from the controller; enforced by the robot controller / safety PLC (and reflected live via `SafetyState.speed_scale`). Host planners apply global `max_speed_*` only, not per-zone clamping. |
| `max_step_m` | `0.01` (`None` allowed with `PathCheck.COLLISION`) | Largest move of one `move_to`, in metres. |
| `max_step_rad` | `0.05` (`None` allowed with `PathCheck.COLLISION`) | Largest rotation of one `move_to`, in radians. |
| `max_speed_m_s` / `max_speed_rad_s` | `None` | Optional TCP/joint speed ceilings. |
| `max_path_length_m` / `max_waypoints` | `None` / `100` | Optional total chord length cap and waypoint count cap for `move_path`. |
| `skill_timeout_s` | `10.0` | A motion that runs longer is stopped and fails with `timeout`. |
| `stop_timeout_s` | `2.0` | How long a stop may take before the robot is reported as possibly still moving. |

- `RobotController` / `RobotAdapter` require `backend.path_check == PathCheck.COLLISION` by default (`require_path_check=PathCheck.COLLISION`). Backends without 3D scene collision checking (e.g. desk arms with `PathCheck.EE_WORKSPACE`, or `FakeBackend` with `PathCheck.NONE`) must opt out explicitly at startup, and the active `path_check` level is advertised in the agent card.
- Unbounded steps (`max_step_m=None` / `max_step_rad=None`) and `move_path` require `PathCheck.COLLISION` (unless `require_path_check=PathCheck.NONE` for test doubles).
- Live controller safety state (`SafetyState`: `normal`, `reduced`, `protective_stop`, `estop`, `fault`, plus optional `limits_revision`) is reported in `SkillResult.safety`. Blocking safety states refuse new motions with `safety_stopped`. A changed `limits_revision` (when both the startup `revision` and the live field are set) also refuses with `safety_stopped`. Mid-motion e-stop / protective stop is handled by the backend while it executes; the controller only re-checks `safety_state()` before the next skill.
- A move larger than `max_step_m` or `max_step_rad`, a path exceeding `max_waypoints` / `max_path_length_m`, or a pose/waypoint violating `workspace`, `keep_out_zones`, or `safety_planes` is refused before anything moves. Moves are never clamped.
- A step is measured from the hand's last target when its last skill was a successful `move_to` or `move_path`, because a robot settles within a small tolerance of the target, not exactly on it. After anything else (a failed move, a stop, a timeout, a cancel, or `open`/`close` on that hand) it is measured from the observed pose.
- If a motion finishes its settle window without converging (`not_settled`), the controller calls `hold()` so hardware actuators stop pushing against any unmodeled obstruction.
- One skill runs at a time per robot. A second motion request fails at once with `busy` instead of queueing.
- `stop`, `tasks/cancel`, timeouts and shutdown all stop the backend. Backends run in a worker thread and poll a stop flag every control step (or controller status poll), so stopping does not depend on cancelling a Python task.
- `tasks/cancel` replies only after the motion has stopped and the hands are frozen, and the task is then canceled.
- If the motion does not stop within `stop_timeout_s` (2 s by default), the hands are still told to hold, but the stop or timed-out skill fails with "the robot did not stop ... it may still be moving". No new motion starts until that motion ends.
- A `tasks/cancel` whose stop times out keeps waiting for the motion, up to a2a-adapter's cancel wait (10 s). If the motion ends by then the task is canceled; otherwise `tasks/cancel` returns the task failed with "Cancel failed: the robot did not stop ... it may still be moving".
- If the backend raises during a motion, the hands are frozen and the task fails. The error is logged on the server; the client gets a message naming the task, because backend errors can hold internal details.
- `serve_robot()` binds `127.0.0.1` by default, because anyone who can reach the server can move the robot.

## Quick start

```bash
uv sync --extra dev
uv run python examples/fake_robot.py   # serves on http://127.0.0.1:9100/
```

```bash
curl -s http://127.0.0.1:9100/ -H 'Content-Type: application/json' -d '{
  "jsonrpc": "2.0", "id": 1, "method": "message/send",
  "params": {"message": {"role": "user", "messageId": "1",
    "parts": [{"kind": "data", "data": {"skill": "observe"}}]}}}'
```

## Adding a robot

This repository keeps each robot backend as an independent Python package under `packages/a2a-robots-<name>` (for example `a2a-robots-sharpa`) with its own dependencies, lockfile, and virtual environment. Only `a2a-robots` (or `a2a-adapter` for the ROS 2 bridge) is shared. `FakeBackend` stays in the core package only as a dependency-free test double.

### Planning

Arms such as Sharpa D01 take joint position targets, with planning and collision checking on the host. `a2a_robots.planning` defines that layer: a `Planner` turns a pose target into a `JointTrajectory` (one target per control step for the joints that carry the hand), and the backend streams it, checking the stop flag between targets. A planner reports "no safe path" by raising `PlanError`, which becomes a completed skill with `success: false`. `interpolate()` gives a speed-limited, smooth joint-space path for planners to build on. Any planner can be plugged in: `MujocoPlanner` today, a ROS 2 or Isaac planner later.

A robot package subclasses `RobotBackend` and implements `hands`, `observe`, `move_to`, `open`, `close`, `hold` and `shutdown`. Motion methods are synchronous, run in a worker thread, and must check the `stop` event at every control step and return `MotionOutcome(FailureCode.STOPPED)` once it is set. See `src/a2a_robots/fake.py` and `packages/a2a-robots-sharpa`.

Every backend must pass the shared conformance checks in `a2a_robots.testing`. Subclass `BackendContract` in the package's tests and return the backend from `make_backend()`:

```python
from a2a_robots.testing import BackendContract


class TestMyRobotContract(BackendContract):
    def make_backend(self):
        return MyRobotBackend(...)
```

They check that `observe` reports every hand and stays safe during motion, that `move_to`, `open` and `close` check `stop` throughout the motion and return `stopped` when it is set before or during it, that `hold` keeps the hands still, and that the robot moves again after a stop. Override `move_target()` or the tolerances if the default small move does not suit the robot.

## Development

Each package is an independent `uv` project with its own `uv.lock` and environment:

```bash
uv sync --extra dev
uv run ruff format --check . && uv run ruff check .
uv run pytest
uv run --directory packages/a2a-robots-lerobot --extra dev pytest
uv run --directory packages/a2a-robots-pollen --extra dev pytest
uv run --directory packages/a2a-robots-ros2 --extra dev pytest
uv run --directory packages/a2a-robots-sharpa --extra dev pytest
```

## Releases

Package versions and PyPI publishes are automated with release-please. See
[CONTRIBUTING.md](https://github.com/hybroai/a2a-robots/blob/main/CONTRIBUTING.md#release-process).

## License

Apache-2.0
