hylo.codeagents.replay¶
Package: hylo-code-agents · Core contracts
replay ¶
Replay to sim (RFC-0006 part 8): a recorded episode -> tracked objects and hand -> MuJoCo scene -> replay -> checks.
hylo replay SOURCE --out DIR [--profile libero|droid|video] [--camera KEY] [--agent] [--model SPEC]
[--labels "red block,plate"] [--step K] [--max-frames N] [--stub] [--no-video]
[--hand g1|allegro|<name>]
SOURCE: a saved recording folder, panda:TASK:SEED (records one of our episodes with the privileged oracle, ground truth kept for evaluation), hf:REPO:EPISODE (a LeRobot dataset episode; --camera names the image key), or a video file (a human hand demonstration). See replay_data.py.
Steps (each a method of ReplayPipeline, callable on its own and in this order by run()):
labels a vision chat model names the objects in the first frame (fallback: the instruction's noun phrases)
segment SAM 3 masks for those labels (best mask per label, duplicates and table-sized masks dropped)
lift depth (recorded, or MoGe-2 per frame rescaled to frame 0), the camera in a +z-up frame (recorded pose,
or GeoCalib gravity refined by the RANSAC table plane), the table plane
hands (human videos) hand keypoints -> metric scale from the hand's size -> parallel-gripper TCP and opening;
with --hand also the keypoints in the world retargeted onto a multi-finger robot hand (hylo.manip.retarget:
finger joints per frame and the palm pose; the hand's side follows the detected handedness)
track object poses through the video (mask propagation + ICP on the per-frame depth)
register (robot videos without a camera pose) scale, yaw and offset to the robot frame from the carried object's
path and the TCP path; IK of the TCP path on the Panda (base pose fitted when unknown)
objects per object: mesh (mesh tool) -> convex parts (convex tool) + a support part down to the table
grasps (--hand) each recorded grasp refined with the dexterous grasp planner on the object's convex parts at
the grasp moment, the plan nearest the retargeted hand chosen; the palm path is bent onto it (pre-pose,
straight approach, then the hand-relative offset kept while carrying), the fingers open before it,
close to the plan's squeeze command and hold until the release
scene MJCF with the table, the objects (moving ones free, others fixed), the camera and the Panda, a
free-floating gripper or (--hand) a free-floating multi-finger hand
replay kinematic replay (recorded motion written into qpos) and physics replay (joint targets / TCP path,
hand closed between grasp and release; objects move only by contact)
checks pose error per object over time (sim vs tracked, and vs ground truth when known), contact events
(grasp, lift, place) matched to the recording, final-state success, mesh size error (ground truth)
video side-by-side MP4, recording | simulation, rendered with the render tool
With --agent a chat model drives the same steps from a sandboxed Python session (the code-agents sandbox and turn loop): it sees each step's summary and overlay images, may change labels, masks, tracking mode or thresholds and re-run steps, and calls finish() when the checks are done. Without it the steps run in order with defaults. Writes DIR/report.json, DIR/scene.xml (+ meshes/), DIR/tracks.npz, DIR/replay.mp4 and DIR/overlays/*.png.
AGENT_SYSTEM
module-attribute
¶
AGENT_SYSTEM = 'You turn a recorded manipulation video into a physics simulation and check it. You work in a\nPython session (only math and numpy can be imported) through the object `replay`, whose methods run the workflow\'s\nsteps and return short summaries (dicts). Images (masks, tracked models) are attached to your next message.\n\nSteps, normally in this order:\n replay.info() the recording: frames, fps, task text, what the source provides\n replay.labels(names=None) propose object labels from the first frame (or set them: a list of str)\n replay.segment(labels=None, keep=None) masks for the labels in frame 0; keep=[indices] keeps some of them\n replay.lift() depth, camera frame, table plane\n replay.hands() human videos only: hand -> gripper (call after lift)\n replay.track(mode="yaw", gate=0.04) object poses through the video; mode "xyz", "yaw" or "full"\n replay.register() camera to robot frame, IK of the robot path (when needed)\n replay.events() grasp / lift / release / place from the gripper and object motion\n replay.objects() meshes and convex collision parts\n replay.grasps() with a multi-finger hand (--hand): plan grasps, bend the hand\'s motion\n replay.scene() the MuJoCo scene\n replay.replay() kinematic and physics replay\n replay.checks() pose errors, matched contact events, final-state success\n replay.video() the side-by-side video\n finish(note) end the session with a one-paragraph note on what reproduced\n\nCheck each result before moving on: are the masks on the objects the task is about (look at the image)? Did a\ntracked object get lost for many frames or jump? Did registration use enough pairs with a small rmse? If a check\nfails, change what you control (labels, kept masks, tracking mode or gate) and run the step again; later steps must\nthen be re-run too. Do not invent results: report what the checks say. Write one ```python block per reply, with a\nsentence of reasoning before it. Keep blocks short and print what you need.'
DEFAULT_MODEL
module-attribute
¶
DEFAULT_MODEL: dict[str, Any] = {'backend': 'ollama', 'model': 'qwen3.5:35b-a3b', 'vision': True, 'reasoning_effort': 'none', 'max_tokens': 3000, 'timeout_s': 900}
ReplayAPI ¶
What the model's programs see as replay (every method returns a JSON-ready summary).
ReplayConfig
dataclass
¶
ReplayConfig(n_labels: int = 4, track_mode: str = 'yaw', gate: float = 0.04, static_eps: float = 0.015, mass: float = 0.08, final_tol: float = 0.03, event_tol_s: float = 1.0, video_height: int = 360, render_scale: float = 2.0, max_mask_frac: float = 0.25, min_scale_path: float = 0.12, mesh_min_pixels: int = 1500, hand: str | None = None, hand_kp_scale: float = 1.0, refine_grasps: bool = True, grasp_ramp_s: float = 0.6)
ReplayPipeline ¶
ReplayPipeline(rec: Recording, out: str | Path, tools: Any, *, model: Any = None, config: ReplayConfig | None = None, log: Callable[[str], None] | None = None)
One replay: the recording, the tools, the chat model (labels; optional) and the state of every step.
report
instance-attribute
¶
report: dict[str, Any] = {'recording': {'name': rec.name, 'frames': rec.T, 'fps': round(rec.fps, 3), 'instruction': rec.instruction, 'agent': rec.agent, 'meta': {k: v for k, v in rec.meta.items()}}, 'steps': {}, 'timing': {}}
tcp
instance-attribute
¶
segment ¶
Masks for the labels in frame 0: the best-scoring mask per label; overlapping or table-sized ones dropped.
keep selects masks by index from the previous result instead of running the segmenter again.
hands ¶
Human video: hand keypoints -> scale from the hand's metric size -> gripper TCP and opening in the world.
register ¶
Robot videos without a camera pose: similarity from F to the robot frame (carried object vs TCP).
refine_grasps ¶
Bend the retargeted hand motion onto planned grasps of the objects the recording grasps.
run_agent ¶
run_agent(pipe: 'ReplayPipeline', model: Any, *, turns: int = 16, block_timeout_s: float = 120.0, log: Callable[[str], None] | None = None) -> dict[str, Any]
A chat model drives the pipeline from the sandbox; turns go to DIR/agent_turns.jsonl.
replay_command ¶
replay to sim: a recorded episode -> MuJoCo scene -> kinematic and physics replay -> checks and video