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;
}

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();
SAFE: This plugin only exposes read operations. Agents can search and read articles but cannot create, edit, or delete content.

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');
    },
  };
}
SAFE: Read-only availability checks. Agents cannot book, cancel, or modify appointments.

Publishing Plugins

To share your plugin with the community:

  1. Package it as an npm module following the naming convention @aixa/plugin-<name>.
  2. Export a factory function that returns { register, unregister }.
  3. 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