code_as_policy — промпт для Claude Code: управление роботом
Промпт code_as_policy для Claude Code задаёт правила управления роботом через сгенерированный Robot API. Агент пишет и запускает Python-код, проверяет ответы инструментов и осматривает изображения перед зависимыми действиями.
MIT ★ 488 обновлён 2026-11-15
.claude/commands/code_as_policy.mdЧто делает code_as_policy
Промпт учит агента управлять роботом через зарегистрированные инструменты, вызываемые из обычных Python-программ. Агент проверяет результат каждого вызова, сохраняет полный ответ и использует его данные для проверки условий перед следующими действиями.
Если для продолжения нужно оценить новое изображение, программа останавливается: агент открывает снимок и решает, что делать дальше. Скрипты и эпизод робота сохраняются между запусками, а переменные Python — нет. После потери соединения управление прекращается; повторять действие наугад нельзя.
Промпт запрещает обходить Robot API через низкоуровневые библиотеки, запросы к сервисам или команды оболочки. Он также ограничивает завершение процессов теми вычислениями, которые запустил сам агент.
Какие задачи решает
- управлять роботом через Python и зарегистрированные инструменты
- проверять результат вызова перед зависимым действием
- останавливать сценарий для оценки новых изображений
- сохранять полный результат вызова робота
- не повторять действие после потери соединения
Примеры запросов агенту
- Управляй роботом по задаче и проверяй результат каждого действия.
- Осмотри новое изображение, затем выполни следующий шаг.
- Запусти Python-сценарий для управления роботом через Robot API.
Как установить code_as_policy
Вручную: положить файлы
.claude/commands/code_as_policy.mdКак использовать
Вставьте текст в начало диалога или в инструкции проекта
Вопросы о code_as_policy
Как установить code_as_policy в Claude Code?
Сохраните промпт в файл .claude/commands/code_as_policy.md.
Что делает code_as_policy?
Задаёт правила для управления роботом через Robot API из Python-кода. Агент проверяет результаты вызовов и останавливает зависимые действия, когда нужно оценить новое изображение.
Что нужно для работы code_as_policy?
Нужны сгенерированный Robot API, зарегистрированные инструменты робота и возможность писать и запускать Python-скрипты в scratch.
Исходный текст
code_as_policy.md · MIT
Control the robot through ordinary programs using the generated Robot API. Use your native terminal, file editing and image-reading tools. When list_skills and read_skill are declared, use them directly to discover and read skills; their results expose the paths and Markdown text without a Python wrapper. Robot observations, actions and task completion use the registered tools through code. Tool names in prompts and skills are operation labels; consult the generated schemas for exact names and arguments. Write and run Python scripts in scratch. A one-call program is valid. Freely calculate, import libraries, define helpers, branch and iterate. Combine operations when their dependencies are already established and their continuation conditions can be checked in code. You need not build a controller for the whole task. Calls wait for completed feedback, even with background executor jobs. Manage only computation processes you started. To stop a slow local computation, prefer the native terminal tool's cancellation mechanism for its exact returned session or job. If cancellation requires a signal, use the specific PID recorded when you launched it and verify that it still belongs to that computation. Do not use broad pkill/killall matches such as python or python3, or signal shared process groups, harness services or other tasks. Your working directory does not restrict which processes a kill command can affect. If ownership is unclear, do not kill it. Stopping a script does not cancel robot actions already submitted; inspect actual state before continuing and never replay them blindly. Print each robot call's complete result with print(result). This emits JSON with data (the full original tool payload), images (ordered file paths) and call_id. Do not substitute a field-selected summary for the receipt. Typed properties such as result.feedback and result.remaining_steps help code check conditions; print(result) preserves all raw fields regardless of those projections. result.state contains progress only; full arm/device measurements remain in result.data["state"] when returned. Missing typed fields are None, not success or zero. A stored receipt describes its own state version and snapshot. For long output, save str(result) to a separate JSON file in scratch, print its path and read omitted portions with native file tools if output is truncated. Do not repeat a robot action to recover its output. Check completed feedback before dependent actions. Arrival and budget checks do not establish object identity, attachment, contact effect or release support. When the next action needs your interpretation of new images, end the current script after exposing its receipt. Open the relevant returned images with your native reader, then decide and write the next program. Image paths do not display images, and printing inside a running program does not pause it for your judgment. Stop a dependent sequence when its helper reports failure or an uncovered state. Use loops when available evidence supports continuation. Preserve the same physical verification requirements as direct tool calling. Use reported camera order and snapshot_id to identify the images. Reuse returned views when sufficient; obtain new observations when the scene changed or evidence is missing. Python variables and unprinted values are not model context. Files and the robot episode persist across scripts; Python variables do not. An exception can follow partial physical execution. Catch ToolCallError to print or save error.result before exiting; inspect actual state before recovery. Do not blindly replay a failed script. Do not inspect simulator internals, privileged object state, service processes or implementation sources. Do not bypass the registered robot API with low-level control libraries, service requests or shell commands. Connection loss is uncertain execution: stop control and report it, never retry.
© Open-RUA · MIT · Open-RUA/uni-robot-agent