Make Your Search Page Agent-Ready

AI agents are starting to search and shop on websites: a site's own assistant, or the visitor's agent in the browser. Most of them work a page the way a person does, from screenshots or the page's accessibility tree, finding the search box, typing, finding the filters, clicking. That takes many steps and many tokens, and it breaks when the page changes.

With intrface, your search page can tell an agent what is on it as data instead: the search text, each facet's values with their counts, the order, and the results by name, with what the agent may do to each. The agent reads the page in one call and searches, filters and sorts in one more. It changes the page the way a person does, so your statistics count what it picks and Search or ask sees the same page.

It is built on UI SDK's agent bridge, which is in beta, so this is experimental too.

Looking for agents that search your data directly, without a page? That is the server's MCP endpoint: Using Indx for AI Agents.

Install

intrface 4.0 (beta), and UI SDK beside it:

bash
npm install @indxsearch/intrface@beta @ui-sdk/core@0.1.0-beta.17 @ui-sdk/react@0.1.0-beta.17

The agent parts are their own entry point, @indxsearch/intrface/agent. A page that does not import it loads none of UI SDK.

Wrap the page

Put SearchAgent around the page, inside your SearchProvider, and each part you want agents to see in its wrapper. The parts keep their look.

tsx
import { SearchProvider, SearchInput, ValueFilterPanel, RangeFilterPanel, SortByPanel, SearchResults } from '@indxsearch/intrface';
import { SearchAgent, AgentSearchText, AgentFacet, AgentRange, AgentSort, AgentResults } from '@indxsearch/intrface/agent';

export function Search() {
  return (
    <SearchProvider url={url} team={team} dataset="products" preAuthenticatedToken={searchKey}>
      <SearchAgent browser={{ allow: () => true }}>
        <AgentSearchText><SearchInput /></AgentSearchText>
        <AgentFacet field="brand" label="Brand"><ValueFilterPanel field="brand" label="Brand" /></AgentFacet>
        <AgentRange field="price" label="Price"><RangeFilterPanel field="price" label="Price" /></AgentRange>
        <AgentSort><SortByPanel /></AgentSort>
        <AgentResults title={product => product.name}>
          <SearchResults>{product => <h3>{product.name}</h3>}</SearchResults>
        </AgentResults>
      </SearchAgent>
    </SearchProvider>
  );
}

What an agent sees of it, for example:

json
[
  { "ref": "c1", "component": "search", "label": "Search", "value": "lamp", "actions": ["setValue"] },
  { "ref": "c2", "component": "facet", "label": "Brand", "value": [], "actions": ["setValue", "toggle"],
    "items": [{ "value": "Nordform", "label": "Nordform (12)" }, { "value": "Tre", "label": "Tre (7)" }] },
  { "ref": "c4", "component": "sort", "label": "Sort by", "value": "", "actions": ["setValue", "setAscending"] }
]
WrapperWhat an agent seesWhat it can do
AgentSearchText
the search text
setValue: searches, as typing does
AgentFacet
the facet's values with their counts, the ticked ones
toggle a value, or setValue the ticked set
AgentRange
the range's limits, and the dataset's bounds
setValue { min, max }, or clear
AgentSort
the sortable fields, the field and direction
setValue a field (empty is relevance), setAscending
AgentResults
the results by place and name
pick one, reported as a click

With UI SDK's components of your own

A page built from UI SDK's own components is visible to agents already, so it needs no wrappers, only the search. intrface's bindings give it: each is a hook that returns what a controlled component takes, a value and an onValueChange, with the choices as items, read from and written to the search. They come from the main entry and need nothing of UI SDK, so they serve Base UI, Radix and others the same way.

tsx
import { useSearchTextBinding, useFacetBinding, useSortBinding } from '@indxsearch/intrface';
import { SearchAgent } from '@indxsearch/intrface/agent';
import { Input } from '@ui-sdk/react/input';
import { Checkbox, CheckboxGroup } from '@ui-sdk/react/checkbox';

function Search() {
  const text = useSearchTextBinding();
  const brand = useFacetBinding('brand');
  return (
    <>
      <Input aria-label="Search" value={text.value} onValueChange={text.onValueChange} />
      <CheckboxGroup aria-label="Brand" value={brand.value} onValueChange={brand.onValueChange}>
        {brand.items.map(i => <label key={i.value}><Checkbox value={i.value} />{i.label}</label>)}
      </CheckboxGroup>
    </>
  );
}

// Inside your SearchProvider:
<SearchAgent><Search /></SearchAgent>
BindingGives
useSearchTextBinding()
the search text; setting it searches, as typing does
useFacetBinding(field)
the ticked values, and the facet's values with their counts as items
useRangeBinding(field)
the range { min, max } or null, and the bounds of the current search
useSortBinding()
the sort field (empty is relevance), ascending and onAscendingChange, the sortable fields as items
useResultsBinding(title)
the results as items by place and name, and pick, reported as a click

SearchAgent is still what hands the page to your own assistant (useSearchAgent) and to the visitor's browser agent (browser), and where allow decides.

Your own assistant

useSearchAgent() gives the page's bridge to an assistant of your own. snapshot() reads the page, and act({ steps }) runs steps, several in one call:

tsx
const agent = useSearchAgent();
agent.snapshot();
await agent.act({ steps: [
  { ref: 'Search', action: 'setValue', args: ['floor lamp'] },
  { ref: 'Brand', action: 'toggle', args: ['Nordform'] },
  { ref: 'Sort by', action: 'setValue', args: ['price'] },
] });

The three methods are also tools by the same names, to hand a model as they are.

The visitor's browser agent

browser={{ allow }} hands the page's tools to the visitor's own agent in the browser, through WebMCP, where the browser has it; elsewhere it does nothing. The allow there is required: that agent is not one you wrote, and it decides each step it asks for.

Decide what an agent may do

allow on SearchAgent sees each step before it runs and returns true or false, or a promise of one, so you can ask the visitor first. For example, let agents search and sort but not filter:

tsx
<SearchAgent allow={step => step.component !== 'facet'}>

A refused step changes nothing, and the agent is told it was refused.

Count agents' searches apart

mark sends the searches an agent's changes cause as an agent's (actor=agent), so the dataset's statistics count them beside the totals and Observr does not read an agent's repeated searches as visitors'. Off unless you turn it on; a person's change searches unmarked as before.

tsx
<SearchAgent mark>