Agent Tools

Lets agents in the browser read the page and act through the same controls people use.

Invoice PDF shows last month's address

Halcyon Health · Open

Installation

pnpm dlx shadcn@latest add checkfu/uicontext/agent-tools

Usage

import * as AgentConfirm from "./ui/uicontext/components/agent/AgentConfirm.ts"import * as AgentPage from "./ui/uicontext/components/agent/AgentPage.ts"
const allow: AgentPage.AllowList = {	actions: [		"SupportTicket.PickedStatus", // agents may change a ticket's status		"Inbox", // and read the inbox, without acting on it	],}const root = document.getElementById("app")!BrowserHost.mount(SupportTicket, { agentId: "ticket-4821" }, root).pipe(	Layer.provide(AgentPage.layer({ allow })),	Layer.provide(AgentConfirm.layer()),	Layer.launch,	Effect.runFork,)

Examples

What agents can't do

Agents get a plain error, never an exception: an action the allow list leaves out, an input that doesn't fit, a change that changes nothing.

Invoice PDF shows last month's address

Halcyon Health · Open

Wiring it to your app

Give each component agents can use a stable ID, and list the actions they may take. Agents find actions with page_snapshot, read their inputs with page_query, then call page_act.

Mount one AgentConfirm dialog, with its policy, below the page layer. A task that must confirm its target takes the action's input and the target it saw separately. Pass an AbortSignal to cancel a pending tool call.

View a complete app example
import "@w3c/webmcp-polyfill/auto"import { BrowserHost, Html } from "@effect/ui/html"import { Effect, Layer, Schema } from "effect"import { Notes } from "./notes.ts"import { SaveWorkflow, Workflows } from "./workflows.ts"import { AgentConfirm, layer as confirmLayer } from "./ui/uicontext/components/agent/AgentConfirm.ts"import { layer as pageLayer, type TaskTool } from "./ui/uicontext/components/agent/AgentPage.ts"import "./base.css"const App = Html.component({ name: "ContractExamples", model: Schema.Null, message: Schema.Never }).make({	init: () => null,	update: {},	view: (h) => h.div.attr("class", "contract-examples").children(		h.h1.children("Controlled interfaces"),		Notes(h, {}),		Workflows(h, {}),		AgentConfirm(h, {}),	),})const archiveSelection: TaskTool = {	name: "archive_selection",	title: "Archive selected workflows",	description: "Archive exactly the selected workflow rows after a person reviews the selection.",	target: { id: "workflows", action: "ClickedAction" },	input: Schema.Struct({ action: Schema.Literal("archive") }),	targetAcknowledgement: "explicit",	consequential: true,}const root = document.querySelector("main")if (root === null) throw new Error("Missing example root.")const main = BrowserHost.mount(App, {}, root).pipe(	Layer.provide(SaveWorkflow.layer),	Layer.provide(pageLayer({		allow: {			actions: ["Table.CommittedEdit", "Table.RequestedSelection"],			tasks: [archiveSelection.name],		},		tasks: [archiveSelection],	})),	Layer.provide(confirmLayer()),)Effect.runFork(Layer.launch(main))
entry.ts on GitHub

Accessibility

  • Agents in the browser get three tools: page_snapshot lists what's on the page and the actions they may take, page_query lists a component's choices, and page_act acts as a person would.
  • Nothing is allowed until the app's allow list names it, and every action goes through the same controls and checks a person's click does.
  • A consequential action names the exact state it applies to, and a person confirms it before it runs.

Source