Agents in your app

Deleting

Let an agent delete an event only after the person on the page says yes.

Live. Ask for a delete, then answer above the calendar. The step waits for you, and fails if you keep the meeting.

A deleted event is gone from the calendar, so an agent can't delete until you turn it on. Two switches are involved, and a careful app sets both:

  1. allowAgentDelete on Root. Without it the calendar has no deleteEvent action, for every agent and whatever the bridge allows, and it refuses a delete an agent causes any other way, with one exception: a button of yours that waits before it deletes.
  2. The bridge's allow, which holds the step until the person answers.

This page's samples import the Calendar, meetings and weekRules that the Quick start puts in calendar.tsx, and applyChange and timedOnly from agent-save.ts in Connect an agent.

Off by default

A calendar without allowAgentDelete doesn't offer the action. deleteEvent isn't in its actions, describeCalendar reports canDelete: false, and a step that asks for it fails with the bridge's message for an action a component doesn't have:

{
  "ok": false,
  "error": {
    "step": 0,
    "message": "calendar c1 takes no deleteEvent now. It takes: createEvent, describeCalendar, getChange, goToDate, listEvents, moveEvent, navigateNext, navigatePrevious, navigateToday, resizeEvent, selectEvent, setTimeZone, setView, updateEvent."
  },
  "steps": [],
  "appeared": [],
  "values": {}
}

So a model that reads the calendar first never proposes a delete it can't make. A read-only calendar, one without onEventChange, has no deleteEvent either, whatever allowAgentDelete says.

A new calendar lists every action for a moment

The actions a calendar doesn't offer leave its actions one microtask after it mounts. A snapshot taken in the same task as the mount still lists deleteEvent and, on a read-only calendar, the actions that change events. No agent reads a page that fast, but a test that mounts a calendar and reads actions at once does: await a microtask first. A deleteEvent called in that moment deletes nothing: it fails with calendar-event-change-rejected: agent-delete-not-allowed.

Ask the person

allow can return a promise. The bridge holds the step until it settles, so allow is where the question goes. This bridge puts the request in a small store and resolves when the person answers:

agent-confirm.ts
"use client";

import { createAgent } from "@ui-sdk/react/agent";

/** A delete the agent asked for, waiting for the person's answer. */
export interface DeleteRequest {
  readonly answer: (allowed: boolean) => void;
  readonly eventId: string;
}

let request: DeleteRequest | null = null;
const listeners = new Set<() => void>();

function setRequest(next: DeleteRequest | null): void {
  request = next;
  for (const listener of listeners) listener();
}

/** The request on screen, for `useSyncExternalStore`. */
export const deleteRequest = {
  getSnapshot: () => request,
  subscribe: (listener: () => void) => {
    listeners.add(listener);
    return () => void listeners.delete(listener);
  },
};

/** The event a step names. `allow` runs before the calendar checks the step's arguments. */
function eventIdOf(args: readonly unknown[]): string {
  const input = args[0];
  if (typeof input !== "object" || input === null || !("eventId" in input)) return "";
  return typeof input.eventId === "string" || typeof input.eventId === "number"
    ? String(input.eventId)
    : "";
}

export const agent = createAgent({
  allow: ({ action, args, component }, { signal }) => {
    if (component !== "calendar") return false;
    if (action !== "deleteEvent") return true;
    // The bridge holds this step, and every call after it, until the promise settles.
    return new Promise<boolean>((resolve) => {
      const answer = (allowed: boolean) => {
        setRequest(null);
        resolve(allowed);
      };
      // Nobody answered in time, or the turn was stopped: take the question down.
      signal.addEventListener("abort", () => answer(false), { once: true });
      setRequest({ answer, eventId: eventIdOf(args) });
    });
  },
  // How long a step waits for the answer. Five minutes when left out.
  timeout: 60_000,
});

The calendar turns deleting on and draws the question from that store:

agent-confirm-calendar.tsx
"use client";

import { useEffect, useState, useSyncExternalStore } from "react";

import { CalendarToolbar } from "@/components/calendar/calendar-toolbar";
import { Button } from "@/components/ui/button";

import { deleteRequest } from "./agent-confirm";
import { applyChange, timedOnly } from "./agent-save";
import { Calendar, meetings as initialMeetings, weekRules } from "./calendar";

