Skip to content

Pyodide Phase 3: edit the agent brain in the browser and re-run#10

Merged
rsasaki0109 merged 1 commit into
mainfrom
pyodide-phase3-editor
Jun 4, 2026
Merged

Pyodide Phase 3: edit the agent brain in the browser and re-run#10
rsasaki0109 merged 1 commit into
mainfrom
pyodide-phase3-editor

Conversation

@rsasaki0109

Copy link
Copy Markdown
Owner

What

Follow-up item ② Phase 3 from docs/pyodide_playground_strategy.md — the "edit the robot's brain in the browser" moment.

The pick_and_retry scenario now shows an "Agent brain" code editor pre-filled with the real PickAndRetryAgent source (fetched via inspect.getsource, so it can never drift from the file). Edit it, click Run edited agent, and the playground execs your 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.

Changes

  • examples/manipulation/01_pick_and_retry.py — extract run_agent(agent, ...); run() delegates 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 (no 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.pyrun_agent tolerates a custom (belief-less) agent and still produces valid, plain-JSON config.

Safety

The edited code runs entirely client-side — Pyodide is a WASM sandbox in the visitor's own browser, so exec'ing it is no more privileged than a local REPL. Nothing touches a server.

Verification

  • Full suite green (122 tests).
  • Verified the exact drivers in an unpacked-bundle sim: the default source reproduces seed=3 (4 steps, retries=2); removing the deliberate first offset makes the agent grab the belief mean immediately (2 steps, retries=0) — a live lesson in why the retry schedule exists; malformed code raises a caught error.

Still pending (browser, your side)

Pick "Pick and retry (real Python)", confirm the editor populates with the real source, edit offset_schedule / act(), and confirm Run edited agent re-runs and inline errors render.

🤖 Generated with Claude Code

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) <noreply@anthropic.com>
@rsasaki0109 rsasaki0109 merged commit 647105e into main Jun 4, 2026
3 checks passed
@rsasaki0109 rsasaki0109 deleted the pyodide-phase3-editor branch June 4, 2026 20:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant