Skip to main content

On-Page Agent

@nxisai/agent-harness puts an AI agent on your own pages. It's a drop-in chat element backed by a tool-calling harness. It discovers the tools your page and your site's MCP server expose. Then, on each turn, it decides whether to run a tool, ask for what's missing, or confirm with the visitor before anything is sent.

By default the model runs on the visitor's device, over WebGPU. There's no server and no API key. You can also point it at a model you host.

npm install @nxisai/agent-harness
Where it fits

The JS tag registers your page's forms as WebMCP tools, and your site's MCP server answers typed queries. The agent harness is a visitor-facing agent that uses both. It isn't loaded by the JS tag; you add it to your pages yourself.

Quick start​

import '@nxisai/agent-harness/ui';
<nxis-agent></nxis-agent>

The element registers itself, finds the page's tools, and renders a chat surface with an inline launcher. It opens as a window docked in the corner unless you set a mode. That's the whole integration for a single agent.

const agent = document.querySelector('nxis-agent');
agent.systemPrompt = '…';
agent.suggestions = ['Find a plumber', 'Book a visit'];
agent.open();

Display modes​

Set the mode attribute:

modeBehavior
window (default)Docks in the corner at --window-w × --window-h (400 × 620 by default), so your page stays visible and usable beside it. Below 520 px wide, a window covers the page anyway.
fullscreenCovers the page when open, for a site where the agent is the experience.
inlineFills the box the host puts it in and stays open, for a copilot rail that you lay out.
<nxis-agent mode="fullscreen"></nxis-agent>

In window and fullscreen, a header button lets the visitor switch between the two. Their choice is remembered for the next visit only when you set no mode attribute; an explicit mode always wins. The button is hidden in inline, below 520 px, and when you add no-mode-toggle.

Deprecated element name

<nxis-agent-fullscreen> still works as a deprecated alias of <nxis-agent>. Unlike <nxis-agent>, it defaults to fullscreen when no mode is set. Rename it to <nxis-agent mode="fullscreen"> to keep the same layout.

What a turn does​

Given the tool the model picked and everything already known, the harness asks what's still missing:

ToolMissing fieldsResult
Read (readOnlyHint)NoneRuns. Several records end with a recommended pick
ReadSomeAsks only for those, then runs
WriteNoneAn action card: what will be sent, and Send
WriteSomeAn action card: what it has, what's still needed, then Send

Nothing is written without the visitor pressing Send. When a search returns several records, the agent recommends one with two or three reasons. Each reason is checked against the record, so a number has to be one the record states and "open now" has to match its opening hours. Reasons that fail are dropped.

A form can only be submitted on its own page. When the visitor asks for an action whose form is on another page, the agent collects and confirms the values where the visitor is. It then opens that page and submits there.

Where the tools come from​

  1. WebMCP: the tools on document.modelContext, registered by the JS tag (browser or ssr mode), by a browser extension, or by your own code.
  2. Your site's MCP server: found by fetching discovery files from the page's own origin. These are /.well-known/ai-catalog.json first, then /.well-known/mcp/catalog.json, followed to the MCP server card. The bridged tools are the public typed-retrieval tools (nxis_list_types, nxis_query, nxis_get). See Agent Protocols and Standards for the file formats.
  3. Site-wide actions: once connected, the harness asks the server for the site's Schema.org Actions and registers them too, so the agent can reach a form on another page. site-actions="false" turns this off.

The element never supplies an API key, and there's no attribute for one, because a key in page HTML is readable by every visitor. Public typed retrieval needs no key. Discovery failure is never fatal: the agent keeps running with whatever the page registered.

Models and providers​

On-device (default). Gemma 4 (E2B, q4f16) runs in the tab over WebGPU, with no configuration. The weights are fetched on first use (gigabytes on a first run) and then kept in Cache Storage.

Attribute / propertyValuesPurpose
preloadeager, idle (default), noneWhen the weights are fetched.
cache"false"Don't store model files in Cache Storage.
model-hostURLFetch weights from your own origin or CDN instead of the public model hub, which rate-limits busy sites.
model-path-templatestringThe path under model-host. Defaults to {model}/.

assessLocalCapability() tells you whether a device can load the local model without loading it. The local provider runs the same check and declines by default on devices that can't, because an out-of-memory kill would take the host page down with it.

Your own model. Point createProxyProvider at an endpoint on your own origin. The endpoint holds the vendor key:

import { createProxyProvider } from '@nxisai/agent-harness';

agent.modelProvider = createProxyProvider({ endpoint: '/api/agent' });

Your endpoint receives a POST with { messages, tools, maxTokens?, cache? } and answers { text, call?, usage?, model? }, with at most one tool call per turn. When a provider is remote, the header badge reads Remote, so visitors can see that the conversation leaves the device. For any other transport, implement the ModelProvider interface directly. The agent-model-proxy skill writes this endpoint for you, with origin, rate and size limits. Your endpoint can also enforce the agent's guardrails from a policy you change without a deploy: see Enforcing at the model proxy.

Keep vendor keys off the page

Don't call a model vendor's API from the browser. A key in page source is readable by anyone, and a browser can't rate-limit or audit itself.

Multiple agents​

By default, one agent reads every tool on the page. With many forms, you can instead declare specialists and a routing table. Each turn then loads one agent's instructions and tools, instead of all of them:

