Skip to content

Live, watchable 2-agent ETH-escrow demo (mock chain) — stacked on #131#132

Open
Pattermesh wants to merge 3 commits into
pattermesh/switchboard-agentic-demo-pwafrom
pattermesh/switchboard-agentic-demo-live
Open

Live, watchable 2-agent ETH-escrow demo (mock chain) — stacked on #131#132
Pattermesh wants to merge 3 commits into
pattermesh/switchboard-agentic-demo-pwafrom
pattermesh/switchboard-agentic-demo-live

Conversation

@Pattermesh

Copy link
Copy Markdown
Collaborator

SIMULATED / MOCK CHAIN — not a live network. No real ETH, no real RPC, no network, no funds. Everything runs against an in-memory MockChain implementing the AgentEscrow surface (lock → confirm → release / refund). Synthetic agents/keys only. Nothing here is a live or production deployment.

Stacked on #131. Base is pattermesh/switchboard-agentic-demo-pwa (the head of #131), not main. Review/merge #131 first; retarget this PR to main after #131 merges.

Makes the existing examples/agentic_demo agent-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)

cd <repo>
PYTHONPATH=. python examples/agentic_demo/server.py
# then open http://127.0.0.1:8402/   (or add --open)

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:

  1. Agent A hires Agent B for an inference job.
  2. B → 402 Payment Required with an x402 escrow PaymentOffer (5 USDC).
  3. A's real X402Middleware validates the offer against a cap, recipient allow-list, and gas budget.
  4. Escrow LOCK — A locks 5 USDC in AgentEscrow (state Locked); A's balance 100 → 95 USDC.
  5. B delivers the work (HTTP 200) against the payment proof.
  6. Escrow RELEASE — A confirms; escrow Locked → Released; B credited 5 USDC.
  7. SafeSwap — B routes the received USDC through the SafeSwap orchestrator into the target asset (ETH/LUX), with a real best-execution route + receipt.

Every number on the page is the real orchestration's output — real escrow state, real X402Middleware.get_spend_summary(), real SafeSwap receipt — replayed step by step, not recomputed/faked in JavaScript.

How it's built (nothing core is rewritten)

scenario.py / onchain.py / safeswap.py are byte-for-byte unchanged. The live layer is purely additive:

File Role
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
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
test_live.py, web/demo.test.mjs pin timeline order, determinism, the HTTP envelope, and the demo.html build-sync
DEMO.md the fixed design contract (event model, step ids, HTTP API)

JSON API (see DEMO.md):

POST /api/demo/run    → run the scenario, return the ordered timeline + summary envelope
GET  /api/demo/state  → replay the last run (or a fresh seeded one)
POST /api/demo/step   → optional server-driven stepwise mode
GET  /healthz         → {"ok": true}

Verification

  • PYTHONPATH=. python3 -m pytest examples/agentic_demo/ -q29 passed; existing tests/test_agentic_demo.py11 passed (unchanged scenario still green). Broader suite: 245 passed, 62 skipped, 0 failed.
  • node --check on every web/*.js → clean; node --test examples/agentic_demo/web/demo.test.mjs20 passed.
  • Live smoke: started the server, GET / → 200 HTML (sandbox banner + canvas present); POST /api/demo/run → ordered timeline setup → 402 → validate → pay → deliver → settle → swap.quote → swap.execute, escrow Locked → Released, payee B credited 5.00 USDC, A debited to 95.00 USDC, settled: true; GET /api/demo/state echoes 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

@abhicris

Copy link
Copy Markdown
Contributor

🤖 Audit skipped — diff is 206KB (limit 64KB). Labelling for human review.

abhicris and others added 3 commits June 30, 2026 18:19
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>
@Pattermesh Pattermesh force-pushed the pattermesh/switchboard-agentic-demo-live branch from b5d6cc6 to 3319cc7 Compare July 1, 2026 08:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants