Skip to content

sim/mujoco: MjSpec stage 6 - agent-authored raw MJCF (replace_scene_mjcf / patch_scene_mjcf) (#121) #125

@cagataycali

Description

@cagataycali

Part of #121. See IDEA.md stage 6.

Goal

The new capability unlocked by the refactor: let agents write MJCF elements that SimObject can't express (<tendon>, <equality>, <pair>, custom friction/solref/solimp, sites, flex bodies, hfields, skins, plugins, etc).

API

Two new @tool-exposed actions:

def replace_scene_mjcf(world, xml: str):
    \"\"\"Atomically swap the whole scene to agent-written MJCF.
    Validated by actually compiling it. Raises on failure with the
    MuJoCo compiler error verbatim.\"\"\"
    new_spec = mujoco.MjSpec.from_string(xml)
    new_model = new_spec.compile()  # raises if invalid
    ...

def patch_scene_mjcf(world, ops: list[dict]):
    \"\"\"Apply a list of structured ops to the live spec.
    ops = [
      {'op': 'add_body', 'parent': 'world', 'name': 'foo', 'pos': [...]},
      {'op': 'add_geom', 'body': 'foo', 'type': 'box', ...},
      {'op': 'set_attr', 'path': 'body/foo', 'attr': 'pos', 'value': [1,0,0]},
      {'op': 'delete',   'path': 'body/foo'},
    ]\"\"\"

Acceptance

  • Both tool actions in tool_spec.json enum.
  • Wrapped spec.compile() in try/except with clear error-shape parity with the rest of the tool surface.
  • Integration test: agent writes a scene with a <tendon> element, confirms it compiles and simulates.
  • Documented in the main tool docstring as an 'escape hatch' from the SimObject vocabulary.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions