Agents in your app

Connect an agent

Create the agent bridge, name your calendar, and decide which actions an agent may run.

Live, in the browser's own styles. Pick what the agent may do, then send a call.

A calendar is reachable by agents once your app creates ui-sdk's agent bridge. The bridge lists the calendar, runs an agent's steps on it, and asks your allow before each one. This page sets that up. Its samples import the Calendar and Meeting that the Quick start puts in calendar.tsx, and the seed and weekRules in its app.tsx.

Create the bridge

The bridge comes from @ui-sdk/solid/agent. @ui-sdk/solid is one of the calendar's peer dependencies, so Installation already added it. Create one bridge for the whole app, in a module of its own:

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

// Once, in the browser. It finds the calendars already on the page and hears new ones.
export const agent = createAgent();

The bridge finds the calendars already on the page and hears new ones as they mount. It covers every ui-sdk component in your app, not only calendars. On the server it lists nothing, so the module is safe to import from a component that renders there.

Creating the bridge connects nothing to a model. It gives your code four methods:

MethodWhat it does
agent.snapshot()Lists every component on the page
agent.query({ within })Finds components, or the events one calendar shows. Resolves with the list
agent.act({ steps })Runs steps in order. Resolves with what each one did
agent.subscribe(listener)Calls listener when a component's state changes. Returns the function that stops it

You hand those to an agent in one of two ways: WebMCP for the agent built into a browser, or your own server for a model you run.

Name the calendar

An agent names a component by its label. Give Root a label, and make changes saveable with onEventChange:

agent-calendar.tsx
import { createSignal } from "solid-js";

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

export function AgentReadyCalendar() {
  const [meetings, setMeetings] = createSignal(seed);

  return (
    <Calendar.Root
      // The name an agent finds the calendar by. Without it, the title names the calendar, and
      // the title changes with every navigation.
      label="Team calendar"
      events={meetings()}
      // An agent's change arrives here like a drag does, and `detail.fields` has what the agent
      // sent beside the times, such as a title. Without a handler the calendar is read-only,
      // for agents too.
      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.Toolbar>
          <Calendar.PreviousTrigger>Previous</Calendar.PreviousTrigger>
          <Calendar.TodayTrigger>Today</Calendar.TodayTrigger>
          <Calendar.NextTrigger>Next</Calendar.NextTrigger>
          <Calendar.Title />
        </Calendar.Toolbar>
        <Calendar.Viewport>
          <Calendar.ActiveView />
        </Calendar.Viewport>
      </Calendar.Frame>
    </Calendar.Root>
  );
}

Without label, the calendar is named by its title, such as "Oct 5 – 11, 2026", and the title changes each time the agent navigates. With two calendars on a page, give each its own label.

The bridge finds a calendar by its Calendar.Frame. A Root that renders its views without a frame works for a person and isn't listed for an agent.

applyChange, titleFrom and timedOnly are this example's own. applyChange is what saving means here, and timedOnly is a policy that refuses an all-day meeting:

agent-save.ts
import type {
  CalendarEventChange,
  CalendarPolicy,
  CalendarProposalDetail,
} from "@moltenship/calendar-solid";

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

export type MeetingChange = CalendarEventChange<Meeting, string, never>;

/**
 * The title an agent sent with `createEvent` or `updateEvent`. The calendar passes `fields` on
 * as it got them, so check each one as you would a form's input.
 */
export function titleFrom(detail: CalendarProposalDetail | undefined): string | undefined {
  const title = detail?.fields?.title;
  return typeof title === "string" && title.trim() !== "" ? title.trim() : undefined;
}

