Manual Configuration
Manual configuration gives you full control over what tools AI agents can access. Use it when you need to expose custom APIs, handle complex SPA workflows, enforce strict security policies, or integrate with services that don't have corresponding DOM elements.
All manual registrations take precedence over auto-inferred tools. If a manually registered tool shares a name with an auto-inferred one, the manual definition wins.
registerSearch()
registerSearch() registers a read-only search/query tool. It is the
simplest registration method and is ideal for any operation that retrieves data
without side effects.
Signature
aixa.registerSearch(
name: string,
parameters: ParamDef[],
endpoint?: string,
method?: string
)
| Parameter | Type | Required | Description |
|---|---|---|---|
name |
string |
Yes | Unique tool name. Prefixed with search_ automatically if not already present. |
parameters |
ParamDef[] |
Yes | Array of parameter definitions. Each includes name, type, description, and optional required and enum. |
endpoint |
string |
No | API endpoint URL. If omitted, calls are dispatched as events on the page. |
method |
string |
No | HTTP method for the endpoint. Defaults to "GET". |
Example: E-Commerce Product Search
aixa.registerSearch('product_search', [
{
name: 'q',
type: 'string',
description: 'Search query — matches against product name and description',
required: true
},
{
name: 'category',
type: 'string',
description: 'Filter by product category',
enum: ['electronics', 'clothing', 'home', 'sports']
},
{
name: 'minPrice',
type: 'number',
description: 'Minimum price in USD'
},
{
name: 'maxPrice',
type: 'number',
description: 'Maximum price in USD'
},
{
name: 'sortBy',
type: 'string',
description: 'Sort order for results',
enum: ['relevance', 'price_asc', 'price_desc', 'rating', 'newest']
}
], 'https://api.example.com/products/search');
registerAction()
registerAction() registers a tool that performs a state-changing
(mutation) operation. Actions support an optional confirmation gate for
human-in-the-loop workflows.
Signature
aixa.registerAction(
name: string,
description: string,
parameters: ParamDef[],
handler: (params: object) => Promise<void> | void,
requiresConfirmation?: boolean
)
| Parameter | Type | Required | Description |
|---|---|---|---|
name |
string |
Yes | Unique action name. |
description |
string |
Yes | Human-readable description of what the action does (shown in confirmation prompts). |
parameters |
ParamDef[] |
Yes | Array of parameter definitions, same format as registerSearch(). |
handler |
function |
Yes | Async or sync function that executes the action. Receives the parsed parameters object. |
requiresConfirmation |
boolean |
No | If true, the agent must present a confirmation prompt to the user before the action executes. Defaults to false. |
Example: Add to Cart with Confirmation
aixa.registerAction(
'add_to_cart',
'Add a product to the shopping cart',
[
{
name: 'productId',
type: 'string',
description: 'Unique product identifier',
required: true
},
{
name: 'quantity',
type: 'number',
description: 'Number of items to add',
required: true
},
{
name: 'variantId',
type: 'string',
description: 'Product variant (size, color, etc.)'
}
],
async (params) => {
const response = await fetch('/api/cart/add', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(params)
});
if (!response.ok) {
throw new Error(`Failed to add to cart: ${response.statusText}`);
}
const cart = await response.json();
window.dispatchEvent(new CustomEvent('cart:updated', { detail: cart }));
},
true // requiresConfirmation — user must approve before execution
);
registerTool()
registerTool() is the base registration function. It offers the
most flexibility, exposing every field of the tool schema. Use this when
registerSearch() or registerAction() don't provide
enough control — for example, when you need custom risk levels, categories,
or a tool that doesn't fit the search/action dichotomy.
Signature
aixa.registerTool(
name: string,
description: string,
parameters: ParamDef[],
handlerOrEndpoint: function | string,
riskLevel?: 'safe' | 'high',
category?: string
)
| Parameter | Type | Required | Description |
|---|---|---|---|
name |
string |
Yes | Unique tool name. |
description |
string |
Yes | What the tool does. Displayed to agents and in confirmation dialogs. |
parameters |
ParamDef[] |
Yes | Parameter definitions. |
handlerOrEndpoint |
function | string |
Yes | Either a handler function or an endpoint URL string. If a URL is given, requests are forwarded as HTTP calls. |
riskLevel |
'safe' | 'high' |
No | Defaults to 'safe' for endpoint URLs and 'high' for handler functions. |
category |
string |
No | Logical grouping for the tool (e.g., 'shopping', 'account'). |
When to Use registerTool()
-
Custom risk levels — You need a
'safe'mutation tool or a'high'query tool. -
Non-standard categories — Your tool doesn't fit
search,filter,sort,navigate, ormutation. - Direct handler + custom response — You want complete control over response serialization and error handling.
- Streaming or WebSocket tools — Your handler manages a persistent connection instead of a request/response cycle.
Unregistering
Remove tools from the registry when they are no longer available:
// Remove a single tool by name
aixa.unregisterTool('search_product_search');
// Remove all registered tools (auto-inferred and manual)
aixa.clearRegistry();
Note: clearRegistry() removes all tools.
Auto-inferred tools will be re-discovered on the next refreshTools() call.
Manual tools must be re-registered explicitly.
Override Behavior
When both auto-inference and manual registration produce tools with the same name, the manual tool wins. This is by design — it lets you replace auto-inferred behavior with custom logic without modifying your HTML.
unregisterTool() before
re-registering.
Example: Full E-Commerce Setup
A complete e-commerce configuration combining search and multiple guarded actions:
import { AIXA } from '@aixa/core';
const aixa = new AIXA();
// --- Search: browse products ---
aixa.registerSearch('product_search', [
{ name: 'q', type: 'string', description: 'Search query', required: true },
{ name: 'category', type: 'string', description: 'Product category',
enum: ['electronics', 'clothing', 'home', 'sports'] },
{ name: 'minPrice', type: 'number', description: 'Minimum price' },
{ name: 'maxPrice', type: 'number', description: 'Maximum price' },
{ name: 'sortBy', type: 'string', description: 'Sort order',
enum: ['relevance', 'price_asc', 'price_desc', 'rating'] }
], 'https://api.example.com/products/search');
// --- Action: add to cart (HITL) ---
aixa.registerAction(
'add_to_cart',
'Add items to the shopping cart',
[
{ name: 'productId', type: 'string', description: 'Product ID', required: true },
{ name: 'quantity', type: 'number', description: 'Quantity', required: true },
{ name: 'variantId', type: 'string', description: 'Variant (size/color)' }
],
async (params) => {
const res = await fetch('/api/cart/add', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(params)
});
if (!res.ok) throw new Error(`Cart error: ${res.statusText}`);
return res.json();
},
true // requiresConfirmation
);
// --- Action: checkout (HITL) ---
aixa.registerAction(
'checkout',
'Complete the purchase and place the order',
[
{ name: 'paymentMethodId', type: 'string', description: 'Saved payment method ID', required: true },
{ name: 'shippingAddressId', type: 'string', description: 'Saved shipping address ID', required: true },
{ name: 'couponCode', type: 'string', description: 'Optional discount code' }
],
async (params) => {
const res = await fetch('/api/checkout', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(params)
});
if (!res.ok) throw new Error(`Checkout failed: ${res.statusText}`);
const order = await res.json();
window.location.href = `/orders/${order.id}/confirmation`;
return order;
},
true // requiresConfirmation — highest sensitivity
);
// --- Start the SDK ---
aixa.start();
With this setup, an AI agent can search products, add items to the cart (after user confirmation), and complete checkout (after a separate user confirmation). The human-in-the-loop gates ensure the user stays in control of all state-changing operations.