ui-calling

ui-calling

Send a screen from any chat. Your agent hears what happens on it.

Built for the conversations that would otherwise be lost: the user who stops halfway, the payment that fails, the slot that disappears.

Preview. On npm as 0.1.0-preview, not ready for production. The contract is frozen (what's stable); the rest may still change. MIT licensed and self-hosted: it runs in your app, not on someone else's platform.

The whole loop in the demo: a customer asks to return a cracked blender, the agent sends a link, they get two steps into the return screen and leave; the abandon wakes the agent, which writes first in the chat

Your agent is talking to a customer on WhatsApp. To process a return it needs the items, a reason for each, photos and a pickup slot, and chat is bad at all four. So it calls show_order_return({ order_id }) like any other tool. The customer gets a link and opens a real screen. They pick the items, give a reason, and stop before the photos. Fifteen minutes later the agent reads:

08:20:11 [order_return] opened: User opened the screen
08:20:40 [order_return] items_chosen: Step 1 of 5:
         chose items to return: 1× BL-200
08:21:02 [order_return] reasons_given: Step 2 of 5:
         gave reasons: BL-200 damaged ("jar cracked")
08:36:02 [order_return] abandoned: User stopped partway
         without finishing. Last step: Step 2 of 5

It writes back in the chat: "Want to send the photos later? Your progress is saved." The link, or a new one once it expires, opens at the photos. (Abandon is opt-in: nothing wakes the agent until you set abandonAfterMs.)

That's ui-calling: tool calling lets an agent call your functions, ui-calling lets it call a screen. A screen's link works in any channel (WhatsApp, SMS, email, a web chat), and its whole life comes back into the agent's context (opened, left, came back, each action and its outcome, errors, completed, abandoned). It works with Anthropic, OpenAI, the AI SDK and MCP. Screens are React, copied into your repo, and it's self-hosted.

Use it when the agent's channel can't, or shouldn't, show the screen the task needs, but can send a link, and the agent has to learn what happened there (progress, errors, an abandon, the outcome) to carry on the conversation. The screen opens in the browser, outside the chat, and its events come back to the agent, which replies in the channel the user started in.

Most events are just recorded for the agent's next turn. The ones that matter (a finished task, an abandon, a failure) wake the agent: they start a turn on their own, so it can write first, as in the return above. When a follow-up wouldn't help, the agent calls the built-in stay_silent tool instead of writing, and ui.onSilentWake counts those turns, so you can see which screens wake it for nothing.

agent ──tool call──▶ show_order_return({ order_id })
                        │  link: opaque token, bound to this conversation
                        │  and this user, expires
                        ▼
chat  ◀── "Let's start your return 👇" + [Start return] button
                        │
user opens link ──▶ data loaded on the server, only what this user may see
                        │
user picks items, gives a reason ──▶ recorded quietly, step by step
                        │
15 minutes idle ──▶ "User stopped partway… Step 2 of 5"  (wake)
                        ▼
agent writes first: "Want to send the photos later?"

Why ui-calling

Other tools let a bot open screens. ui-calling lets your agent know what happens on them.

How it compares

UseWhen
MCP Apps, or the AI SDK's tool partsThe user is already in a client that renders UI inline: Claude, ChatGPT, your own web chat
WhatsApp FlowsA short form whose fields you know in advance; it never leaves WhatsApp
LangGraph interrupts, or a durable workflow engineYou need to pause and resume an agent, with no screen of your own
ui-callingThe user is in a channel that can only carry a link, the screen is your own, and what happens on it (a stall, a failure, partial progress) should change what the agent says next

They combine: a ui-calling event can resume a paused workflow, and a screen is just a page, so it can also open from a web chat.

When not to use it

What you can build

The fit is a task that is hard in chat (uploads, live availability, a long list, a third-party SDK) and where stalling or failing matters to the follow-up. These five run today, in the demo or as ready-made screens you copy into your project:

Use caseWhat the screen doesIn this repo
Returns and exchangesItems, a reason each, photos, refund and pickupDemo (order_return)
Delivery rescheduleLive slots, "that slot is gone", carrier outagesReady-made: order-status
Account linkingVerify an email code, link the chat to a customerReady-made: link-account
Shift pickingOpen shifts that others may take first; asks for the worker's PINDemo (shift_picker)
Job applicationsFour steps with an ID photo, no account needed; a candidate who stops gets a nudge, or a template the next dayDemo (job_application)

A whole app built on these pieces, deployed on Vercel with Supabase and Twilio WhatsApp: an event concierge (a ticket behind an SMS code, workshops with limited seats, investor meetings whose abandon the agent follows up), with a README that walks through every part.

The same pieces fit insurance claim intake (the return's steps and photo upload), onboarding paperwork and payslips (verify: true), identity verification (abandon at the selfie), appointment booking across locations, and B2B reorders (quantity-stepper, choice-card).

Try the demo

A hosted demo is on the roadmap; for now it runs from a clone, with no API key needed:

git clone https://github.com/pausanchez/ui-calling && cd ui-calling && npm install
npm run dev

Open http://localhost:5173 and ask "¿Dónde está mi pedido?", "The blender arrived cracked, I want to return it" (a five-step return with photo upload), "Are there any shifts open this week?" (PIN 1357) or "Busco trabajo, ¿tenéis ofertas?" (a job application; switch on "24-hour window closed" to see the next-day template). It's a simulated WhatsApp chat next to an "Under the hood" panel with two tabs:

No API key? A scripted agent runs the same loop. Options, resets and running it on a real WhatsApp number: Getting started.

Get started

Install the packages and the adapter for your agent SDK (here Anthropic's), then set it up in your app and generate your first screen. init prints anything else your framework needs.

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

Getting started has the install command, the words the API uses, what init writes for Next.js, Vite, React Router and Express, the packages, and the three primitives (contract, implementation, screen). GUIDE.md has the patterns and rules, written so coding agents can follow them too.

Errors reach the agent too

Where errors come from and how to throw your own: GUIDE.md.

Retries are safe

What each state means and exactly what's guaranteed: GUIDE.md. scripts/test-guarantees.ts checks it on every store.

Security, in short

The whole model, plus persistence, languages and WhatsApp identity: GUIDE.md.

Questions people ask

What's stable

The contract is frozen for the 0.1 previews: defineSurface and event, implement (resolve, summarize, on, ctx), useSurface, createUiCalling's options, the HTTP routes and the events the agent reads. Changes there are additive until 1.0; anything else comes with a deprecation first. Blocks, parts, templates, the CLI's output and the demo keep growing. GUIDE.md has the list.

Roadmap

Next up: a hosted demo you can try without cloning. The rest of the list is in Getting started.

License

MIT. See LICENSE.

Source: README.md