Skip to content

hylo.codeagents.scene_free

Package: hylo-code-agents · Core contracts

scene_free

Free-form scene building (RFC-0006 part 8, free mode): task text -> a scene program -> checked -> solved.

hylo scene build --free "lift the cable by both ends" --out runs/scenes_free/cable [--model SPEC] [--attempts 6]
hylo scene check runs/scenes_free/cable            (a directory with scene.py, or the .py itself)
hylo scene solve runs/scenes_free/cable [--model SPEC] [--turns 30]

The fixed format (hylo.scene/v0.1, scenes.py) describes a scene as data: primitives on a Panda's table and a predicate from a small language. Free mode lets the model write the task as a Python program instead (hylo.freescene/v0.1, run by the env mujoco.free_scene): it chooses the robot (Panda, the two ALOHA arms or the G1 humanoid), builds the world with MuJoCo's model editor or MJCF (cables, cloth, tendons, equality constraints, hinged and sliding parts: anything MuJoCo compiles, except actuators and keyframes), and writes success(sim) over the simulation state. Optional demo(sim) proves the task can be done with invisible hands; the checker runs it.

build: the code agents' turn loop (turns.CodeLoop) with a scene-program runner in place of the robot sandbox. Each turn the model replies with one ```python block holding the whole program; the runner validates it with a wider allow-list than robot programs (scene programs may import mujoco and use the model editor; still no files, no underscores, no exec), saves it, and runs the free checker (scene_free_check.py) under a time limit. The checker's numbered problems are what the model reads next, until the program passes or the attempt budget is spent. Writes DIR/scene.py (the last attempt), DIR/attempts/NN.py and DIR/build.json (per attempt: problems, tokens, latency).

solve: code.llm on mujoco.free_scene with privileged state: PrivilegedFreeTools adds robot.scene() (rigid bodies, cable nodes, flex vertices, joint values and sites from the simulator), robot.points(name), robot.top_down(xyz) and robot.scene_table(). Two-arm robots use the toolkit's multi-arm verbs (arm=..., robot.run({arm: plan}, sync=True)). Writes DIR/solve/trace, DIR/solve/turns.jsonl, DIR/solve.json and DIR/front.mp4, like the fixed-format solve (scene_episode.run_recorded_episode). agent= runs another agent instead, e.g. code.program with a scripted solution (written to DIR/.json and DIR/.mp4).

Modules: scene_free_check (the program allow-list and the checker), scene_free_prompt (what the model is told), scene_free_tools (the privileged toolkit); this file only orchestrates.

SceneProgramRunner

SceneProgramRunner(out: Path, checker: FreeSceneChecker)

What CodeLoop runs each turn in free mode: validate the block as a scene program, save it, check it. Duck-types the Sandbox's run(); the last CheckReport stays in report.

k instance-attribute

k = 0

report instance-attribute

report: Any = None

problems instance-attribute

problems: list[Any] = []

run

run(code: str) -> BlockResult

FreeSceneBuilder

FreeSceneBuilder(model: str | Mapping[str, Any] | ChatModel | None = None, *, attempts: int = 6, seeds: Sequence[int] = (0, 1, 2), reply_tokens: int | None = None, timeout_s: float = 600.0, log: Callable[[str], None] | None = None)

A chat model writes a scene program; the free checker's problems go back to it until it passes.

model instance-attribute

model = build_chat(model_spec)

say instance-attribute

say = log or (lambda msg: None)

build

build(task: str, out_dir: str | Path) -> dict[str, Any]

solve_free_scene

solve_free_scene(scene_dir: str | Path, model: str | Mapping[str, Any] | ChatModel | None = None, *, turns: int = 30, seed: int = 0, block_timeout_s: float = 120.0, reply_tokens: int | None = None, cameras: Sequence[str] | None = None, video: bool = True, max_cost_usd: float | None = None, act_wait_s: float = 4 * 3600.0, agent: Any = None, out_name: str = 'solve', log: Callable[[str], None] | None = None) -> dict[str, Any]

code.llm with privileged state on DIR/scene.py (or agent, e.g. code.program with a scripted solution); returns, and writes to DIR/.json, the outcome. cameras: None for the robot's own cameras.

is_free_scene

is_free_scene(path: str | Path) -> bool

A scene program (scene.py, or a directory holding one and no scene.json).