ui-calling

Getting started

ui-calling is a preview (0.1.0-preview on npm). The contract is frozen (what's stable); blocks, templates and the CLI keep growing. What it is and why: the overview.

It fits when the agent's channel can't, or shouldn't, show the screen a task needs but can send a link (WhatsApp, SMS, email, a web chat), and the agent has to learn what happened on that screen to carry on. If the channel can't carry a link either, ui-calling alone doesn't solve it.

Three words

Install and set up

Add the adapter for your agent SDK (@ui-calling/anthropic, @ui-calling/ai-sdk, @ui-calling/openai, @ui-calling/bedrock, @ui-calling/adk or @ui-calling/mcp), and @ui-calling/postgres if you run several instances or on serverless. @ui-calling/otel sends what happens on the screen to the OpenTelemetry setup your agent already has. ui-calling is the CLI: installing it pins the version npx ui-calling runs. init then prints anything else your framework needs: on Vite, hono @hono/node-server tsx for the small API server it writes.

npm install @ui-calling/core @ui-calling/server @ui-calling/react @ui-calling/sqlite ui-calling zod
npx ui-calling init
npx ui-calling new shift-picker

init detects your framework and writes the runtime (ui.ts), the store (store.ts), the screen router (surface-screen.tsx) and the design tokens. Then, per framework:

FrameworkAPI (what the screen talks to)Screen route
Next.jsapp/api/ui/[...path]/route.tsapp/s/[token]/page.tsx
ViteA small Hono server in server/index.ts (port 8787, npm run dev:api), with /api proxied to it/s/:token, rendered from src/main.tsx
React Router 7app/routes/api.ui.ts, a resource routeapp/routes/s.$token.tsx
Express, Fastify, KoaYou mount uiCallingNodeHandler before your body parser; init prints the linesYou route /s/:token to <SurfaceScreen>

Verified end to end on Next.js 16, Vite, React Router 7 and Express 5, and in four pilot apps that coding agents built from the packages alone. For a deployed app to read from top to bottom, see the event concierge: Vercel, Supabase Postgres and Twilio WhatsApp, with screenshots of every step. GUIDE.md covers the patterns, rules and a done checklist, and is written so coding agents can follow it too (npx ui-calling guide prints it in any project). Agents working on this repo should read AGENTS.md.

The primitives

1. Contract (isomorphic, shared by agent, server and UI):

export const orderStatus = defineSurface({
  name: "order_status",
  description: "Live status of a customer's order…",         // the LLM reads this
  input: z.object({ order_id: z.string() }),                  // becomes the tool schema
  data: z.object({ /* what the screen renders */ }),
  events: {
    reschedule_delivery: event(slot, {
      describe: (p) => `User rescheduled the delivery to ${p.date}, ${p.window}`,
      wake: true,                                             // start an agent turn right away
    }),
  },
});

2. Implementation (server only):

const ui = createUiCalling({
  baseUrl: "https://ui.acme.com",
  onEvent: (e) => handleUiEvent(e),            // append to the conversation; if e.wake, run the agent
  surfaces: [
    implement(orderStatus, {
      resolve: ({ order_id }, ctx) => getOrder(order_id, ctx.subject),  // access check lives here
      summarize: (o) => `Order ${o.id}: ${o.status}…`,                 // what the agent is told
      on: { reschedule_delivery: async (slot, ctx) => updateEta(slot, ctx.subject) }, // side effects; return fresh data
    }),
  ],
});

ui.tools();                                     // → tool definitions for any function-calling LLM
await ui.runTool(toolName, input, { conversationId, subject });  // → { content for the model, link for the user }

3. Screen:

const { data, emit, complete } = useSurface(orderStatus);
emit("reschedule_delivery", { date, window });   // typed from the contract

Lifecycle events (opened, returned, left, completed, abandoned) are tracked automatically.

Context, not just a callback

The point isn't only that the agent writes again: the conversation continues with everything that happened on the screen, so the user can say "what I reported earlier" and the agent knows. Each event carries three things into the agent's context:

Where it comes fromExample
What the user sawstate on opened (via summarize)items, prices, delivery slot at the moment they opened it
What the user diddescribe(payload)"User reported a problem (damaged): …"
What resultedstate after the event's handler"Open issue: damaged, ticket INC-3944"
<ui_events …>
- 08:21:04 [order_status] report_problem: User reported a problem (damaged): "…" {…}
  → screen now shows: Order A-1042: issue … Open issue: damaged, ticket INC-3944.
</ui_events>

Write summarize as "everything the screen shows, in one line": it's the agent's view of the screen.

Packages

PackageWhat it does
@ui-calling/coredefineSurface, implement, createUiCalling (tools, sessions, events), formatEventsForAgent, WhatsApp CTA adapter
@ui-calling/serverThe routes the screen talks to (GET /sessions/:token, POST /sessions/:token/events): a Hono app, a (Request) => Response handler, and a Node (req, res) handler for Express and Fastify (@ui-calling/server/node)
@ui-calling/react<SurfaceProvider>, useSurface(contract): typed data, typed emit, automatic lifecycle tracking
@ui-calling/anthropicSurfaces as Anthropic SDK tools: tool runner (anthropicRunnableTools) or manual loop (anthropicTools, anthropicToolResult)
@ui-calling/ai-sdkSurfaces as Vercel AI SDK tools (aiSdkTools)
@ui-calling/openaiFunction tools for the Responses API and Chat Completions, no SDK dependency
@ui-calling/sqliteZero-config persistence on Node's built-in SQLite: links and the agent's context survive restarts. Also sqliteIdentity: account links and one-time codes with attempt limits
@ui-calling/postgresThe same persistence in Postgres, for several instances and serverless hosts: pass a pg Pool (or any client with query). Tables are created on first use
@ui-calling/bedrockTools for the Amazon Bedrock Converse API, no SDK dependency
@ui-calling/adkSurfaces as a toolset for Google's Agent Development Kit for TypeScript (adkToolset)
@ui-calling/mcpAn MCP server whose tools are your surfaces (createUiCallingMcpServer)
@ui-calling/otelWhat happens on the screen as OpenTelemetry spans, in the same trace as the agent's turn (otelTrace)
ui-calling (CLI)init sets ui-calling up in your project (detects Next.js, Vite, React Router, and Express, Fastify or Koa); new <name> scaffolds a surface and registers it (--template steps for several steps); add copies ready-made blocks and parts (list shows them); link and events open a screen for a test user on your dev server and show what the agent reads; whatsapp dev and whatsapp check connect a real WhatsApp number; tokens copies only the design tokens; guide prints the building guide and its recipes (guide toc lists its sections). Any command takes --help

Running the demo

From a clone of the repo, npm install and npm run dev, then open http://localhost:5173.

Reset data puts orders, returns, shifts and job applications back to the start and keeps chats and account links. Reset all clears everything, real WhatsApp chats included.

On your own WhatsApp

The demo also answers a real WhatsApp number, using a Meta test number on the WhatsApp Cloud API. Put the four keys from the GUIDE in .env, install cloudflared (brew install cloudflared), then run:

npm run dev:whatsapp

It opens a tunnel, starts the demo with PUBLIC_URL set to it, points the Meta app's webhook there and prints Ready. Message the test number. Your number isn't linked to a demo customer, so the agent first sends a linking screen: use lucia.romero@example.com and code 246810. The shift picker then asks for a PIN: 1357. At every start the demo prints one WhatsApp line that names an expired token or a webhook pointing at an old address.

Roadmap

Source: docs/getting-started.md