Agents in your app

Agent reference

Every action an agent can call on a calendar, with its arguments, results and errors, and every field of the calendar's snapshot entry.

This page lists what a calendar gives ui-sdk's agent bridge. The guides start at Agents in your app.

Root props

Three props on Root are for agents:

PropTypeDefaultEffect
labelstringnoneThe calendar's name for agents: label in its snapshot entry. Without it, the title is the name
allowAgentDeletebooleanfalseGives the calendar its deleteEvent action. Without it, any delete an agent causes is refused
formatAgentEventLabel(event: CalendarAgentEvent) => stringnoneWrites each event's label in the snapshot's items, in place of the default

An agent's change also needs onEventChange, as every change does. A calendar is listed for agents only when it renders Calendar.Frame.

The bridge

The bridge is ui-sdk's, from @ui-sdk/solid/agent:

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

export const agent = createAgent({
  // Optional. Asked before every step; `false` refuses it.
  allow: ({ component, action }) => component === "calendar" && action !== "setTimeZone",
  // Optional. How long a step waits for a promise from `allow`, in milliseconds. 5 minutes by default.
  timeout: 60_000,
});
MemberWhat it does
agent.snapshot()Returns an entry for every component on the page
agent.query({ text?, within?, kind? })Resolves with the entries that match. within with a calendar's label returns it with the events in view
agent.act({ steps }, { signal? })Runs steps in order and resolves with the result. Stops at the first that fails
agent.subscribe(listener)Calls listener for each settled state change, an agent's or a person's. Returns the unsubscribe function
agentToolsThe definitions of snapshot, act and query for a model: { name, description, inputSchema }
registerTools(agent, { allow })Registers the three tools with WebMCP. Returns the unregister function

agentTools and registerTools are exports of the same entry as createAgent. On a server, import agentTools from @ui-sdk/core/agent.

subscribe reports changes to the calendar's state: view, anchorDate, timeZone, selection, focus and expandedResourceIds. It doesn't report events changing, since your app holds them. Use onEventChangeResult for those.

The three tools are the bridge's own and the same for every component. act's definition says a step has a ref, an action and args. It can't say what a calendar's actions take: that's in describeCalendar().actions, and in the message of a call that got it wrong.

Snapshot entry

FieldTypeContents
refstringThe bridge's handle, such as "c1". Stays with the calendar while it's on the page
component"calendar"The component's kind
labelstringRoot's label, or the calendar's title
actionsstring[]The actions this calendar offers now, in alphabetical order
viewstringThe active view's name
anchorDatestring, as "2026-10-08"The date the visible range is built around
timeZonestringThe IANA time zone times are shown in
selectionyour selection type, or nullWhat's selected
focusyour focus type, or nullWhat has keyboard focus inside the calendar
expandedResourceIdsarray of resource IDsThe expanded resource groups
items{ value: string; label: string }[]The events in the visible range. Absent when there are none
textstring[]The calendar's title, such as "Oct 5 – 11, 2026"
offPagetrueOnly on a calendar that left the page, which the bridge remembers for a while

Which actions a calendar offers:

Root hasactions
No onEventChangeThe ten that read, navigate and select
onEventChangeThose, and createEvent, updateEvent, moveEvent and resizeEvent: fourteen
onEventChange and allowAgentDeleteAll fifteen, with deleteEvent

A calendar lists all fifteen for one microtask after it mounts, and the ones it doesn't offer leave after that. A step for an action that isn't offered fails with the bridge's calendar c1 takes no deleteEvent now. It takes: ….

In items, value is the event's ID turned into a string. label is the event's title, a middle dot, and when it happens, in ISO 8601 and not in Root's locale:

EventLabel
TimedDesign review · 2026-10-08T15:00 to 2026-10-08T16:00 (Europe/Berlin)
All-day, one dayOffsite · 2026-10-06 (all day)
All-day, severalConference · 2026-10-06 to 2026-10-08 (all day). The last day is included
FloatingLunch · 2026-10-08T12:00 to 2026-10-08T13:00 (local time)

A timed event's times are wall-clock times in the calendar's time zone, which the label names. An event without a title has only the time. All-day events come first, then the rest by start.

An all-day label ends on the event's last day, and listEvents gives the same event an exclusive end: the conference above has "end": "2026-10-09" there.

formatAgentEventLabel replaces the label. It gets the event as listEvents describes it:

<Calendar.Root
  label="Team calendar"
  formatAgentEventLabel={(event) => `${event.title} (${event.start} to ${event.end})`}
  /* …the rest of your props */
/>

Keep ISO dates in it. A model reads 2026-10-08T15:00 back exactly, and a localized date it has to guess at.

selection and focus are your own values, sent as JSON. Keep them serializable if agents should read them.

In the object agent.snapshot() returns in the page, anchorDate is a Temporal.PlainDate. It becomes the string above once the snapshot is serialized, which every tool call does.

Actions

A step names the calendar by ref: its ref, its label, or "calendar". An action takes nothing, or exactly one JSON object as args[0]. An action that takes nothing accepts {} too. A second argument, a value that isn't an object, a key the action doesn't have, a null and a missing required key each fail the step with calendar-agent-invalid-arguments.

Reading

ActionInputReturns
describeCalendarnothingThe calendar's description
listEventsnothing, or { start?, end? }A list of events
getChange{ changeId }A change by its ID, as it is now

These change nothing and call no handler of yours. They're steps, so the bridge's allow is asked for each.

describeCalendar

FieldTypeContents
actionsRecord<string, string>Each action the calendar offers now, with its input as the tables on this page give it
conventionsstringHow dates, times, ranges and IDs are written, in a sentence for the model
todaystring, as "2026-10-06"Today in the calendar's time zone
nowstring, as "2026-10-06T11:42:07.512+02:00"The current time, with the calendar's time zone's offset
timeZonestringThe IANA time zone times are shown in
localestringRoot's locale
viewstringThe active view
viewsstring[]The names setView takes
anchorDatestringThe date the visible range is built around
visibleRange{ start, end } or nullThe dates in view. end is exclusive
resources{ id, parentId, title }[]Your resources, for resourceIds. Empty without any
selectedEventIdan event ID, or nullThe selected event, when the selection is the default kind
pendingChangeschangesThe changes being checked or saved now, a person's included
readOnlybooleantrue when Root has no onEventChange
canDeletebooleanWhether the calendar offers deleteEvent

today and now follow Root's now or clock prop when you pass one.

listEvents

Without input, the events of the visible range. With start, end or both, the events of those dates, in view or not; the one left out is the visible range's. Both are ISO dates, and end is exclusive. A start that isn't before the end fails with calendar-agent-invalid-range.

FieldTypeContents
idstring or numberThe event's ID as your adapter gives it. What eventId takes
titlestringThe adapter's title
kind"timed", "all-day" or "floating"How start and end are written
startstringSee below
endstringExclusive
resourceIdsarray of resource IDsThe resources the event is on
pendingtrueOnly while a change to the event is being checked or saved
readOnlytrueOnly on an event that can't be changed
kindstart and end
timedA date-time with the calendar's time zone's offset: "2026-10-08T15:00:00+02:00"
all-dayA date: "2026-10-06". One day on October 6 ends on "2026-10-07"
floatingA date-time without an offset: "2026-10-08T12:00:00"

The list has all-day events first and then the rest by start. It shows events as the calendar does, with pending changes applied. It has the adapter's fields and none of your record's others: what else an event holds is your app's to tell a model.

ActionInputEffectHandler on Root
navigateNextnothingMoves one range forward, by the active view's steponAnchorDateChange
navigatePreviousnothingMoves one range backonAnchorDateChange
navigateTodaynothingShows the range that holds todayonAnchorDateChange
goToDate{ date: "2026-10-09" }Shows the range that holds the dateonAnchorDateChange
setView{ view }: one of viewsSwitches the viewonViewChange
setTimeZone{ timeZone: "America/New_York" }Shows times in that zoneonTimeZoneChange
selectEvent{ eventId }: an ID, or nullSelects the event, or clears the selectiononSelectionChange

Each handler gets detail.source of "agent" and detail.reason of "imperative", with no detail.event. detail.cancel() keeps the value, and the step still succeeds, with no changes. That's for the actions in this table: when the agent presses one of the calendar's triggers instead, the handler gets the trigger's own reason, such as "next-press".

goToDate also takes a date-time and uses its date. setTimeZone changes how times are shown and moves no event.

selectEvent sets the selection to { kind: "event", eventId }, the calendar's default selection for an event. It writes that shape on a calendar with a selection type of its own as well. If yours differs, map it in onSelectionChange with selection controlled, or refuse selectEvent in allow.

Events

ActionInputProposes
createEvent{ start, end, title?, resourceIds?, fields? }cause: "create", with eventId: null and event: null
updateEvent{ eventId, title?, start?, end?, resourceIds?, fields? }cause: "update". Needs one key beside eventId
moveEvent{ eventId, start, end?, resourceIds? }cause: "move". Without end the event keeps its length
resizeEvent{ eventId, start } or { eventId, end }cause: "resize-start" or "resize-end". The other edge stays
deleteEvent{ eventId }cause: "delete". Offered only when Root has allowAgentDelete

Each is a proposal with detail.input of "agent": policies see it, and so do onEventChange and onEventChangeResult. Each returns a change.

eventId is an id from listEvents, or an item's value. A number ID matches as a number or as its string. Any event you passed to events can be named, in view or not.

title and fields are for your record. createEvent and updateEvent take them, and the other three don't. They reach your policies and your onEventChange as detail.fields: the fields object, with title in it as fields.title. The calendar checks that title is a string and fields an object, and that the title isn't given both ways. It checks nothing inside fields. Save what the agent sent has the handler.

updateEvent with start and no end keeps the event's length, as moveEvent does. With end alone the start stays. With neither, the event keeps its times, and the change still has them as proposed.

How start and end are read depends on the event:

Eventstart and endExamples
TimedA date-time. Without an offset it's wall-clock time in the calendar's time zone; with Z, an offset or a bracketed zone it's that exact moment"2026-10-09T10:00", "2026-10-09T08:00Z", "2026-10-09T10:00+02:00[Europe/Berlin]"
All-dayA date. The end is exclusive: one day on October 9 ends on October 10"2026-10-09"
FloatingA date-time without an offset"2026-10-09T10:00"

What listEvents returns for an event's start and end is valid input for them.

Dates are in the ISO calendar. A date or a time annotated with another calendar, such as "2026-10-09[u-ca=hebrew]", fails with calendar-agent-unsupported-calendar: the calendar doesn't convert it.

createEvent makes an all-day event when both start and end are dates, and a timed one otherwise.

resourceIds is a list of resource IDs from describeCalendar's resources. On a calendar that has resources, an ID that isn't one of them fails with calendar-agent-unknown-resource, which lists the ones there are. A calendar without resources doesn't check them.

A wall-clock time that a daylight saving change skips or repeats is resolved with Root's disambiguation, "compatible" by default.

Recurring events

With recurring events, each occurrence is an event of its own in listEvents, with the ID your expansion gives it, such as standup::2026-10-20T09:00:00Z. An agent names an occurrence by that ID.

Which occurrences a change covers is your app's choice, so it travels as a field. An agent sends it with updateEvent, the one action for an existing event that takes fields:

{
  "ref": "Team calendar",
  "action": "updateEvent",
  "args": [
    {
      "eventId": "standup::2026-10-20T09:00:00Z",
      "start": "2026-10-20T10:00",
      "fields": { "scope": "all" }
    }
  ]
}

Your handler reads detail.fields?.scope and applies the change to that occurrence or to the series, as it does for a person's choice in a dialog. moveEvent, resizeEvent and deleteEvent take no fields, so they act on the occurrence named, with your handler's default scope. After a change to a series, occurrence IDs can differ, and the agent calls listEvents again.

Results

act resolves with:

FieldContents
oktrue when every step ran
error{ step, message } for the step that failed. step counts from zero
stepsThe steps that ran: { step, ref, changes?, result? }
appearedComponents that came onto the page during the call
valuesThe values of form fields on the page. A calendar adds nothing here

What a calendar's step reports:

StepReports
Navigation or state, appliedchanges: [{ component: "calendar", label, key, value }], with key such as "anchorDate"
Navigation or state, cancelled or unchangedNeither changes nor result
describeCalendar, listEventsresult: the description, or the list
An event action, and getChangeresult: a change

A failed step stops the call. Steps before it stay applied.

A change

What createEvent, updateEvent, moveEvent, resizeEvent, deleteEvent and getChange return:

FieldTypeContents
changeIdstringNames the change on this calendar, for getChange
cause"create", "update", "move", "resize-start", "resize-end" or "delete"What was proposed
eventIdan event ID, or nullThe event. null for a create: your app makes the event and its ID
proposed{ start, end, kind, resourceIds }, or nullWhere the event lands, written as listEvents writes it. null for a delete
status"saved", "saving", "validating" or "rejected"Where the change is
reasonstringOnly with "rejected": one of the rejection reasons
statusWhen
savedYour onEventChange returned, or the promise it returned resolved
savingYour onEventChange returned a promise that hasn't settled
validatingA policy returned a promise that hasn't settled. Your onEventChange hasn't been called
rejectedA policy or your handler refused the change after the step had returned it

A refusal that comes at once never returns as a change: it fails the step. So a step's own result is saved, saving or validating, and rejected is something getChange reports.

saved means your handler took the change. It doesn't say your events prop has the event in its new place yet. listEvents reads your events with the changes still pending on top, so what it shows after the step depends on your handler:

Your onEventChangelistEvents after the step
Updates events before it returnsThe event in its new place
Returns a promiseThe new place, with pending: true while it saves and from events after
Returns nothing and updates events laterThe old place, until events changes

The third is a handler that starts a save and doesn't return its promise. The calendar takes a change for saved the moment such a handler returns, a person's drag included, so return the promise.

A new event is listed once your events has it. While a createEvent is saving, listEvents doesn't have the event yet.

A calendar keeps the last 50 changes agents proposed on it, for as long as it's mounted, and getChange reads those however they ended. It also reads any change that's still being checked or saved, a person's included, by the ID describeCalendar's pendingChanges gives it. Once a person's change has ended, the calendar no longer has it. getChange with an ID it doesn't have fails with calendar-agent-unknown-change and lists the agents' last ten.

Errors

A failed step's message starts with a code.

CodeWhenThe message also says
calendar-agent-invalid-argumentsThe input isn't one object with the action's keysWhat the action takes, and what was wrong
calendar-agent-invalid-dateA date isn't an ISO dateThe key, an example, and what was sent
calendar-agent-invalid-timeA time isn't an ISO date-timeAn example in the calendar's time zone, and what was sent
calendar-agent-invalid-time-zonesetTimeZone got something that isn't an IANA time zoneAn example, and what was sent
calendar-agent-unsupported-calendarA date or a time is in a calendar other than ISO 8601The calendar it names, and what was sent
calendar-agent-invalid-resourcesresourceIds isn't a list of strings or numbersWhat was sent
calendar-agent-unknown-resourceresourceIds has an ID that none of the calendar's resources hasThe first 20 resource IDs
calendar-agent-invalid-rangelistEvents got a start that isn't before its endWhat was sent
calendar-agent-unknown-eventNo event has that IDThe first 20 event IDs
calendar-agent-unknown-changegetChange got an ID the calendar doesn't haveThe last ten change IDs
calendar-unknown-viewsetView got a name that isn't registeredThe registered view names
calendar-event-change-rejectedA policy, the calendar or your handler refused the change at onceThe reason

What calendar-agent-invalid-arguments says after the code:

moveEvent takes { eventId: ID, start: ISO date or date-time, end?: same, resourceIds?: ID[] }; it takes one object, not 2 arguments
moveEvent takes { eventId: ID, start: ISO date or date-time, end?: same, resourceIds?: ID[] }; it has no "fields"
moveEvent takes { eventId: ID, start: ISO date or date-time, end?: same, resourceIds?: ID[] }; start is missing
goToDate takes { date: ISO date }; got "2026-09-01"
updateEvent changes something: { eventId: ID, title?: string, start?: ISO date or date-time, end?: same, resourceIds?: ID[], fields?: object }
resizeEvent takes one of start and end: { eventId: ID, start?: ISO date or date-time, end?: same }, one of start and end
give the title as title or as fields.title, not both

The bridge has messages of its own:

MessageWhen
The app refused moveEvent on c1.allow returned false
deleteEvent on c1 was cancelled.The signal passed to act aborted while the step waited
No component "Team calendar" on the page. Its labels: …Nothing has that ref, label or kind
calendar c1 takes no deleteEvent now. It takes: createEvent, …The calendar doesn't offer the action, or has no such one
"Private calendar" isn't available to agents here. Ask the person.The calendar is inside data-agent-hidden