// What saving a change means in this example: a new array of meetings.
export function applyChange(
  meetings: readonly Meeting[],
  change: MeetingChange,
  detail?: CalendarProposalDetail,
  id: string = crypto.randomUUID(),
): readonly Meeting[] {
  if (change.cause === "delete") {
    return meetings.filter((meeting) => meeting.id !== change.eventId);
  }
  if (change.proposed.kind !== "timed") return meetings;

  const interval = change.proposed;
  const title = titleFrom(detail);
  if (change.cause === "create") {
    // A create has times and no event: the app makes the meeting. An agent's `createEvent` can
    // name it; a slot a person drags out can't. An undone delete brings the deleted meeting.
    const meeting = change.event ?? { id, title: title ?? "New meeting" };
    return [...meetings, { ...meeting, interval }];
  }
  // A move, a resize, or an agent's `updateEvent`, which can bring a title with or without times.
  return meetings.map((meeting) =>
    meeting.id === change.eventId
      ? { ...meeting, title: title ?? meeting.title, interval }
      : meeting,
  );
}

// Meetings always have a time, so an all-day proposal is refused with a reason, not dropped.
export const timedOnly: CalendarPolicy<Meeting, string, never> = ({ proposed }) =>
  proposed === null || proposed.kind === "timed"
    ? { type: "accept" }
    : { type: "reject", reason: "meetings-need-a-time" };

Without onEventChange the calendar is read-only for agents as well. An agent can still read it and navigate. The actions that change an event leave its actions, and describeCalendar reports readOnly: true.

Save what the agent sent

The calendar knows when an event is and which resources it's on. Everything else about an event is your record's, so the calendar can't write it. An agent sends those values, and your handler stores them.

An agent's createEvent and updateEvent take two inputs for that: title, and fields, an object of whatever your events have.

{
  "ref": "Team calendar",
  "action": "createEvent",
  "args": [
    {
      "start": "2026-10-06T14:00",
      "end": "2026-10-06T15:00",
      "title": "Customer call",
      "fields": { "color": "green" }
    }
  ]
}

Your onEventChange gets them as detail.fields, with the title folded in:

// change.cause === "create", change.event === null, detail.input === "agent"
detail.fields; // { color: "green", title: "Customer call" }

What each change brings:

Stepchange.causechange.proposeddetail.fields
createEvent"create"The new event's times and resourcestitle and fields, when sent
updateEvent"update"The event's times, new or as they weretitle and fields, when sent
moveEvent"move"The new timesAbsent: the action takes no fields
resizeEvent"resize-start" or "-end"The new timesAbsent
deleteEvent"delete"nullAbsent

Three rules for the handler, which applyChange above follows:

  • Check every field. The calendar passes fields on as the agent sent them. It checks that fields is an object and title a string, and nothing inside: a value can be any type, nested to any depth. titleFrom takes a title only when it's a non-empty string; treat each field of yours the same way, as you would a form's input.
  • An update can bring fields alone. updateEvent with only a title proposes the event's current times, so keep storing change.proposed and read the title beside it.
  • A person's change has no fields. A drag, a resize and an undo arrive without detail.fields, so fall back to what the event had.

A policy gets the same detail as its second argument's detail, so a rule can read a field before anything is saved: refuse an agent's create without a title, or a title that's too long. The agent reads the policy's reason in the failed step.

What the handler doesn't store is dropped without a word to the agent. If your app takes only some fields from an agent, say which in the model's prompt, or refuse the others in a policy.

Try it from the console

Before any model is involved, call the bridge yourself. Put it on window in development:

main.tsx
import { agent } from "./agent";

// Vite sets `import.meta.env.DEV` in development.
if (import.meta.env.DEV) Object.assign(window, { agent });

Then, in the browser's console:

Console
agent.snapshot();
// [{ ref: "c1", component: "calendar", label: "Team calendar", view: "list", … }]

const calendar = { ref: "Team calendar" };

await agent.act({ steps: [{ ...calendar, action: "describeCalendar" }] });
// { ok: true, steps: [{ step: 0, ref: "c1", result: { today: "2026-10-06", views: […], … } }], … }

await agent.act({ steps: [{ ...calendar, action: "listEvents" }] });
// { ok: true, steps: [{ step: 0, ref: "c1", result: [{ id: "standup", title: "Standup", … }] }], … }

