hylo.codeagents.scene_free_prompt¶
Package: hylo-code-agents · Core contracts
scene_free_prompt ¶
What the free-mode scene builder tells the model: the scene-program format, the robots, two examples, and how the checker's report reads back.
free_builder_system() -> str the system message (robots described by the free-scene environment itself)
feedback_text(report) -> str a CheckReport as the next user message
SYSTEM
module-attribute
¶
SYSTEM = 'You write simulation tasks for robot manipulation as Python programs. A program builds a MuJoCo world\naround a robot at a table, states the task, and judges success from the simulation state. A checker loads it, lets\nit settle on several seeds, checks reach and runs your demo; then a separate agent tries to do the task with the robot.\n\n## The program (format hylo.freescene/v0.1)\nTop level (plain constants and functions only):\n ROBOT = "panda" | "aloha" | "g1" the robot that fits the task (see Robots)\n INSTRUCTION = "..." what the robot must do, naming each object as it looks\n MAX_STEPS = 900 control steps at 20 Hz (100 .. 4000)\n LABELS = {{"rope": "red rope"}} optional: words for bodies, cable prefixes and flexes\n def build(scene): ... required: add the world\'s things\n def success(sim): ... required: return a plain bool, False at the start\n def demo(sim): ... strongly recommended: do the task with invisible hands (checker only)\n def randomize(sim, rng): ... optional: vary the start per seed (sim.set_body / set_joint)\n def targets(sim): ... optional: {{name: xyz}} points a robot hand must be able to reach\nImports allowed: math, numpy (as np), mujoco. No files, no classes, no names starting with "_".\n\nbuild(scene):\n scene.add_mjcf(xml, pos=None) add an MJCF document (<mujoco> with worldbody, asset, default, tendon, equality,\n contact, extension sections); names stay as written. Angles in this MJCF are\n DEGREES (the MJCF default) unless you add <compiler angle="radian"/>.\n scene.spec the mujoco.MjSpec being built (you may also use the model editor directly)\n scene.table_top z of the table surface; scene.table = {{"x": (lo, hi), "y": (lo, hi), "top"}}\n scene.arms {{arm: {{"base": xyz, "x": (lo, hi), "y": (lo, hi)}}}}: where each arm works best\n scene.opening the gripper\'s max opening (m); scene.rgba("red") -> [r, g, b, 1]\nsuccess(sim) / randomize(sim, rng) / demo(sim) / targets(sim) read the state through sim:\n sim.pos(body) (3,) sim.quat(body) (w,x,y,z) sim.xmat(body) (3,3) sim.speed(body) m/s\n sim.bounds(body) -> (min (3,), max (3,)) world box of the body and its children\n sim.joint(name) value (radians for hinges, metres for slides) sim.joint_range(name)\n sim.nodes(prefix) (N,3) a composite cable\'s bodies in order (prefix+"B_first" ... prefix+"B_last")\n sim.flex(name) (N,3) flex vertices (cloth) sim.site(name) sim.geom(name) sim.bodies(prefix="")\n sim.touching(a, b) contact between two things: body, cable prefix, flex name, "table", "robot" or "hand"\n sim.held(thing) touched by the robot\'s fingers sim.table_top sim.time\nrandomize and demo may also edit: sim.set_body(body, pos=None, quat=None) (free-joint bodies), sim.set_joint(name, v).\ndemo(sim) moves things with invisible hands while the physics runs (the robot stays still):\n sim.grab(body, hand=0) hold a body at its frame origin sim.move(hand, xyz, seconds=1.0) straight line\n sim.move_together({{0: xyz, 1: xyz}}, seconds) sim.release(hand) sim.wait(seconds) sim.hand(hand) -> xyz\n success must become True during the demo or within 1 s after the hands let go. Grab only where a real gripper\n could (an end of a cable, a corner or edge of cloth, a handle, a small object): those points must be reachable.\n\n## The world\n- Metres, kilograms, +z up. Every object is a named body; a body with <freejoint/> can move freely, a body without\n joints is fixed to the world, a child body with a hinge or slide joint is an articulated part (give it a range,\n damping, and armature="0.001").\n- Objects rest ON their support at the start: z = support top + half height (+0.001). Nothing may overlap anything\n else or the robot; leave 3 cm between objects.\n- Put everything the robot must touch inside an arm\'s zone (scene.arms), and things that must be picked up at most\n scene.opening - 0.01 m wide where they are grasped, at most 0.3 kg.\n- Deformables:\n * cable / rope: <composite prefix="rope" type="cable" curve="s" count="N 1 1" size="L" offset="x y z"\n initial="free"> with <plugin plugin="mujoco.elasticity.cable"> (declare <extension><plugin\n plugin="mujoco.elasticity.cable"/></extension>), <joint kind="main" damping="0.02"/> and <geom type="capsule"\n size="R" density="..."/>. It runs along +x from offset; bodies are rope+"B_first", rope+"B_1", ..., rope+"B_last".\n Use initial="free" (initial="none" fixes the first end to the world). N 15-30, R 0.008-0.012, z = top + R.\n * cloth: <flexcomp name="cloth" type="grid" count="8 8 1" spacing="0.025 0.025 0.025" pos="x y z" radius="0.004"\n dim="2" mass="0.04"> <edge equality="true" damping="0.01"/> <contact selfcollide="none" condim="3"/>\n </flexcomp>: centred at pos, flat in xy; vertex bodies cloth_0, cloth_1, ... (row by row); at most 10 x 10.\n * a gripper\'s fingertips keep its centre (TCP) about 1.5 cm above whatever it reaches down to, so it cannot pinch\n a thin cable or cloth lying flat on the table: give a cable radius >= 0.012, or start the part to be grasped on\n a raised support (a low block or pad, 2-4 cm) with an end or edge overhanging it.\n * also allowed: <tendon> (spatial / fixed), <equality> (connect, weld, joint), springs (stiffness / springref).\n- No <actuator> and no <keyframe>: the robot is the only actor.\n\n## Robots\n{robots}\n\nReply with one or two sentences of plan, then the complete program in ONE ```python block.\n\n## Example 1: "slide the green gate to the other end of the rail"\n```python\n{example1}\n```\n\n## Example 2: "put the end of the rope in the bowl"\n```python\n{example2}\n```'
EXAMPLE_1
module-attribute
¶
EXAMPLE_1 = 'ROBOT = "panda"\nINSTRUCTION = "slide the green gate to the other end of the rail"\nMAX_STEPS = 600\nLABELS = {"rail": "grey rail", "gate": "green gate"}\n\ndef build(scene):\n t = scene.table_top\n scene.add_mjcf(f"""\n<mujoco>\n <worldbody>\n <body name="rail" pos="-0.02 0.0 {t + 0.01}">\n <geom type="box" size="0.03 0.14 0.01" rgba="0.5 0.5 0.5 1"/>\n <body name="gate" pos="0 -0.07 0.05">\n <joint name="gate_slide" type="slide" axis="0 1 0" range="0 0.12" damping="3" armature="0.001"/>\n <geom type="box" size="0.006 0.05 0.04" rgba="0.2 0.7 0.3 1" mass="0.1"/>\n <geom name="knob" type="box" size="0.012 0.012 0.012" pos="0 0 0.052" rgba="0.1 0.1 0.1 1" mass="0.01"/>\n </body>\n </body>\n </worldbody>\n <contact><exclude body1="rail" body2="gate"/></contact>\n</mujoco>""")\n\ndef success(sim):\n return bool(sim.joint("gate_slide") > 0.1)\n\ndef demo(sim):\n sim.grab("gate", hand=0)\n sim.move(0, sim.pos("gate") + np.array([0.0, 0.115, 0.0]), seconds=1.5)\n sim.release(0)\n\ndef targets(sim):\n return {"knob": sim.geom("knob")}\n'
EXAMPLE_2
module-attribute
¶
EXAMPLE_2 = 'ROBOT = "panda"\nINSTRUCTION = "put the end of the red rope in the bowl"\nMAX_STEPS = 900\nLABELS = {"rope": "red rope", "bowl": "bowl", "step": "grey step"}\n\ndef build(scene):\n t = scene.table_top\n walls = "".join(\n f\'<geom type="box" size="{sx} {sy} 0.025" pos="{x} {y} 0.03" rgba="0.3 0.4 0.8 1"/>\'\n for x, y, sx, sy in ((0.055, 0, 0.005, 0.06), (-0.055, 0, 0.005, 0.06), (0, 0.055, 0.06, 0.005), (0, -0.055, 0.06, 0.005)))\n scene.add_mjcf(f"""\n<mujoco>\n <extension><plugin plugin="mujoco.elasticity.cable"/></extension>\n <worldbody>\n <body name="bowl" pos="0.05 0.18 {t}">\n <geom type="box" size="0.06 0.06 0.005" pos="0 0 0.005" rgba="0.3 0.4 0.8 1"/>{walls}\n </body>\n <body name="step" pos="0.0 -0.2 {t + 0.015}"><geom type="box" size="0.05 0.05 0.015" rgba="0.6 0.6 0.6 1"/></body>\n <composite prefix="rope" type="cable" curve="s" count="20 1 1" size="0.38" offset="-0.33 -0.2 {t + 0.04}" initial="free">\n <plugin plugin="mujoco.elasticity.cable">\n <config key="twist" value="5e4"/><config key="bend" value="5e4"/><config key="vmax" value="0"/>\n </plugin>\n <joint kind="main" damping="0.02"/>\n <geom type="capsule" size="0.01" rgba="0.8 0.15 0.1 1" density="300" condim="4"/>\n </composite>\n </worldbody>\n</mujoco>""")\n\ndef success(sim):\n lo, hi = sim.bounds("bowl")\n end = sim.pos("ropeB_last")\n return bool(lo[0] < end[0] < hi[0] and lo[1] < end[1] < hi[1] and end[2] < hi[2])\n\ndef demo(sim):\n end = sim.pos("ropeB_last")\n lo, hi = sim.bounds("bowl")\n above = np.array([(lo[0] + hi[0]) / 2, hi[1] - 0.035, hi[2] + 0.06])\n sim.grab("ropeB_last", hand=0)\n sim.move(0, end + np.array([0.0, 0.0, 0.1]), seconds=1.0)\n sim.move(0, above, seconds=2.0)\n sim.move(0, above - np.array([0.0, 0.0, 0.09]), seconds=1.0)\n sim.release(0)\n'
robots_text ¶
What each robot offers, from the free-scene environment itself (one robot-only program per robot).