From ca88a1e7525e8e7fbdfb7e1a6048c73f49548483 Mon Sep 17 00:00:00 2001 From: rsasaki0109 Date: Fri, 5 Jun 2026 05:47:10 +0900 Subject: [PATCH] Pyodide Phase 3: edit the agent's brain in the browser and re-run MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add an "Agent brain" code editor to the pick_and_retry scenario. It is pre-filled with the real PickAndRetryAgent source (fetched via inspect.getsource so it can never drift from the file). Editing it and clicking "Run edited agent" execs the user's class in Pyodide and runs it against the real Tabletop2D via the example's own run_agent() — the same loop the CLI uses, so there is no second loop to drift. Syntax/runtime errors surface inline. - examples/manipulation/01_pick_and_retry.py: extract run_agent(agent, ...) and have run() delegate to it. run_agent reads belief attributes defensively, so a custom agent that changes or drops them still runs and serializes. - docs/playground.{html,js,css}: editor panel (shown for pick_and_retry only), "Run edited agent" / "Reset code" buttons, inline error status. USER_SRC is injected via pyodide.globals to avoid string-escaping; the source-fetch driver registers the module in sys.modules so inspect.getsource works; the editable header re-adds `from __future__ import annotations` + typing.Any so the class execs standalone. - tests/test_playground_trace.py: run_agent tolerates a custom (belief-less) agent and still produces valid, plain-JSON config. The edited code runs entirely client-side (Pyodide is a WASM sandbox — no more privileged than a local REPL). Verified the exact drivers in an unpacked-bundle sim: default source reproduces seed=3 (4 steps, retries=2); removing the first offset grabs the belief mean immediately (2 steps, retries=0); malformed code raises a caught error. Full suite green (122 tests). Browser check still pending. Co-Authored-By: Claude Opus 4.8 (1M context) --- docs/playground.css | 49 ++++++++ docs/playground.html | 11 ++ docs/playground.js | 126 +++++++++++++++++++++ docs/pyodide/pir_bundle.zip | Bin 31786 -> 32024 bytes docs/pyodide_playground_strategy.md | 32 ++++-- examples/manipulation/01_pick_and_retry.py | 29 +++-- tests/test_playground_trace.py | 61 ++++++++-- 7 files changed, 285 insertions(+), 23 deletions(-) diff --git a/docs/playground.css b/docs/playground.css index e158b0b..15a6093 100644 --- a/docs/playground.css +++ b/docs/playground.css @@ -149,6 +149,55 @@ button:disabled { color: #b5482f; } +.code-panel { + border: 1px solid #d7dcd6; + border-radius: 10px; + margin-top: 14px; + overflow: hidden; +} + +.code-head { + align-items: center; + background: #eef1ec; + display: flex; + flex-wrap: wrap; + gap: 8px; + justify-content: space-between; + padding: 8px 12px; +} + +.code-head span { + color: var(--ink-soft, #5a6b67); + font-size: 0.82rem; +} + +.code-head code { + background: #dfe4dd; + border-radius: 3px; + padding: 0 3px; +} + +.code-actions { + display: flex; + gap: 8px; +} + +.code-cell { + background: #0f1419; + border: 0; + box-sizing: border-box; + color: #d6deeb; + display: block; + font-family: ui-monospace, SFMono-Regular, Menlo, monospace; + font-size: 0.8rem; + line-height: 1.45; + padding: 12px; + resize: vertical; + tab-size: 4; + white-space: pre; + width: 100%; +} + .status-strip { display: grid; gap: 10px; diff --git a/docs/playground.html b/docs/playground.html index f4027b4..0d3a6fa 100644 --- a/docs/playground.html +++ b/docs/playground.html @@ -113,6 +113,17 @@

Playground

+ +