Skip to content

hylo.codeagents.prompt

Package: hylo-code-agents · Core contracts

prompt

What code-writing models are told: the robot, the toolkit's API, the rules, and the feedback after each block.

Task-agnostic: the robot comes from RobotSpec, the API from the toolkit itself (hylo.manip.api_reference, else the Tools signatures and docstrings), the task from the instruction. No task names, no success signal.

FENCE module-attribute

FENCE = re.compile('```(?:python|py)?[ \\t]*\\n(.*?)```', re.S | re.I)

RULES module-attribute

RULES = "How to work:\n- Reply with a short thought, then exactly ONE fenced block: ```python ... ```. It runs as soon as you send it; you\n  see what it printed, any error, and the robot's status, then you write the next block. There are no tools or\n  functions to call through the chat: write the code as text in your reply, inside the fence.\n- Variables, functions and imports persist between blocks. Preloaded: `robot` (the toolkit), `np` (numpy), `math`.\n  The only imports allowed are math and numpy. No files, no network, no class definitions, no names that start\n  with an underscore.\n- Each block may compute for at most {block_s:g} s; time the robot spends moving is not counted.\n- Every turn is one model call, which can be slow: when you are confident, do several steps in one block (perceive,\n  plan, run a motion, check it) and print what you need to verify.\n- `robot.run(plan)` is the only call that moves the robot: it returns when the motion is done. The simulation is\n  paused while you think, so take the time you need.\n- print() what you need to see: values you do not print are not shown to you.{vision}"

VISION module-attribute

VISION = '\n- `robot.show(view_or_image, note)` attaches an image you will see with the next feedback.'

NO_VISION module-attribute

NO_VISION = '\n- You receive text only: images passed to robot.show are not shown to you.'

extract_code

extract_code(text: str) -> tuple[str | None, int]

The first fenced Python block of a reply, and how many blocks there were.

compact

compact(value: Any, limit: int = 1500) -> str

A short JSON-ish rendering of a status dict (numbers rounded, arrays as lists).

robot_description

robot_description(robot: RobotSpec | None, env: EnvSpec | None) -> str

api_reference

api_reference(tools: Any) -> str

The toolkit's reference, after what the toolkit says about itself first (tools.extra_reference(), e.g. privileged verbs).

toolkit_reference

toolkit_reference(tools: Any) -> str

The toolkit's own reference (hylo.manip.api_reference) or, until it exists, signatures and docstrings.

code_llm_system

code_llm_system(*, robot: str, api: str, block_s: float, vision: bool, skills: str = '', demonstration: str | None = None) -> str

budget_text

budget_text(budget: Mapping[str, Any]) -> str

task_message

task_message(instruction: str, status: Mapping[str, Any], budget: Mapping[str, Any], scene: str = '') -> str

scene_preview

scene_preview(tools: Any, vision: bool) -> tuple[str, list[Any]]

What the first message says about the scene before any block ran: the segment labels the environment gives (if any) and, for a vision model, the cameras side by side. Saves the model a turn spent only looking.

feedback

feedback(*, code: str | None, n_blocks: int, output: str, error: str | None, status: Mapping[str, Any] | None, images: Sequence[Mapping[str, Any]], vision: bool, remaining: Mapping[str, Any], seconds: float = 0.0) -> str