Rejection reasons

What follows calendar-event-change-rejected: in a failed step, and what a rejected change has as reason:

ReasonMeaning
a policy's reasonA policy rejected the change, such as agents-book-weekdays-only
read-onlyThe event is read-only
unknown-eventNo event has the change's ID
agent-delete-not-allowedAn agent caused a delete on a Root without allowAgentDelete
invalid-placementThe range is empty or reversed, such as an end before the start
handler-errorYour onEventChange threw, or the promise it returned rejected
policy-errorA policy threw
supersededA newer change to the same event replaced this one

A failed step adds the thrown error's message in parentheses: calendar-event-change-rejected: handler-error (This slot was just taken). A rejected change's reason is the reason alone.

The calendar's own actions look the event up before they propose, so a step that names a missing event fails with calendar-agent-unknown-event, which lists the IDs there are. unknown-event is what your onEventChangeResult gets for a proposal made another way, such as a button of yours that proposes a change to an event that's gone.

Who made a change

WhereFieldValues
State handlers, such as onViewChange(view, detail)detail.source"agent", "mouse", "touch", "pen", "keyboard", "virtual", "programmatic"
onEventChange(change, detail)detail.input"agent", "pointer", "keyboard", "api"
onEventChangeResult(result, detail)detail.inputThe same
A policy's second argument, { detail }detail?.inputThe same
A history step, from useCalendarHistory(history).pastinputThe same

The same detail has fields for an agent's createEvent or updateEvent that sent a title or fields, and no fields key otherwise.

An undo or redo also has detail.history, "undo" or "redo", and its input is "api" unless you pass another to undo({ input }).

Anything a step causes is the agent's, not only the calendar's own actions. When an agent presses a ui-sdk button of yours and its handler calls proposeEventChange, an action such as setView, or a history's undo, your policies and handlers hear "agent", whatever input your code passed. That holds for what the handler does before it returns: a call it makes after an await, in a timer or in an effect reads as your own code, as Who made a change explains. A delete an agent causes that way is refused on a Root without allowAgentDelete, as Deleting describes.

A person's keys report "keyboard" in a state handler: arrow-key navigation, moving focus between cells and events, and expanding or collapsing a resource. "programmatic" is left for calls your own code makes.

Each of an agent's proposals reaches onEventChangeResult once, however it ends: committed, or rejected with the reason, a policy's refusal included.

What isn't there yet

  • Tool definitions for the actions. The bridge's act can't describe an action's input. A model learns it from describeCalendar().actions or from a failed call's message.
  • A dry run. An agent can't ask whether a change would be accepted. It proposes the change and reads the refusal.
  • A selection of your own shape from selectEvent. It writes { kind: "event", eventId } whatever selection type the calendar has, and selectedEventId reads only that kind.
  • A settled list of actions at mount. A calendar lists every action for one microtask after it mounts, before the ones it doesn't offer leave.
  • Your record's other fields in listEvents. It has the adapter's ID, title, times and resources.
  • The new event's ID from createEvent. The change has eventId: null, and the agent finds the event with listEvents.
  • Event changes in subscribe. It reports state. onEventChangeResult reports events.

Types

The actions' TypeScript types are in @moltenship/calendar-primitives, for code that wraps the bridge or builds on the calendar's ui-sdk primitive. Apps don't have that package as a direct dependency, so install it to import from it:

pnpm add @moltenship/calendar-primitives
agent-actions.ts
import {
  calendarAgentActions,
  type CalendarAgentApi,
  type CalendarAgentChange,
  type CalendarAgentDescription,
  type CalendarAgentEvent,
} from "@moltenship/calendar-primitives";

// The fifteen action names. A snapshot lists the ones a calendar offers, in alphabetical order.
export const actionNames: readonly (keyof CalendarAgentApi)[] = calendarAgentActions;

/** What `describeCalendar`, `listEvents` and an event action return, for code that reads them. */
export interface CalendarReads {
  readonly description: CalendarAgentDescription;
  readonly events: readonly CalendarAgentEvent[];
  readonly change: CalendarAgentChange;
}

Apps don't need them: an agent calls the actions by name through the bridge, and TypeScript infers the CalendarAgentEvent that a formatAgentEventLabel written inline takes.

On this page