Agents in your app

Deleting

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

Live, in the browser's own styles. Send the delete, then answer the question.

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 in the Quick start's calendar.tsx, the seed and weekRules in its app.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 signal and resolves when the person answers:

agent-confirm.ts
import { createAgent } from "@ui-sdk/solid/agent";
import { createSignal } from "solid-js";

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

const [request, setRequest] = createSignal<DeleteRequest | null>(null);

/** The request on screen, as an accessor. */
export const deleteRequest = request;

/** 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 signal:

agent-confirm-calendar.tsx
import { createSignal, onCleanup, Show } from "solid-js";

import { deleteRequest } from "./agent-confirm";
import { applyChange, timedOnly } from "./agent-save";
import { seed, weekRules } from "./app";
import { Calendar } from "./calendar";

export function ConfirmingCalendar() {
  const [meetings, setMeetings] = createSignal(seed);
  const titleOf = (eventId: string) =>
    meetings().find(({ id }) => id === eventId)?.title ?? `"${eventId}"`;
  // The calendar left the page with a question open: the answer is no.
  onCleanup(() => deleteRequest()?.answer(false));

  return (
    <>
      <Show when={deleteRequest()}>
        {(pending) => (
          <div role="alertdialog" aria-label="The agent asks to delete a meeting">
            <p>
              The agent wants to delete <strong>{titleOf(pending().eventId)}</strong>.
            </p>
            <button type="button" autofocus onClick={() => pending().answer(false)}>
              Keep it
            </button>
            <button type="button" onClick={() => pending().answer(true)}>
              Delete
            </button>
          </div>
        )}
      </Show>
      <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>
          <Calendar.Viewport>
            <Calendar.ActiveView />
          </Calendar.Viewport>
        </Calendar.Frame>
      </Calendar.Root>
    </>
  );
}

The example at the top of this page is that calendar and two calls. AgentSteps is the buttons and the answer, from Agents in your app:

agent-delete.tsx
import { agent } from "./agent-confirm";
import { ConfirmingCalendar } from "./agent-confirm-calendar";
import { AgentSteps, step, type AgentCall } from "./agent-steps";

const calls: readonly AgentCall[] = [
  { label: "List the events in view", steps: [step("listEvents")] },
  { label: "Delete Standup", steps: [step("deleteEvent", { eventId: "standup" })] },
];

export default function AgentDeletePage() {
  return (
    <AgentSteps agent={agent} calls={calls}>
      <ConfirmingCalendar />
    </AgentSteps>
  );
}

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
import { Button } from "@ui-sdk/solid/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(props: { readonly meeting: Meeting }) {
  const actions = 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 actions.proposeEventChange({ cause: "delete", eventId: props.meeting.id })
      }
    >
      Remove {props.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
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