Live, watchable 2-agent ETH-escrow demo (mock chain) — stacked on #131#132
Open
Pattermesh wants to merge 3 commits into
Open
Conversation
Contributor
|
🤖 Audit skipped — diff is 206KB (limit 64KB). Labelling for human review. |
DEMO-READY agentic payments + light UI + PWA proposal.
(1) examples/agentic_demo/ — runnable A2A scenario: Agent A pays Agent B for
work via the x402 middleware + on-chain escrow (402 offer -> validate ->
lock -> deliver -> confirm/release), then an AGENTIC SWAP step where B routes
the received USDC through SafeSwap. Node/RPC-free: drives the real
X402Middleware + GasTracker against an in-memory chain (MockChain /
MockPaymentClient) and a mockable SafeSwap orchestrator. Runs with
`python examples/agentic_demo/run.py` (+ --json, --swap-to, --price).
tests/test_agentic_demo.py asserts the full flow: 402 -> pay -> settle
(escrow Released) and the SafeSwap swap routes (quote -> execute).
(2) web/lab/swap.html — a focused lab page visualizing the A2A pay + swap demo:
animated canvas (payer / escrow / payee / SafeSwap nodes + in-flight
packets), a step-by-step flow ledger, and live balances. Reuses the lab's
shared.css/shared.js; wired into the lab dashboard + sidebar + _build.js.
Does not touch the strict agents-demo.html scene engine.
(3) PWA — web/manifest.json + web/sw.js make the lab installable + offline-
capable (app-shell precache, network-first navigations w/ offline fallback,
stale-while-revalidate assets). Registration injected via shared.js (lab)
and web/index.html (root). docs/PWA.md proposes the "switchboard plugin"
PWA: install/consent flow, offline architecture, and how a host PWA embeds
switchboard payments (402 interception -> pay -> retry, budget-gated).
tests/test_pwa.py validates manifest, icons, SW shell, and registration.
GATE: PYTHONPATH=. python3 -m pytest -q -> 245 passed, 62 skipped (was 223;
+22 new). swap.html + sw.js pass node --check.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Makes the existing examples/agentic_demo A2A flow watchable in a browser:
two synthetic agents transact over an in-memory MockChain AgentEscrow —
x402 402-offer -> validate(cap/allowlist/gas) -> escrow LOCK -> deliver ->
confirm -> RELEASE -> SafeSwap route — replayed step by step from the REAL
orchestration output (real escrow state, real X402Middleware spend summary,
real SafeSwap receipt), not faked in JS.
What's added (scenario.py / onchain.py / safeswap.py stay byte-for-byte
unchanged):
- observable.py — wraps run_scenario into an ordered, deterministic,
render-ready timeline (logical clock + seeded ids => same seed yields
byte-identical runs).
- server.py — stdlib http.server transport: GET /, POST /api/demo/run,
GET /api/demo/state, POST /api/demo/step, GET /healthz (DEMO.md API).
- web/ — canonical page sources (index.html, demo.css, view.js,
demo.js); build.mjs inlines them into the self-contained demo.html the
server serves (drift-guarded by demo.test.mjs).
- test_live.py + web/demo.test.mjs — pin timeline order, determinism, the
HTTP envelope, and the page build-sync.
- DEMO.md — fixed design contract; README.md gains a "Watch it live".
How to run:
PYTHONPATH=. python examples/agentic_demo/server.py
# then open http://127.0.0.1:8402/ (or pass --open)
SIMULATED / MOCK CHAIN — not a live network. No real ETH, no real RPC, no
network, no funds; synthetic agents/keys only. Nothing here is a live or
production deployment. The escrow / x402 / SafeSwap rail being shown is
kcolbchain/switchboard's (the collective's agentic-payments rail; Abhishek
Krishna / @abhicris leads); this layer only makes it watchable.
Demo by Pattermesh (Patty / P. Sundaram).
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
b5d6cc6 to
3319cc7
Compare
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.
Makes the existing
examples/agentic_demoagent-to-agent flow watchable in a browser — the headline asset for showing off switchboard's agentic-payments rail.Run it (the one command a human types)
GET /serves a single self-contained page; press Run demo.What the viewer sees
Two agents transact over a mock-Ethereum
AgentEscrow, animated step by step:402 Payment Requiredwith an x402 escrowPaymentOffer(5 USDC).X402Middlewarevalidates the offer against a cap, recipient allow-list, and gas budget.AgentEscrow(stateLocked); A's balance 100 → 95 USDC.Locked → Released; B credited 5 USDC.Every number on the page is the real orchestration's output — real escrow state, real
X402Middleware.get_spend_summary(), realSafeSwapreceipt — replayed step by step, not recomputed/faked in JavaScript.How it's built (nothing core is rewritten)
scenario.py/onchain.py/safeswap.pyare byte-for-byte unchanged. The live layer is purely additive:observable.pyrun_scenariointo an ordered, deterministic, render-ready timeline (logical clock + seeded ids ⇒ same seed yields byte-identical runs)server.pyhttp.servertransport:GET /,POST /api/demo/run,GET /api/demo/state,POST /api/demo/step,GET /healthzweb/index.html,demo.css,view.js,demo.js);build.mjsinlines them into the self-containeddemo.htmlthe server servestest_live.py,web/demo.test.mjsdemo.htmlbuild-syncDEMO.mdJSON API (see
DEMO.md):Verification
PYTHONPATH=. python3 -m pytest examples/agentic_demo/ -q→ 29 passed; existingtests/test_agentic_demo.py→ 11 passed (unchanged scenario still green). Broader suite: 245 passed, 62 skipped, 0 failed.node --checkon everyweb/*.js→ clean;node --test examples/agentic_demo/web/demo.test.mjs→ 20 passed.GET /→ 200 HTML (sandbox banner + canvas present);POST /api/demo/run→ ordered timelinesetup → 402 → validate → pay → deliver → settle → swap.quote → swap.execute, escrowLocked → Released, payee B credited 5.00 USDC, A debited to 95.00 USDC,settled: true;GET /api/demo/stateechoes the last run.Live demo by Pattermesh (Patty / P. Sundaram). The escrow / x402 / SafeSwap orchestration shown here is kcolbchain/switchboard's — the collective's agentic-payments rail (Abhishek Krishna / @abhicris leads). This PR only makes it watchable.
🤖 Generated with Claude Code