Writing Custom Plugins
The plugin system lets you package reusable AEO capabilities for specific industries or use cases. A plugin is just a plain object with a register() method — you can build one in minutes.
Plugin Interface
Every plugin must conform to this minimal interface:
interface AIXAPlugin {
register(): void;
unregister(): void;
}
register()— Called when the plugin is activated. Use it to register search endpoints, actions, or other tools via the AIXA SDK.unregister()— Called when the plugin is deactivated. Use it to clean up registrations and event listeners.
Internally, register() typically calls aixa.registerSearch() or aixa.registerAction() to expose capabilities to agents. unregister() calls aixa.unregisterTool() for cleanup.
Example: SaaS Knowledge Base
A plugin that exposes a knowledge base search to agents. Users can search articles and fetch full article content. All read-only.
/**
* SaaS Knowledge Base Plugin
* Exposes search_kb and get_article to agents.
*/
export function kbPlugin(config) {
const { apiBase, apiKey } = config;
return {
register() {
// Register knowledge base search
aixa.registerSearch({
endpoint: `${apiBase}/kb/search`,
parameters: [
{ name: 'query', type: 'string', description: 'Search query', required: true },
{ name: 'category', type: 'string', description: 'Article category' },
{ name: 'product', type: 'string', description: 'Filter by product area' },
],
method: 'GET',
});
// Register article detail fetch
aixa.registerAction({
name: 'get_article',
description: 'Fetch the full content of a knowledge base article by ID',
parameters: [
{ name: 'id', type: 'string', description: 'Article ID', required: true },
],
handler: async ({ id }) => {
const response = await fetch(`${apiBase}/kb/articles/${id}`, {
headers: { Authorization: `Bearer ${apiKey}` },
});
if (!response.ok) {
throw new Error(`Article not found: ${id}`);
}
const article = await response.json();
return {
id: article.id,
title: article.title,
content: article.body,
category: article.category,
lastUpdated: article.updated_at,
};
},
});
},
unregister() {
aixa.unregisterTool('search_kb');
aixa.unregisterTool('get_article');
},
};
}
// Usage:
import { kbPlugin } from './kb-plugin';
const kb = kbPlugin({
apiBase: 'https://help.myapp.com/api/v1',
apiKey: 'sk-...',
});
kb.register();
Example: Booking System
A plugin that lets agents check availability and list open time slots. Perfect for salons, clinics, or consultation services.
/**
* Booking System Plugin
* Exposes check_availability and get_available_slots to agents.
*/
export function bookingPlugin(config) {
const { apiBase, calendarId } = config;
return {
register() {
// Check availability for a specific date and service
aixa.registerAction({
name: 'check_availability',
description: 'Check if a date is available for a given service',
parameters: [
{ name: 'date', type: 'string', description: 'Date in YYYY-MM-DD format', required: true },
{ name: 'service', type: 'string', description: 'Service type (e.g., "haircut", "consultation")', required: true },
],
handler: async ({ date, service }) => {
const response = await fetch(
`${apiBase}/calendars/${calendarId}/availability?date=${date}&service=${service}`
);
const data = await response.json();
return {
date,
service,
available: data.slots.length > 0,
remainingSlots: data.slots.length,
};
},
});
// Get all available time slots for a date
aixa.registerAction({
name: 'get_available_slots',
description: 'Get all available time slots for a specific date',
parameters: [
{ name: 'date', type: 'string', description: 'Date in YYYY-MM-DD format', required: true },
],
handler: async ({ date }) => {
const response = await fetch(
`${apiBase}/calendars/${calendarId}/slots?date=${date}`
);
const data = await response.json();
return {
date,
slots: data.slots.map(slot => ({
time: slot.start_time,
duration: slot.duration_minutes,
available: slot.status === 'open',
})),
};
},
});
},
unregister() {
aixa.unregisterTool('check_availability');
aixa.unregisterTool('get_available_slots');
},
};
}
Publishing Plugins
To share your plugin with the community:
- Package it as an npm module following the naming convention
@aixa/plugin-<name>. - Export a factory function that returns
{ register, unregister }. - Publish to npm with clear documentation on configuration options.
// package.json
{
"name": "@aixa/plugin-kb",
"version": "1.0.0",
"description": "Knowledge base plugin for aixa.js agents",
"main": "index.js",
"keywords": ["aixa", "plugin", "knowledge-base"],
"peerDependencies": {
"@aixa/sdk": "^1.0.0"
}
}
Users then install and use your plugin in two lines:
import { kbPlugin } from '@aixa/plugin-kb';
kbPlugin({ apiBase: '...' }).register();
Best Practices
- Always SAFE by default. Design plugins to be read-only unless the use case absolutely requires writes. This builds trust with site owners who are understandably cautious about granting agent capabilities.
- Use
requiresConfirmationfor mutations. If your plugin must perform writes (e.g., adding an item to a wishlist), setrequiresConfirmation: trueon the action so the HITL (Human-in-the-Loop) modal prompts the user before execution. - Document your parameters. Every parameter should have a clear
description— this is what the agent reads to understand how to use your tools. Vague descriptions lead to bad agent behavior. - Use TypeScript. Export type definitions for your configuration and return types so users get IDE autocompletion.
- Handle errors gracefully. Return meaningful error messages. Agents use error messages to correct their next attempt.
- Clean up in
unregister(). Remove event listeners, clear intervals, and unregister all tools. Leaving stale registrations causes agents to call dead endpoints.