Pyodide Phase 3: edit the agent brain in the browser and re-run#10
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
PickAndRetryAgentsource (fetched viainspect.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 realTabletop2Dvia the example's ownrun_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— extractrun_agent(agent, ...);run()delegates to it.run_agentreads 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_SRCis injected viapyodide.globals(no string-escaping); the source-fetch driver registers the module insys.modulessoinspect.getsourceworks; the editable header re-addsfrom __future__ import annotations+typing.Anyso the class execs standalone.tests/test_playground_trace.py—run_agenttolerates 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
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