← All Labs Lab 10 / 19 Serve agents over A2A
Lab 10 · Durable agents · Folded back

Serve agents over A2A

One AgentHost opens each agent's SQLite file on its first request, once, only for safe ids, and serves it as an A2A 1.0 agent whose card points at a reachable endpoint.

Folded back Needs: chat Smoke: pnpm exec tsx examples/10-agents-over-a2a/host.ts --smoke Run: pnpm exec tsx examples/10-agents-over-a2a/host.ts Source: examples/10-agents-over-a2a
bash
pnpm exec tsx examples/10-agents-over-a2a/host.ts --smoke

One AgentHost serves every agent under /agents/<id>/ on one Node HTTP server (createHttpHandler). Each agent is a DurableAgent with its own agents/<id>/agent.sqlite, opened when the first request for it arrives. The model is faux, so the lab runs offline.

CheckWhat it shows
lazy-openNothing is open and no data directory exists before the first request
card-reachableThe agent card's endpoint is the address the request came in on
a2a-answerA2A 1.0 SendMessage to that endpoint completes with the agent's answer
own-sqliteThe agent got its own agents/research/agent.sqlite
open-onceTwo simultaneous first requests to a new agent open its file once
id-traversal-refusedAn id like ..%2F..%2Fescaped gets 400 and creates nothing

Revert the AgentHost fix in packages/agent/src/durable/durable-agent.ts and four checks fail.

Prompt

Coding-Agent Prompt · Ready to Paste
Build examples/10-agents-over-a2a/host.ts: one @umwelten/agent AgentHost serving many SQLite-backed DurableAgents as A2A 1.0 agents on one Node HTTP server via createHttpHandler, with a faux model so it runs offline. Check, printing PASS/FAIL per check and exiting 1 on any failure: nothing opens before the first request; each agent gets its own <dataDir>/<id>/agent.sqlite; the agent card's endpoint is reachable and SendMessage to it completes; two simultaneous first requests open the agent once; an id that decodes to a path outside dataDir is refused and creates nothing. Strict TypeScript, no any, clean up the temp dir in finally.
Works in Pi, Claude Code, Codex & Antigravity Offline mock first → --live opt-in

What we learned

The answer

One AgentHost serves many agents from one process, each from its own SQLite file opened on demand. Going through the lab found three bugs in AgentHost.createHttpHandler, all fixed in the package with a regression test (durable-agent.test.ts, "serves only safe agent ids over HTTP…"):

  • Path traversal through the agent id. The id from /agents/<id>/ was percent-decoded and joined onto dataDir, so /agents/..%2F..%2Fescaped/… opened (and created) an agent directory outside the data directory. Ids must now match ^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$; anything else gets 400, and AgentHost.get() rejects it too.
  • Concurrent first requests opened the file twice. Two requests for a not-yet-open agent each ran DurableAgent.open on the same agent.sqlite, which breaks pi-durable's one-writer rule. First opens in flight are now shared.
  • The agent card advertised an unreachable endpoint. Without a publicOrigin, the card said http://127.0.0.1/agents/<id>/a2a, with no port, so a client following the card got connection refused. It now uses the request's Host.

What going through it found about the lab

  • The lab checked nothing. It printed the card name and the raw task JSON and always exited 0. It now has six PASS/FAIL checks and exits 1 on failure.
  • The old README and prompt promised more than the code did (repo guards, probes, ui:// resources). Those are Labs 09, 07 and 13; this lab now tests only the host.
  • The existing host test never used createHttpHandler. It wired one agent's A2A surface to a server by hand, which is why none of these bugs showed up.

Gotchas

  • Behind a proxy, set publicOrigin. The Host fallback is right for direct access; a proxy that rewrites Host would advertise its internal address.
  • No auth by default. Without a bearerToken from configure, each agent allows unauthenticated loopback callers only.

Not tested

  • Idle eviction and reopen through HTTP (Lab 08 covers eviction directly).
  • Authenticated agents (bearerToken), and many agents at once.
  • A live model.

Smoke run

Visual Target Wireframe ASCII Layout
  PASS  lazy-open: before any request: 0 open, data dir exists=false
  PASS  card-reachable: card endpoint http://127.0.0.1:33607/agents/research/a2a
  PASS  a2a-answer: TASK_STATE_COMPLETED "Answer 1 from a SQLite-backed agent."
  PASS  own-sqlite: agents/research/agent.sqlite exists=true
  PASS  open-once: statuses 200, 200; agent opened 1 time(s)
  PASS  id-traversal-refused: HTTP 400; open: [research, support]; data dir: [research, support]

  6/6 passed

Before the fix, 3/7: card-reachable, card-endpoint-answers, open-once and id-traversal-refused failed.