A deep dive into four internal mechanisms powering EGP Code, Mercari's AI-driven landing page editor. The post covers: (1) a recursive agent loop where the AI reasons, calls tools, and self-corrects on errors; (2) real-time sync using Firestore so users see live progress without WebSockets; (3) a browser-native test runner built on @vitest/expect and Testing Library that runs inside an iframe; and (4) a mapping table using injected data-egp-src-id attributes to link rendered preview elements back to their positions in the HTML source, enabling Monaco editor jumps and precise AI instructions. The article also details real-time steering — injecting mid-flight instructions into an already-running agent loop — and how Zero Data Retention requirements led to self-managed conversation history.

12m read timeFrom engineering.mercari.com
Post cover image
Table of contents
Mechanism 1: A recursive agent loop that bundles context and toolsMechanism 2: Real-time sync using Firestore as the handoff point for instructionsMechanism 3: A test runner that runs entirely in the browserMechanism 4: A mapping table linking preview elements to positions in the HTMLConclusion
518 Impressions