Agents & WebMCP
An agent that drives a page through the accessibility tree reads every element, clicks a trigger, waits for a popup, reads it again and clicks once more. The agent bridge in reka-ui/agent gives it three tools instead — snapshot, query and act — that read each component's state and change it through the component's own model, the same path a click or a key press takes. A whole task, like filling in a settings page and saving it, fits in one act call.
The bridge is opt-in. Nothing in it runs, and components do no extra work, until you create one.
The tools follow the shapes of the UI SDK agent bridge: the same names, inputs, outputs and descriptions. Agents and skills written for it work on a Reka UI page unchanged.
Setup
Create the bridge before app.mount(). Components announce themselves to the bridge as they are set up, so components mounted before it exists aren't seen (native fields and buttons are, since the bridge reads those from the page). A bridge created later fails safe: content that a portal moved out of the app and that no known portal claims is treated as data-agent-hidden, and development builds warn.
import { createAgent, registerTools } from 'reka-ui/agent'
import { createApp } from 'vue'
import App from './App.vue'
const agent = createAgent({
// Decide each step an agent asks to run. Return false (or a promise of false) to refuse it.
allow: step => (step.confirm ? window.confirm(step.confirm) : true),
})
// Give the tools to the browser's own agent through WebMCP. A no-op where the browser has none.
registerTools(agent, {
// A press's `args` hold the whole text of the button it resolved to, like "Cancel my subscription" for "Cancel".
allow: step => step.action !== 'press' || window.confirm(`Let the assistant press "${step.args?.[0] ?? step.label}"?`),
})
createApp(App).mount('#app')The same with the Vue plugin, which creates the bridge when the app is set up, provides it to useAgent() and removes it on app.unmount():
import { AgentPlugin } from 'reka-ui/agent'
createApp(App)
.use(AgentPlugin, { webmcp: { allow: () => true } })
.mount('#app')To drive the page with your own model, pass a tool call straight to the bridge: the three methods take the tools' inputs and return their outputs.
import { agentTools } from 'reka-ui/agent'
// Hand `agentTools` (name, description, inputSchema) to your model API, then:
const output = await agent[call.name](call.input)Tools
| Tool | Input | What it does |
|---|---|---|
act | { steps: [{ ref, action, args? }] } | Runs steps in order and stops at the first that fails. A step names a component by ref, label, row text or kind, and finds it behind closed tabs and accordion sections. Returns what each step changed and every field's value after. |
query | { text?, within?, kind?, closed?, from? } | Finds components and list items without listing the page. within reads a list's items, 50 at a time with from. closed: true opens closed tabs and sections one at a time to read them, then goes back. |
snapshot | {} | Lists the components on the page: ref, component, label, row, state (value, checked, open…), items when there are 10 or fewer (more otherwise), buttons, disabled and actions. Components that left the page follow with offPage: true. |
Refs (c1, c2, …) stay the same while a component is mounted, and a component that comes back, like a field on a tab you return to, gets its old ref again.
await agent.act({
steps: [
{ ref: 'Project name', action: 'setValue', args: ['Atlas'] },
{ ref: 'Visibility', action: 'setValue', args: ['Internal'] },
{ ref: 'Priya Shah', action: 'press', args: ['Make admin'] }, // opens her row's menu first
{ ref: 'Email > Deploy failures', action: 'setChecked', args: [true] }, // opens the tab and section
{ ref: 'Save settings', action: 'press' },
],
})A step fails when its change didn't take, for example when a controlled v-model doesn't accept the value within about a second, when a number is outside the component's min/max, or when a choice names no item of the list.
agent.subscribe(listener) reports every change to a component, with source: "agent" for the ones a step made.
Supported components
| Component | Agent kind | State | Actions |
|---|---|---|---|
| Checkbox | checkbox | checked | setChecked, toggle |
| Switch | switch | checked | setChecked, toggle |
| Toggle | toggle | pressed | setPressed, toggle |
| RadioGroup | radio-group | value, items | setValue |
| ToggleGroup | toggle-group | value, items | setValue, toggle |
| Select | select | value, open, items | setValue, setOpen |
| Combobox | combobox | value, open, query | setValue, setOpen, setQuery, clear |
| Listbox | listbox | value, items | setValue (clear when multiple) |
| Tabs | tabs | value, items | setValue |
| Accordion | accordion | value, items | setValue, open, close, toggle (openAll, closeAll when multiple) |
| Collapsible | collapsible | open | setOpen |
| Slider | slider | value, min, max, step | setValue, increment, decrement |
| NumberField | number-field | value, min, max, step | setValue, increment, decrement, clear |
| TagsInput | tags-input | value | setValue, add, remove, clear |
| PinInput | pin-input | value (always "[redacted]" when filled) | setValue, clear |
| Dialog, AlertDialog | dialog, alert-dialog | open, text, buttons | setOpen, press |
| DropdownMenu | menu | open, buttons | setOpen, press (opens the menu to press an item) |
| Popover | popover | open, buttons | setOpen, press |
<input>, <textarea> | input, textarea | value | setValue, clear |
<input type="checkbox"> | checkbox | checked | setChecked, toggle |
<select>, radio inputs | select, radio-group | value, items | setValue |
<button> | button | press |
Native fields are set the way typing does — the value, then input and change events — so v-model hears them. A Combobox only knows its items while it is open: a setValue with an item's label opens it for a moment to read them, asking allow first. Components that aren't listed are read through their native elements where they have them.
The bridge sees components from reka-ui, not yet from the experimental reka-ui/vapor entry: on a Vapor page it creates fine and the components work as usual, but they aren't listed, only the native fields and buttons they render.
A component that is disabled, read-only, inside a disabled <fieldset> or an inert element, or behind an open modal dialog or menu reports disabled: true and no actions, and a step that names something behind an open modal fails with the modal's name and buttons.
Marks
Write these attributes on any element to decide what agents may see and do there:
| Attribute | Effect |
|---|---|
data-agent-hidden | Agents never see what is inside. A step that names something inside gets the same answer as a name that isn't on the page, so a guess can't learn it's there. On a list's item, the item is left out, and when it is the chosen one the list reports it as not chosen (null, or left out of a multiple value) and isn't named by it. A Combobox learns which items are hidden the first time it opens. On a list's content part, like SelectContent or ComboboxContent, the mark covers every item, while the list is closed too. |
data-agent-secret | Values inside read "[redacted]" when filled (a checkbox, switch or toggle reads "[redacted]" whether on or off), item labels of lists inside read "[redacted]", and text inside is never read: not as a label, a row (the text beside a component in its list item or table row), a section name, a title, a button or through aria-labelledby from elsewhere. Name a private control with aria-label or a <label> outside the mark; a private component is never named by what it shows, like a select's chosen item. A list whose items sit inside the mark is private as a whole, and so is one whose content part (SelectContent, ComboboxContent) or any native <option> carries it. Password, one-time-code and card fields, and every PinInput, are treated the same way without the attribute, and so is a field that was a password when the bridge saw it, after a show toggle or a swap to a text field with the same id or name. |
data-agent-confirm="What it does." | A change or press inside needs a person. Without allow the step fails with Needs a person: "What it does."; with allow, allow receives the sentence as step.confirm and decides. A change that touches several marked items gets every sentence. On a list's content part, every item's change asks, while the list is closed too. |
<section data-agent-hidden>…</section>
<input v-model="apiKey" data-agent-secret>
<div data-agent-confirm="Deletes the project for everyone.">
<button @click="deleteProject">Delete project</button>
</div>Security notes
- Labels, text and items come from the page and can hold what its users wrote: an agent should treat them as data, never as instructions.
registerToolssends the WebMCP spec's tool annotations:untrustedContentHinton every tool,consequentialHintonactandreadOnlyHintonsnapshot. What a browser does with them is up to the browser, and some keep only part of them, so don't rely on a browser to show or act on them. registerToolsrequiresallow, because the browser's agent isn't one you wrote. It runs aftercreateAgent's ownallow, and both must agree.allowalso decides when a step opens a closed tab or section to look behind it.actandqueryrun one at a time, so while a step waits onallow— a confirm the person has to answer — no other call can press that confirm.timeout(5 minutes by default) fails a step whoseallowdoesn't answer, so a forgotten prompt doesn't hold every later call.- Mark destructive actions with
data-agent-confirmand anything private withdata-agent-hiddenordata-agent-secret. The bridge only reaches what a person could reach on the page: nothing behind an open modal, nothing disabled. - Marks follow components, not where their content lands: a mark around a Dialog, Popover, menu, Select or any other component also covers the content its portal renders in
bodyor in a customto, popups inside popups included. This holds for Reka UI's portals, including ones mounted after the bridge and ones that outlive a destroyed bridge. Content outside the Vue app that no Reka UI portal claims, like what Vue's own<Teleport>moved intobody, is treated asdata-agent-hidden, so an agent never sees content it can't place. - One rule decides what an agent may know of a component, on every path —
snapshot,query(text,within,closed),act, error messages andsubscribe: it must show on the page (not insidehiddenoraria-hidden="true"), and nothing of it may be insidedata-agent-hidden. Items follow the same rule — a tab, section, radio, option or toggle withhiddenoraria-hidden="true"is neither listed nor picked — and a private list's sections are never opened to look behind. Text hidden with CSS, likev-show, is never read into a label or a row.aria-hiddenthe app wrote stays hidden while a modal hides the rest of the page from screen readers. - Marks around the host of a shadow root cover an app mounted inside it, and the bridge finds native fields in the shadow roots its components live in.
- Vue's own
<Teleport>to a target inside the app moves its content to where it lands: the marks around that place apply, not the marks around the<Teleport>. Put the mark inside the teleported content, or use Reka UI's portals, whose content keeps the marks of where the component sits. - Every action checks its arguments before it changes anything: how many it takes and of what shape. A single list (Tabs, RadioGroup, a single Accordion or ToggleGroup, Select, Listbox) takes one item and never a list; a multiple list takes a list of items, never a nested one;
open,closeandtoggleon a list, and a TagsInput'saddandremove, take one item;clear,openAll,closeAll,incrementanddecrementtake none. A list that always holds an item, like Tabs or RadioGroup, can't be set to nothing. An item is of the kind the list's items are — a TagsInput takes text tags — and text always fits, since a snapshot gives values as text. Numbers are finite decimals, as numbers or text like"90": neverInfinity,NaN,"0x10"or text too large to hold, for a NumberField, a Slider or a native number or range field. - A native date, time, color, range or number field that won't take a value, like
"tomorrow"in a date field, keeps the one it had, and the app hears nothing. A field'smaxlengthholds for an agent as for typing. - A change that takes out a chosen item that isn't rendered now, like one a filter or a virtual list leaves out, is held to the mark that item had when the agent last saw it. If it was never shown, its marks aren't known, and a Combobox or Listbox change that would take it out fails with a message that it needs the list unfiltered.
- A chosen item that is hidden stays chosen through a change or a
clearof a multiple list or TagsInput, since the agent can't name it to keep it:cleartakes out the rest. Changes that don't touch it go ahead. - Every change is checked against its marks right before it's made, after any wait on
allow. A step stops if its target has left, become off-limits, gone behind a modal, or gained a mark the person wasn't shown. The same applies to each item a multi-item change picks, opens or closes, including the itemsclear,openAllandcloseAlltouch.openAllandcloseAllleave disabled sections as they are. - An action that does what one of the component's own buttons does is held to that button's marks:
incrementanddecrementto the NumberField's increment and decrement buttons, a TagsInput'sremoveto that tag and its delete button,clearto the clear button (TagsInput, Combobox), andsetOpen(false)on a dialog, popover or menu to the confirm marks of every button inside it. A marked button asks a person; for the controls an action does the work of, a hidden one makes the action unavailable and a disabled one makes it fail. Closing a popup presses none of its buttons, so a hidden or disabled one inside doesn't stop it. - A Combobox's items show only while it is open, so every change of its value,
clearincluded, opens it for a moment to read them and their marks first, askingallowbefore it opens. - A step that opens a closed tab or section to look behind it checks the place again after
allowanswers, and doesn't open it if it gained a mark, was hidden or changed meanwhile. - A Listbox or Combobox choice clicks its item, so a
selecthandler that callspreventDefault()stops an agent the same way it stops a person. - A private list's item values stay visible, so an agent can still pick one by value; only their labels are redacted. Values are often IDs or email addresses: when they are sensitive themselves, use
data-agent-hiddeninstead. - Failures on a private component read the same whatever the reason, like a missing item, a disabled choice or a bound, so an error never says what it holds. A change to one always reports
"[redacted]", even when the value was already what was asked, and a mark on any of its items asks a person for every change, so neither tells which item is chosen. - Only what an agent could see is remembered when a component leaves the page: a component hidden or marked when it leaves keeps nothing, and a native field that left before the bridge could check it keeps what it held when the agent last saw it.
- A component's parts are the elements it rendered, never other page content that happens to carry the same
id. - Marks only cover what is inside them, and names come from the page: content users write can add a
<label for>that names another field. A step that then names two fields alike fails as ambiguous rather than picking one, but don't let user content sit beside fields an agent operates without a mark. - A private component offers only the actions whose outcome says nothing of what it holds: a private NumberField takes
setValueandclear(noincrement/decrement), a SlidersetValue, a TagsInputsetValueandclear(noadd/remove), an AccordionsetValue, and a ComboboxsetValue,setOpenandclear(nosetQuery, whose filter would test its labels). - A press, and each item a change picks, is checked again after
allowanswers: a button or item the page renamed meanwhile, like an unkeyed list that re-rendered, stops the step instead of pressing what it became. - Pressing an open dialog's or popover's own trigger closes it, so it is held to the marks of the buttons inside, as
setOpen(false)is. A native<dialog>opened withshowModal()covers the rest of the page like a modal Dialog does. - A popup's
buttonsleave out other components' own controls, like a Select trigger inside a dialog, which is listed as itself. - While a Select's chosen item is hidden or private, or the Select is, what its trigger shows is never read as text: not in a neighbour's row, a
querytext match or the buttons an error lists. - A native radio group that spans an open modal picks no radio behind it.
presstakes a button's text or nothing: empty text, which every unnamed button would match, fails.allowreceives a press with the whole text of the button it resolved to instep.args, not the words the agent gave, so "Cancel" that matched "Cancel my subscription" reads as the latter. A button whose whole text matches is preferred over one that only contains the words.- All bridges on a page take turns: an
actorqueryon one waits for every earlier call on any bridge.destroy()makessnapshotandqueryreturn[]andactfail, stops a step waiting onallowbefore it changes anything, and takes back the toolsregisterToolsgave the browser. Create one bridge per page. - A
PinInput's boxes are private even to a bridge created after it mounted. - One
actcall runs at most 100 steps, andqueryrefuses inputs of the wrong type. - A change to a private field is checked like any other: one that doesn't take fails, and the error never says what the field holds.
- Without a page, as during server rendering,
snapshotandqueryreturn[]andactfails withNo page, so the bridge can be created in shared setup code.
