Create a Plugin

Learn how to create custom plugins to extend IrisOS agent capabilities.

Overview

Plugins are modular extensions that add new capabilities to IrisOS agents. This guide will walk you through creating your own plugin from scratch.

Plugin Structure

A basic IrisOS plugin has the following structure:

@irisos/plugin-example/
├── package.json
├── tsconfig.json
├── src/
│   ├── index.ts          # Main plugin export
│   ├── actions.ts        # Custom actions
│   ├── providers.ts      # Data providers
│   ├── services.ts       # Services
│   └── types.ts          # TypeScript types
├── tests/
│   └── index.test.ts
└── README.md

Creating Your First Plugin

1. Initialize the Plugin

2. Install Dependencies

3. Configure TypeScript

Create tsconfig.json:

4. Define Plugin Interface

Create src/types.ts:

Example Plugin: Weather Service

Let's create a weather plugin that fetches weather data:

1. Define Actions

Create src/actions.ts:

2. Create the Main Plugin

Create src/index.ts:

3. Update package.json

Advanced Plugin Features

Adding Providers

Providers supply data to agents:

Adding Services

Services run background tasks:

Adding Middleware

Testing Your Plugin

Create tests/weather.test.ts:

Plugin Configuration

Allow users to configure your plugin:

Building and Testing Locally

Using Your Plugin

Once built, use your plugin with agents:

Plugin Best Practices

  1. Error Handling: Always handle errors gracefully

  2. Validation: Validate all inputs and configuration

  3. Documentation: Provide clear README and inline documentation

  4. TypeScript: Use TypeScript for type safety

  5. Testing: Write comprehensive tests

  6. Versioning: Follow semantic versioning

  7. Performance: Optimize for performance and resource usage

  8. Security: Never expose API keys or sensitive data

  9. Compatibility: Ensure compatibility with IrisOS versions

  10. Clean Code: Follow coding standards and best practices

Publishing Your Plugin

See Publish a Plugin for publishing instructions.

Example Plugins for Reference

Study these official plugins for examples:

  • @irisos/plugin-evm - Blockchain interactions

  • @irisos/plugin-discord - Platform integration

  • @irisos/plugin-images - External API integration

  • @irisos/plugin-sql - Database operations

Next Steps

Need Help?

Last updated