export function ConfirmingCalendar() {
  const [meetings, setMeetings] = useState(initialMeetings);
  const pending = useSyncExternalStore(
    deleteRequest.subscribe,
    deleteRequest.getSnapshot,
    () => null,
  );
  const meeting = meetings.find(({ id }) => id === pending?.eventId);
  // The calendar left the page with a question open: the answer is no.
  useEffect(() => () => deleteRequest.getSnapshot()?.answer(false), []);

  return (
    <div className="flex h-full flex-col">
      {pending === null ? null : (
        <div
          aria-label="The agent asks to delete a meeting"
          className="flex flex-wrap items-center justify-between gap-2 border-b px-4 py-2 text-sm"
          role="alertdialog"
        >
          <p>
            The agent wants to delete{" "}
            <strong>{meeting === undefined ? `"${pending.eventId}"` : meeting.title}</strong>.
          </p>
          <div className="flex gap-2">
            <Button autoFocus onClick={() => pending.answer(false)} variant="outline">
              Keep it
            </Button>
            <Button onClick={() => pending.answer(true)} variant="destructive">
              Delete
            </Button>
          </div>
        </div>
      )}
      <Calendar.Root
        label="Team calendar"
        // Without this the calendar has no `deleteEvent` action, whatever `allow` answers.
        allowAgentDelete
        events={meetings}
        onEventChange={(change, detail) =>
          setMeetings((current) => applyChange(current, change, detail))
        }
        policies={[timedOnly]}
        defaultAnchorDate={Temporal.PlainDate.from("2026-10-08")}
        defaultTimeZone="Europe/Berlin"
        locale="en-US"
        weekRules={weekRules}
      >
        <Calendar.Frame className="flex min-h-0 flex-1 flex-col">
          <CalendarToolbar calendar={Calendar} />
          <Calendar.Viewport className="min-h-0 flex-1">
            <Calendar.ActiveView />
          </Calendar.Viewport>
        </Calendar.Frame>
      </Calendar.Root>
    </div>
  );
}

What happens for each answer:

The personThe stepYour onEventChange
Chooses "Delete"Succeeds. Its result is the change, with proposed: nullGets { cause: "delete", eventId }, input: "agent"
Chooses "Keep it"Fails with The app refused deleteEvent on c1.Isn't called
Doesn't answer in timeFails once timeout passes, and signal aborts so the question goesIsn't called

A few things to get right:

  • Say what will be deleted. args[0] is the step's input as the agent sent it, which should be { eventId }. allow runs before the calendar checks it, so eventIdOf reads it as unknown input. Look the event up and show its title, as the example does, since the person can't judge an ID.
  • Take the question down on signal. It aborts when the wait times out and when the turn is stopped. A question left on screen would answer a step that's already over.
  • Later calls wait. While allow is pending, act and query calls on the same bridge queue behind it. snapshot still answers.
  • The calendar is asked first. On a Root without allowAgentDelete a deleteEvent step fails before the bridge calls allow, so the person is never asked about a delete that can't run.
  • Your policies still run. After the person says yes, the delete is a proposal like any other. A policy can refuse it, and the agent's step fails with the policy's reason.
  • timeout is yours to choose. A step waits five minutes for allow when you don't set it.

A delete button of yours

An agent can press a ui-sdk button your app rendered, with a press step. When that button's handler proposes a delete, the delete is the agent's. Your policies and onEventChange get it with detail.input of "agent", whatever input the handler passed:

remove-meeting.tsx
"use client";

import { Button } from "@ui-sdk/react/button";

import { Calendar, type Meeting } from "./calendar";

// A button of your own, anywhere inside Root. It's a ui-sdk button, so an agent can press it.
export function RemoveMeeting({ meeting }: { readonly meeting: Meeting }) {
  const { proposeEventChange } = Calendar.useCalendarActions();

  return (
    <Button
      // A person's click proposes the delete as your code: `input: "api"`. An agent's press
      // proposes the same delete as the agent: `input: "agent"`.
      onClick={() => void proposeEventChange({ cause: "delete", eventId: meeting.id })}
    >
      Remove {meeting.title}
    </Button>
  );
}
  • Without allowAgentDelete, the calendar refuses it. The press succeeds as a step and deletes nothing. The proposal ends rejected with the reason agent-delete-not-allowed, your onEventChange isn't called, and onEventChangeResult hears the refusal with input: "agent". A person's click on the same button deletes as it did.
  • With allowAgentDelete, the press is what your allow has to hold. The step is press on a button, not deleteEvent on a calendar. The allow above refuses every component but the calendar, so it refuses this press. An allow that lets presses through would let this one delete without the question: ask the person for it as well, or put the button inside an element with data-agent-hidden, which keeps it from agents as Connect an agent does for a whole calendar.

The same holds for every change a pressed button proposes: a policy that refuses agents refuses it. Who made a change has the rule.

All of this is about a handler that proposes the delete before it returns. A button that waits first, for a confirmation dialog of its own or a request, proposes later, and by then the calendar can't tell the agent started it: the delete reads as "api" and goes through without allowAgentDelete. Keep a button like that from agents with data-agent-hidden, or refuse its press in allow.

Stopping a turn

When the person stops the agent while a question is open, pass an AbortSignal to act. The waiting step fails with deleteEvent on c1 was cancelled., allow's signal aborts so the question comes down, and the steps after it don't run:

agent-stop.ts
"use client";

import { agent } from "./agent-confirm";

let turn = new AbortController();

/** A delete the person can stop while its question is open. */
export function deleteEvent(eventId: string) {
  return agent.act(
    { steps: [{ ref: "Team calendar", action: "deleteEvent", args: [{ eventId }] }] },
    { signal: turn.signal },
  );
}

/** For your Stop button: ends the step that waits, and takes its question down. */
export function stop(): void {
  turn.abort();
  turn = new AbortController();
}

Undo instead of asking

Asking first isn't the only shape. For a calendar where a wrong delete is cheap to reverse, let the delete run and offer an undo: an event history with inputs: ["agent"] brings the deleted event back as it was. Keep the question for deletes your app can't take back, such as one that emails the guests.

Next, hand the tools to a browser's agent with WebMCP.

On this page