await agent.act({
  steps: [
    {
      ...calendar,
      action: "moveEvent",
      args: [{ eventId: "standup", start: "2026-10-09T10:00" }],
    },
  ],
});
// { ok: true, steps: [{ step: 0, ref: "c1", result: { changeId: "change-1", status: "saved", … } }], … }

An action takes one object, never a list of values. args: ["review", "2026-10-09T10:00"] fails, and the message says what the action takes:

calendar-agent-invalid-arguments: moveEvent takes { eventId: ID, start: ISO date or date-time, end?: same, resourceIds?: ID[] }; it takes one object, not 2 arguments

ref takes the calendar's label, its ref from the snapshot, or its kind, "calendar". A name that fits two components fails the step and lists both, so use the ref then. The calendar's ref depends on which other ui-sdk components are on the page. Its label doesn't.

In the object snapshot() returns, anchorDate is a Temporal.PlainDate. It becomes the string "2026-10-08" when the snapshot is sent as JSON, which is how a model gets it.

Decide what an agent may do

Without allow, a bridge runs every step. Pass allow to createAgent to decide step by step. This bridge reads a setting the person controls:

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

/** What the person lets the agent do, from a switch in your settings. */
export type AgentAccess = "read" | "navigate" | "edit";

// Reading the calendar's facts, its events and how a change ended. These are steps too, so a
// list of what's allowed has to name them, or the agent never learns an event's ID.
const reading: ReadonlySet<string> = new Set(["describeCalendar", "listEvents", "getChange"]);
const navigation: ReadonlySet<string> = new Set([
  "navigateNext",
  "navigatePrevious",
  "navigateToday",
  "goToDate",
  "setView",
  "selectEvent",
]);
const editing: ReadonlySet<string> = new Set([
  "createEvent",
  "updateEvent",
  "moveEvent",
  "resizeEvent",
]);

let access: AgentAccess = "navigate";

export function setAgentAccess(next: AgentAccess): void {
  access = next;
}

export const agent = createAgent({
  // Asked before every step, with the component the step resolved to. The bridge's own
  // `snapshot` and `query` aren't steps: they always answer.
  allow: ({ action, component }) => {
    if (component !== "calendar") return false;
    if (reading.has(action)) return true;
    if (navigation.has(action)) return access !== "read";
    // Never `deleteEvent` or `setTimeZone`, whatever the switch says.
    return access === "edit" && editing.has(action);
  },
});

The example at the top of this page sets that switch from three radio buttons. AgentSteps is the buttons and the answer, from Agents in your app:

agent-access.tsx
import { createSignal, For } from "solid-js";

import { AgentReadyCalendar } from "./agent-calendar";
import { agent, setAgentAccess, type AgentAccess } from "./agent-permissions";
import { AgentSteps, step, type AgentCall } from "./agent-steps";

const levels: readonly { readonly label: string; readonly value: AgentAccess }[] = [
  { label: "Read", value: "read" },
  { label: "Read and navigate", value: "navigate" },
  { label: "Read, navigate and edit", value: "edit" },
];

const calls: readonly AgentCall[] = [
  { label: "List the events in view", steps: [step("listEvents")] },
  { label: "Go to the next weeks", steps: [step("navigateNext")] },
  {
    label: "Move Standup to Friday at 10:00",
    steps: [step("moveEvent", { eventId: "standup", start: "2026-10-09T10:00" })],
  },
  { label: "Set the time zone to Tokyo", steps: [step("setTimeZone", { timeZone: "Asia/Tokyo" })] },
];

export default function AgentAccessPage() {
  const [access, setAccess] = createSignal<AgentAccess>("navigate");
  return (
    <AgentSteps agent={agent} calls={calls}>
      <fieldset>
        <legend>The agent may</legend>
        <For each={levels}>
          {(level) => (
            <label>
              <input
                checked={access() === level.value}
                name="access"
                onChange={() => {
                  setAccess(level.value);
                  setAgentAccess(level.value);
                }}
                type="radio"
              />
              {level.label}
            </label>
          )}
        </For>
      </fieldset>
      <AgentReadyCalendar />
    </AgentSteps>
  );
}