agent.agents = {
retrieval: {
systemPrompt: RETRIEVAL_PROMPT,
tools: (t) => /^nxis_(query|get)$/.test(t.name),
description: 'questions about services, ratings and areas',
unavailable: 'I cannot search the site records from here right now.',
},
booking: {
systemPrompt: BOOKING_PROMPT,
tools: (t) => /book|appointment/i.test(t.name),
description: 'booking a visit',
unavailable: 'I cannot book a visit from here. The booking page can.',
},
};
agent.routes = [
{ route: 'booking', match: /\b(book|schedule|appointment)\b/ },
{ route: 'retrieval', match: /\b(hours|rated|cover|who|find)\b/ },
];
agent.fallback = 'retrieval';

A turn is routed by the rule table first, with no model call. If the rules are unclear, a short classification pass runs. The chosen agent keeps the conversation until it reports that it can't help. Set agents back to null to return to single-agent mode.

Handoff to another agent or a person​

The agent can hand a conversation to another agent that can finish what it can't, or to a person on your team. Both are reached over A2A 1.0, through a relay you host on your own origin. The relay holds the credentials and the list of targets, so the page never talks to a target directly.

agent.handoff = {
relay: '/api/handoff',
targets: {
booking: { kind: 'agent', label: 'Booking', description: 'books a visit from the free times on the calendar',
takes: ['book_a_visit'] },
team: { kind: 'person', label: 'Our team' },
},
};

This offers the model two tools, transfer_to_agent and talk_to_a_person. They only list targets that both this config and the relay name. The visitor sees who the conversation goes to and the summary that goes with it, and presses Send. From then on, what they type goes to the target, and Back to the assistant ends the handoff. A handoff survives page changes and reloads.

A target can also take a form's place. With takes: ['book_a_visit'], while the target is available, booking requests go to it instead of the page's booking form. When it's away, the form works as before.

NxisAI provides three agents to hand to: a Support Agent that answers from your help content with sources, a Quote Agent and a Booking Agent. Agents explains when to use which, and A2A setup covers the relay, the targets, the secrets your host keeps and link-origins. The agent-handoff skill writes the relay.

Guardrails​

Every turn passes through the agent's guardrails, which are on by default and need no setup. They keep untrusted text (a tool result, a page, a remote agent) as data, decide by code which tools need the visitor's confirmation, and limit where the agent may link and what leaves the page. Agent Guardrails lists the default rules, the strict preset, how to configure and observe them, and the kill switch.

Element reference​

Properties: systemPrompt, suggestions, emptyState, name, logo, theme, agents, routes, fallback, modelProvider, preload, debug, preferences, handoff, guardrails.

Attributes:

AttributeValuesPurpose
modewindow (default), fullscreen, inlineSee Display modes
no-mode-togglepresentHide the window / full-screen button
preloadeager, idle, noneWhen the local model's weights are fetched
debugpresentShow tool receipts, route labels and guardrail decisions
link-originsorigins, space-separatedOther origins a handoff target's reply may link to, and the agent may open without asking. See Origins and link-origins and Guardrails
guardrailsstrictSelect the strict preset of the guardrails
guardrails-srcURLRead the guardrails policy from your model proxy. See Enforcing at the model proxy
discover"false"Skip remote MCP discovery
site-actions"false"Don't fetch the actions on other pages of the site
prompt-style"classic"Use the earlier, separate ask/confirm cards
cache"false"Don't store model files in Cache Storage
model-host, model-path-templateURL, stringSelf-host the model weights
a2ui"false"Use the legacy DOM renderers
auto-openpresentOpen on connect

Theming: set colors, radius and fonts through the theme property, rather than CSS, because it writes both of the element's token systems:

agent.theme = { accent: '#B45309', ink: '#0E1C2B', bg: '#FFFFFF', radius: '14px', fontSans: 'Inter, sans-serif' };

Preferences: agent.preferences.set({ name, email }) stores values used to fill forms. They're session-scoped unless you set agent.preferences.persist = true.

Headless use​

To draw your own UI, import from the package root and bring your own renderer:

import { AgentHarness, AgentCoordinator, LocalGemmaProvider, connectTools } from '@nxisai/agent-harness';

await connectTools(); // WebMCP + remote MCP
const provider = new LocalGemmaProvider(); // or createProxyProvider(...)
const harness = new AgentHarness({ provider, renderer });
await harness.turn(goal, messages);

The package has four entry points: @nxisai/agent-harness (headless), @nxisai/agent-harness/ui (the element), @nxisai/agent-harness/tools (connectTools) and @nxisai/agent-harness/a2ui. The package README on npm has the full API: HarnessRenderer, AgentCoordinator, journey steps, and the handoff controller.

Requirements​

  • WebGPU for the on-device model: Chrome or Edge 113+, or Safari 18+. Devices without it can use a remote provider.
  • Tools: document.modelContext from the JS tag or a browser extension, or an MCP server that the site's .well-known discovery files point to.
  • Model weights: fetched on first use and cached afterward. Self-host them with model-host on a busy site.
Honest scope

The harness makes your pages' tools usable by an agent your visitors talk to. What the agent can do is bounded by the tools your page and MCP server expose, and every write waits for the visitor's Send.