An agent operating a canvas UI, drawn as it happens
A booking form drawn through a shader, leaning in perspective. It offers three tools to an agent. Press "Run the scripted agent", or type a request: each tool call turns the panel to face you, moves a marker to the field and types into the real input.
Show the code tools for an agent, and a shader that shows each call
- An ordinary form with one attribute.
fx="agent"draws it through the shader below. It's still a form: you can fill it in by hand. - The tools. Three functions with a name, a description and a JSON schema. Each returns when its animation is over.
- Give the tools to the browser's agent.
navigator.modelContextis WebMCP. Both spellings of the registration call are tried. - Show a call: four custom properties. The tool writes the lean and the marker position to the form's style.
- CSS transitions move them. The properties are registered as numbers, so they animate.
- The shader reads them as uniforms.
geometry()returns the perspective matrix for hit testing; the fragment function draws the form, dims it away from the marker and draws the rings. GLSL and WGSL. - A request in words, with the Prompt API. The model answers with JSON constrained to the tool names.
- Without a model: a pattern matcher.
- Ask the model what it sees. The picture is taken from the canvas after the shader has run.
- The whole tools file.
What the model sees
The button takes the picture that the canvas shows, after the shader, and gives it to the Prompt API with a question. Without a model that accepts images, the picture is still taken and shown here, and the answer line says what is missing.
How it works
The form is one drawable element. fx uploads it to a texture on every paint and a
fragment shader draws it, with WebGPU when that works and WebGL otherwise. The shader has no state of its own: the lean and the marker
position are CSS custom properties on the form, and the tool code only changes those properties and the form's values.
ariaNotify() announces each step, because a marker drawn by a shader isn't in the accessibility tree.
The same three tool objects are used by every caller on this page: the browser's agent through WebMCP when
navigator.modelContext exists, the scripted run, the Prompt API planner and the pattern matcher. The log names the caller of each
call.
Live checks
| Result | Experiment | Detail |
|---|
Findings
- The canvas can show what an agent does with no extra state. A tool call sets four custom properties and the input's value. CSS transitions animate the properties and the shader reads them each frame. The tool's promise resolves after the animation, so an agent is paced by what the reader sees.
- Typing by a tool goes into the real input. The value is set one character at a time with an
inputevent for each, and the element repaints into the texture each time. The tool doesn't callfocus(), so it doesn't take the keyboard from the reader. - The form takes clicks where it is drawn while it leans. The effect's
geometry()matrix goes toupdateElementGeometry(), and the live check finds four controls withelementFromPoint()at their drawn positions, within 3 px of where the matrix puts them. navigator.modelContextis missing from the test browser (headless Chromium 157), so registration with WebMCP hasn't been run. The code triesregisterTool()and thenprovideContext(). Which one Chrome 159 has, and what the agent passes toexecute(), isn't verified.- The Prompt API couldn't be run either.
LanguageModel.availability()reports "downloadable" in the test browser and nothing can be downloaded there.prompt()with aresponseConstraintresolved with a sentence that starts "On-device" instead of JSON, so the page fell back to the pattern matcher. The planner and the image prompt are written from the specification and aren't verified with a model. - A form control must not be named
length.form.elements.lengthis the number of controls, so a field with that name can't be reached by name. The boat length field is namedboat_length. - The picture for the model is the shaded one. It is copied from the canvas, so it includes the lean, the dimming and the marker. A model reading it sees what the reader sees, which isn't the same as the DOM.
- Not verified: everything that needs the WebMCP flag or origin trial, the on-device model on a phone, and WebGPU on screen (the test browser has no adapter that can present).