ui-calling

The agent fills in what it knows

Use it when the user already said something in the chat that the screen asks for ("the blender arrived cracked"): the agent passes it, and the screen starts with it selected. The user can still change it.

Full example: sku and reason in the demo's order_return.

Contract

Optional inputs, with a describe that tells the model when to pass them. Say it in the surface's description too.

input: z.object({
  order_id: z.string().describe("The delivered order, e.g. A-0987"),
  sku: z.string().optional().describe("The item to preselect, if the user named one"),
  reason: z.enum(RETURN_REASONS).optional().describe("The reason to preselect, if the user gave one"),
}),

Server

Apply the prefill in resolve, into the draft, and only while the user hasn't saved their own choice. A second link (the user asks again) must not overwrite what they picked.

resolve: async ({ order_id, sku, reason }, ctx) => {
  const r = getReturn(order_id, ctx.subject);
  const item = r.items.find((i) => i.sku === sku && i.returnable);
  const itemsSaved = r.submitted || r.draft.step !== "items";
  if (item && !itemsSaved && !r.draft.lines.some((l) => l.sku === item.sku)) {
    addLine(r, { sku: item.sku, qty: 1, reason: reason ?? null, details: "" });
  }
  return getReturn(order_id, ctx.subject);
},

Prompt

The model can only pass IDs it has. Put them in the system prompt for this user:

Returnable orders: A-0987, delivered 2026-11-19: BL-200 Countertop blender, GB-3 Glass mixing bowls (set of 3), KS-1 Kitchen scale (not returnable).

Watch out

In the ui-calling repo

Not in the package; for reading if you have the repo.

Source: packages/cli/recipes/prefill.md