allow gets the step after the bridge found its component:

FieldContents
componentThe component's kind: "calendar" for a calendar
labelThe component's label, such as "Team calendar"
refThe component's ref, such as "c1"
actionThe action, such as "moveEvent"
argsThe input as the agent sent it, such as [{ eventId: "review", start: "…" }]
confirmThe text of a data-agent-confirm mark on the component, if it has one

Return true to run the step and false to refuse it. A refused step fails with a message the agent reads, and the steps after it don't run:

{
  "ok": false,
  "error": { "step": 1, "message": "The app refused moveEvent on c7." },
  "steps": [{ "step": 0, "ref": "c7" }],
  "appeared": [],
  "values": {}
}

Start from a list of what's allowed, as the example does, so an action added in a later version stays refused until you choose it. allow can also return a promise, which is how you ask the person first.

Put the reading actions on that list. describeCalendar, listEvents and getChange are steps like any other, and allow is asked for them. An agent that may move events and may not list them has no event IDs to move. allow sees args before the calendar checks them, so read them as unknown input.

A step isn't always one of the calendar's actions. An agent can also press a ui-sdk button of yours, as a step with the action press, and what its handler does to the calendar counts as the agent's: your policies and onEventChange hear input: "agent". The example's allow refuses every component but the calendar, so no button is pressed there. If yours lets presses through, decide them as carefully as the calendar's own actions, a delete button most of all.

allow covers steps. The bridge's own snapshot and query aren't steps: they answer whatever allow says, with the calendar's entry and the events in view. To keep a calendar from agents entirely, put data-agent-hidden on an element around it:

agent-hidden.tsx
import { seed, weekRules } from "./app";
import { Calendar } from "./calendar";

export function PrivateCalendar() {
  return (
    // Everything inside is left out of what an agent sees and can act on.
    <section data-agent-hidden>
      <Calendar.Root
        label="Private calendar"
        events={seed}
        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>
    </section>
  );
}

That calendar is left out of snapshot and query, and a step that names it fails with "Private calendar" isn't available to agents here. Ask the person.

allow is the first of three checks an agent's change passes. The second is your policies, which see the change itself: the event, where it would land, and who proposed it. The third is your onEventChange, which can refuse to save.

If the agent sees nothing

When agent.snapshot() returns [] while a calendar is on the page, a step fails with a message that starts No component "Team calendar" on the page. The usual cause is that the bridge and the calendar run on two copies of @ui-sdk/core. Each copy keeps its own list of components, so the bridge's copy never hears of the calendar.

Check these first:

  • A frame. The calendar renders Calendar.Frame inside Root. Without one it isn't listed.
  • One version. @ui-sdk/core and @ui-sdk/solid are installed once, at the same version. pnpm why @ui-sdk/core or npm ls @ui-sdk/core shows more than one when they aren't.
  • One import path for the bridge. Import createAgent from @ui-sdk/solid/agent, the adapter your calendar uses.
  • The dev server's pre-bundle. Vite pre-bundles dependencies in development. When one package that imports @ui-sdk/core is kept out of the pre-bundle and another isn't, the page loads the core twice. Solid's Vite plugin does that for @ui-sdk/solid. Keep the core out as well:
vite.config.ts
import { defineConfig } from "vite";

export default defineConfig({
  optimizeDeps: {
    // One copy of the core, unbundled, for the calendar and the bridge alike.
    exclude: ["@ui-sdk/core"],
  },
});

With two copies the calendar's own parts can stop following its state too, so a toolbar that no longer updates is the same problem. Check a new setup in the browser: mount a calendar, call agent.snapshot(), and expect one entry with component: "calendar".

Next, see who made a change.

On this page