Spaces:
Running
Running
Download src/agent/specs.js from VectorW/xlerobot-sim: direct link, hf CLI and curl.
- Browser
- Download file 13.4 kB
-
https://huggingface.co/spaces/VectorW/xlerobot-sim/resolve/main/src/agent/specs.js
- Command line
-
hf download hf://spaces/VectorW/xlerobot-sim/src/agent/specs.js
-
curl -L -o specs.js https://huggingface.co/spaces/VectorW/xlerobot-sim/resolve/main/src/agent/specs.js
13.4 kB
| // What the robot's tools are, as data: the in-page agent's (tools.js runs them), the ones the page adds for an | |
| // MCP client such as Claude Code (bridge.js, main.js), and how to use them. No imports, so the MCP server | |
| // (tools/mcp/server.mjs) reads the same file in Node. | |
| // | |
| // Positions given to and returned by the tools are in the robot frame: forward, left, up in metres from | |
| // the robot's base. Angles are in degrees; positive turns are to the left. | |
| /** A point that locate gave, standing in for an object's name. */ | |
| const AT = { type: "array", items: { type: "number" }, description: "a point [forward, left, up] in metres, as locate gives it (its at), in place of a name" }; | |
| export const TOOL_SPECS = [ | |
| { | |
| name: "observe", | |
| description: | |
| "Describe the scene: the robot's pose, what each gripper holds, every movable object with its position relative to the robot (forward/left/up in metres), its size, and whether an arm can grasp it from where the robot is (with camera-only perception the objects are left out: locate finds them); the fixtures (surfaces, containers, switches) where the scene has them; and the household task in progress, if any.", | |
| parameters: { type: "object", properties: {} }, | |
| }, | |
| { | |
| name: "look", | |
| description: "Take a picture with the robot's head camera and see it (only for models that accept images).", | |
| parameters: { type: "object", properties: {} }, | |
| vision: true, | |
| }, | |
| { | |
| name: "locate", | |
| description: | |
| "Find objects in a robot camera's picture with Gemini 4 Hydrogen, Google DeepMind's model for robotics (it needs a Gemini API key), as the Gemini Robotics plugin's rgb-object-localization skill does: each match comes with its label, its point and box in the picture (0-1000) and at, its position [forward, left, up] in metres, from the head camera's depth or, for a wrist camera, from where it stands on the furniture (method). pick, place, go_to and look_at take that at. The picture, with the matches drawn on it, comes back too. Without a Gemini key, take a picture (camera, or look) and give the points you see in it instead of query.", | |
| parameters: { | |
| type: "object", | |
| properties: { | |
| query: { type: "string", description: "what to find, e.g. 'the yogurt' or 'every piece of fruit'" }, | |
| camera: { type: "string", description: "head (the default), left_wrist or right_wrist" }, | |
| method: { type: "string", enum: ["depth", "plane"], description: "depth (the head camera's default, an RGB-D camera) or plane (RGB only: where the object's box meets the surface under it; the wrist cameras' default)" }, | |
| points: { | |
| type: "array", | |
| description: "instead of query: objects you see in that camera's last picture, on its 0-1000 grid", | |
| items: { type: "object", properties: { label: { type: "string" }, point: { type: "array", items: { type: "number" }, description: "[y, x]" }, box_2d: { type: "array", items: { type: "number" }, description: "[ymin, xmin, ymax, xmax]" } } }, | |
| }, | |
| }, | |
| }, | |
| }, | |
| { | |
| name: "go_to", | |
| description: "Drive around the furniture to where one arm reaches the named object (or the object at a point from locate), facing it so it can be grasped well; or to a fixture (a counter, the sink, the trash can, a switch). pick and place drive there themselves when needed.", | |
| parameters: { type: "object", properties: { object: { type: "string", description: "object or fixture name from observe" }, at: AT } }, | |
| }, | |
| { | |
| name: "drive", | |
| description: "Drive straight forward (positive) or backward (negative) by a distance in metres. Stops short of furniture in the way.", | |
| parameters: { type: "object", properties: { distance_m: { type: "number" } }, required: ["distance_m"] }, | |
| }, | |
| { | |
| name: "turn", | |
| description: "Turn in place by an angle in degrees (positive = left, negative = right). Stops short of furniture the robot would swing into.", | |
| parameters: { type: "object", properties: { degrees: { type: "number" } }, required: ["degrees"] }, | |
| }, | |
| { | |
| name: "pick", | |
| description: | |
| "Grasp an object (by name, or the one at a point from locate) and lift it 10 cm. method 'script' (the default) drives there first if it is out of reach, the arm reaching out as the base arrives, then grasps in one motion; method 'policy' uses the learned ACT policy (trained for objects on a table in front of an arm) on an object within reach. The arm is chosen automatically unless given.", | |
| parameters: { | |
| type: "object", | |
| properties: { | |
| object: { type: "string" }, | |
| at: AT, | |
| arm: { type: "string", enum: ["left", "right"] }, | |
| method: { type: "string", enum: ["script", "policy"] }, | |
| }, | |
| }, | |
| }, | |
| { | |
| name: "place", | |
| description: | |
| "Put down the object held in a gripper: into or onto another object (e.g. a bowl or plate, by name or at a point from locate) or a fixture (a counter or table: at a free spot an arm reaches; a container such as the sink or the trash can: let go over it) when 'on' is given, driving there if needed; otherwise at a spot given as forward/left in metres relative to the robot (or at, where no object is), on the surface it stands on.", | |
| parameters: { | |
| type: "object", | |
| properties: { | |
| arm: { type: "string", enum: ["left", "right"] }, | |
| on: { type: "string", description: "object or fixture to put it in or on" }, | |
| at: AT, | |
| forward_m: { type: "number" }, | |
| left_m: { type: "number" }, | |
| }, | |
| required: ["arm"], | |
| }, | |
| }, | |
| { | |
| name: "press", | |
| description: "Press a switch's button (the radio's power button), driving to it if needed: it switches the device on or off.", | |
| parameters: { type: "object", properties: { object: { type: "string", description: "the switch, e.g. radio" } }, required: ["object"] }, | |
| }, | |
| { | |
| name: "open", | |
| description: "Open a drawer or a door (the fridge's, the microwave's, the island's drawer): the robot drives to it, grasps the handle with a free arm, pulls it open and lets go; the microwave's door (it has no handle) it opens by pressing its door button, and the door pops open. The fridge's door opens to about 60 degrees, the microwave's about 20, a drawer about 30 cm. Things go in or come out of them only while they are open.", | |
| parameters: { type: "object", properties: { object: { type: "string", description: "the fixture, e.g. fridge, microwave, drawer" } }, required: ["object"] }, | |
| }, | |
| { | |
| name: "close", | |
| description: "Close a drawer or a door: the robot drives to it and pushes it shut with a closed gripper, against its handle (the microwave's door, which has none, on its face, and its magnet then holds it). Needs a free arm.", | |
| parameters: { type: "object", properties: { object: { type: "string", description: "the fixture, e.g. fridge, microwave, drawer" } }, required: ["object"] }, | |
| }, | |
| { | |
| name: "task", | |
| description: "The household task in progress (started from the Tasks tab): its instruction, each goal condition and whether it holds now, the score, and the time used and allowed.", | |
| parameters: { type: "object", properties: {} }, | |
| }, | |
| { | |
| name: "gripper", | |
| description: "Open or close one gripper.", | |
| parameters: { type: "object", properties: { arm: { type: "string", enum: ["left", "right"] }, open: { type: "boolean" } }, required: ["arm", "open"] }, | |
| }, | |
| { | |
| name: "move_arm", | |
| description: "Move a wrist to a point relative to the robot (forward/left/up in metres) with the gripper pitched down by pitch_deg (90 = pointing straight down).", | |
| parameters: { | |
| type: "object", | |
| properties: { | |
| arm: { type: "string", enum: ["left", "right"] }, | |
| forward_m: { type: "number" }, | |
| left_m: { type: "number" }, | |
| up_m: { type: "number" }, | |
| pitch_deg: { type: "number" }, | |
| }, | |
| required: ["arm", "forward_m", "left_m", "up_m"], | |
| }, | |
| }, | |
| { | |
| name: "home_arms", | |
| description: "Move both arms back to their resting pose (grippers keep their state).", | |
| parameters: { type: "object", properties: {} }, | |
| }, | |
| { | |
| name: "look_at", | |
| description: "Point the head camera at an object, or at a point [forward, left, up] (at) to look around.", | |
| parameters: { type: "object", properties: { object: { type: "string" }, at: AT } }, | |
| }, | |
| { | |
| name: "wait", | |
| description: "Wait a number of seconds of simulated time.", | |
| parameters: { type: "object", properties: { seconds: { type: "number" } }, required: ["seconds"] }, | |
| }, | |
| ]; | |
| /** | |
| * The page's further tools for an MCP client (through tools/mcp/server.mjs): what the panel's Scene and Tasks | |
| * tabs do, and a picture from any camera (it stands in for look). The in-page agent does without them. | |
| */ | |
| export const BRIDGE_SPECS = [ | |
| { | |
| name: "camera", | |
| description: | |
| "Take a picture and see it: from one of the robot's cameras (head, left_wrist, right_wrist; 4:3) or the page's main view (view: what the person watching the page sees). width in pixels, 512 unless given. locate maps points you see in a robot camera's last picture to positions.", | |
| parameters: { | |
| type: "object", | |
| properties: { camera: { type: "string", description: "head (the default), left_wrist, right_wrist or view" }, width: { type: "number" } }, | |
| }, | |
| }, | |
| { | |
| name: "load_scene", | |
| description: "Load a scene by its id (status lists them, e.g. kitchen or tabletop) with XLeRobot at its start. Ends the task in progress.", | |
| parameters: { type: "object", properties: { scene: { type: "string" } }, required: ["scene"] }, | |
| }, | |
| { | |
| name: "reset_scene", | |
| description: "Put the scene back as it was loaded: the objects, the robot and the fixtures. Ends the task in progress.", | |
| parameters: { type: "object", properties: {} }, | |
| }, | |
| { | |
| name: "start_task", | |
| description: | |
| "Set up a household task (the kitchen has them; status lists them) as the Tasks tab does: its instance (0-99, 0 unless given) decides where its objects and the robot start. Returns the instruction and the goal conditions; do the task, then check with task.", | |
| parameters: { type: "object", properties: { task: { type: "string", description: "task id or title" }, instance: { type: "number" } }, required: ["task"] }, | |
| }, | |
| ]; | |
| /** The robot, for a model that drives it. */ | |
| export const ROBOT_INTRO = `You control XLeRobot, a dual-arm mobile robot, in a MuJoCo physics simulation running in the user's browser. | |
| The robot has a two-wheel base (it can drive forward/backward and turn in place, not sideways), two SO-101 arms with grippers (left and right), and a pan-tilt head camera. | |
| Positions are relative to the robot: forward, left and up in metres from its base. Turns are in degrees, positive to the left.`; | |
| /** How to work with the tools: the in-page agent's system prompt (agent.js) and the MCP server's instructions. */ | |
| export const TOOL_GUIDE = `How to work: | |
| - Start with observe to see the objects and what is in reach. Call it again after moving. | |
| - An object must be in reach before pick. If it is not, call go_to with the object; furniture can stop the robot, then try turning or driving a little and go_to again. | |
| - pick lifts the object 10 cm. Use method "policy" only when the user asks for the learned policy; otherwise "script". | |
| - To put something in or on another object (a bowl, a plate), use place with "on". | |
| - In the kitchen, observe also lists fixtures: surfaces (the kitchen island, the dining table, the pantry shelf), containers (the sink, the trash can, the fridge, the microwave, the island's drawer) and switches (the radio). place "on" a fixture puts the object on a free spot of a surface, lets it go into a container, or stands it on the fridge's shelf; press switches the radio on or off. pick and place drive where they need to. | |
| - The fridge, the microwave and the drawer open and close (observe says which are open): open and close them by their handles, with a free arm (the microwave has none: it opens by its door button and closes when its door is pushed shut, which its magnet then holds). Into the fridge, carry things with the right arm (pick's "arm"): it reaches in past the open door. Something goes into or comes out of them only while they are open, so open first (before picking up what goes in, to keep an arm free), and close them after if the task says so. | |
| - Each arm holds one object, so the robot can carry two: when two objects go to the same place (or near each other), pick one, then the other with the other arm (pick's "arm"), and then place each; one trip instead of two. | |
| - locate finds objects in a camera picture with Gemini 4 Hydrogen (when a Gemini API key is set): say what to look for, and each match comes with at, its position [forward, left, up]; pick, place, go_to and look_at take that at in place of a name. When observe leaves the objects out (camera-only perception), locate is how to find them: look_at or turn first when what you want is out of view, and locate again from nearer when a point is off. | |
| - When the user started a household task (Tasks tab), the task tool tells its goal conditions and which hold; work through the ones that do not, and check with task at the end. | |
| - The gripper opens to about 6 cm; wider objects cannot be picked up. | |
| - If a tool fails, read its message and adapt; do not repeat the same call more than twice.`; | |