← All Labs Lab 23 / 28 A2A tasks carry ui:// views
Lab 23 · Tools & UI · Learned

A2A tasks carry ui:// views

With createA2ASurface({ uiResources: true }), an A2A task carries the ui:// views its turn produced as text/html URL artifacts on the agent's own origin, behind its bearer token, sandboxed, with an unguessable URL.

Learned Needs: tool-calling Smoke: pnpm exec tsx examples/23-a2a-view-artifacts/run.ts --smoke Run: pnpm exec tsx examples/23-a2a-view-artifacts/run.ts Source: examples/23-a2a-view-artifacts
sh
pnpm exec tsx examples/23-a2a-view-artifacts/run.ts --smoke

Lab 13 shows a tool's view reaching the person in the chat client. This lab asks whether another agent gets it too. One DurableHabitat with one plain tool (show_status, returning withUIResources(summary, view)) runs an offline faux model and is served over A2A with a bearer token. A second copy is served without uiResources as a control.

CheckWhat it shows
card-advertises-htmlThe agent card lists text/html output
task-carries-viewSendMessage answers with the summary and a text/html URL artifact on the agent's origin; fetching it with the token returns the tool's HTML
view-needs-tokenThe same URL without the token gets 401
view-sandboxedThe view is served with content-security-policy: sandbox …
wrong-mac-refusedChanging one character of the URL's MAC gets 404
off-without-optionWithout uiResources the same turn answers with the summary and no view artifact

Break it

In packages/habitat/src/durable/durable-habitat.ts, make serveUIView accept a missing identity (identity = (await identify()) ?? "bypass"). view-needs-token fails and the smoke exits 1.

Split out of Lab 13, whose smoke used to include these checks with authentication turned off for loopback.

Prompt

Coding-Agent Prompt · Ready to Paste
Build a self-contained script that opens a DurableHabitat with one plain @umwelten/pi tool returning withUIResources(summary, buildHabitatUIResource(view)), driven by a scripted faux model that calls the tool once and then answers from its summary. Serve it over A2A with createA2ASurface({ uiResources: true, bearerToken }) on a loopback HTTP server, plus a second copy without uiResources as a control. Check, one PASS/FAIL line each and exit 1 on any failure: the card lists text/html output; SendMessage answers with the summary and a text/html URL artifact on the agent's origin that returns the tool's HTML with the token; the same URL without the token is refused; the view is served with a sandbox CSP; a URL with one changed MAC character gets 404; the control answers without a view artifact.
Works in Pi, Claude Code, Codex & Antigravity Offline mock first → --live opt-in

What we learned

The answer

Another agent gets the view, and only with the token. With uiResources: true a completed task carries each ui:// view as a text/html URL artifact under /a2a/ui/… on the agent's own origin. Fetching it needs the same bearer token as /a2a (401 without), it's served with a sandbox CSP, and a URL with a wrong MAC gets 404. Without the option the same turn carries the summary only.

What going through it found

  • Lab 13 never tested the authentication. Its A2A checks ran with allowUnauthenticatedLoopback, so a view server that ignored the token passed them. This lab sets a bearer token; bypassing the identity check in serveUIView fails view-needs-token.
  • A first break test passed by mistake. "bypass" ?? auth ? await auth(req) : … parses as ("bypass" ?? auth) ? …, so auth still ran. A break test has to be checked for actually breaking something.

Gotchas

  • pi-a2a 0.5.1 authenticates the agent card too. GET /.well-known/agent-card.json gets 401 without the token, so a client has to know the token before it can read the securitySchemes the card advertises. A2A expects the public card to be readable; this is upstream behavior in a2aHttpHandler, not changed here.
  • Views are served on the agent's origin because pi-a2a only accepts URL artifacts there; a separate view host wouldn't work.
  • The URL's MAC key is per surface instance. Restarting the agent invalidates every view URL it handed out.

Not tested

  • A2A streaming (SendStreamingMessage) artifacts.
  • More than one view per turn (the surface sends at most four).
  • A real A2A client rendering the view.

Smoke run

Visual Target Wireframe ASCII Layout
  PASS  card-advertises-html: card lists text/html output
  PASS  task-carries-view: answer has the summary; view URL on the agent's origin → 200, the tool's HTML
  PASS  view-needs-token: without the bearer token → 401
  PASS  view-sandboxed: content-security-policy: sandbox allow-scripts allow-forms
  PASS  wrong-mac-refused: one changed character in the URL → 404
  PASS  off-without-option: without uiResources: summary present, view artifact absent

  6/6 passed