The explore agent came back with a clear picture, and the good news is that microworlds are a natural extension of what's already there. Here's the short version of the architecture, then my draft design.
What exists: the web animate tool has the model author a complete HTML+GSAP document, saves it, and emits a <keating-animation json=...> tag; AssistantChatPanel parses the tag and HyperframesPlayer runs the HTML in a sandboxed iframe via a blob URL. Separately, quiz/goal cards already have a full interaction loop: card UI → window CustomEvent → panel listener → synthetic user message via onNew → new agent turn, with resultId letting the agent update an already-rendered card. The web and CLI tool sets are parallel implementations with no shared package, and the web path is the more advanced one — so microworlds should be web-first.
Draft: Microworlds in Keating
Core idea. A microworld tool that works like animate — the agent authors a self-contained HTML/JS world, no templates (consistent with your authored-artifacts rule) — but where hyperframes are watched, microworlds are inhabited. The one genuinely new piece is a two-way bridge so the learner's actions inside the iframe can reach the teacher, and the teacher can reach back into the running world. This is Papert's term, and it fits Keating's cognitive-empowerment thesis exactly: the learner learns by manipulating a world and forming theories, with the teacher watching and coaching rather than lecturing.
The window.keating world API. Instead of hyperframes' direct contentWindow.gsap reach-in, wrap the authored HTML (in a buildMicroworldHtml) with a tiny injected runtime the author codes against:
keating.milestone(id, data) — a declared learning moment was hit ("landed the projectile in the bucket"). This is the main trigger for an agent turn.
keating.observe(event, data) — lightweight action telemetry (slider moved, reset pressed), buffered, not triggering turns.
keating.ask(text) — learner asks the teacher from inside the world; fires a turn with current state attached.
keating.registerState(fn) — the world provides a serializer so a snapshot travels with every milestone/ask.
keating.onMessage(fn) — the agent can push into a running world (change a parameter, add a challenge, drop a hint object into the scene).
Parent side, MicroworldPlayer translates postMessage ↔ window events (keating:microworld-milestone etc.), reusing the exact quiz-card feedback machinery. Bonus: with postMessage we can drop allow-same-origin from the sandbox — stricter isolation than hyperframes currently has.
Tool schema. Roughly: topic, summary, body (full HTML, required, rejected if thin — same guard as animate), plus challenges: [{id, prompt}]. Challenges render as a checklist outside the iframe on the card chrome; the world checks them off by calling keating.milestone(challengeId). That gives every world a visible "what am I trying to do here" without constraining what's inside.
Turn economics. Don't fire an agent turn per click — buffer observe events and only go back to the agent on: milestone hit, explicit ask, or a "Show the teacher" button on the card that sends a state snapshot + recent event digest. This keeps the world feeling live without burning a model call on every slider twitch. A stuck-detection heuristic (N resets or M minutes with no milestone → digest to agent) could come later.
Agent-side updates. Mirror the grade_quiz → quiz-grade pattern: an update_microworld tool that targets a world by id and either pushes a message into the running iframe (keating.onMessage) or appends challenges. So the teacher can say "nice — now try it with gravity halved" and actually change the world mid-conversation.
Example worlds (all authorable as single HTML docs): projectile sandbox with a "land in the bucket" challenge; a Galton board where the challenge is "make the distribution skew left"; a grid-robot the learner programs with a tiny command palette; a two-good market where they chase equilibrium; a logic-gate breadboard.
Phasing.
- MVP:
microworld tool + tag parsing + MicroworldPlayer with the postMessage bridge, milestones, and challenge checklist. Plumbing is ~all cloned from animate + quiz cards. Add a decision rule to operational-protocol.md near the existing animate guidance: animate to show, microworld to let them do.
- Live coaching:
update_microworld, state snapshots persisted in storage so a learner can resume a world, artifact-browser entry.
- Constructionist endgame: let the learner edit the world — "view source, change the rules" — which is the most Papert-faithful move and very on-brand for Keating.
The design questions I'd want your call on before speccing: whether milestones auto-trigger an agent turn or queue until the learner surfaces (auto feels magical but chatty); whether MVP includes update_microworld or ships read-only-teacher first; and whether CLI parity matters at all for this or it's web-only. Want me to turn this into a spec doc for codex to implement?