Skip to content

docs: add eliza tutorial #1209

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Apr 15, 2025
179 changes: 179 additions & 0 deletions docs/tutorials/ai-plus-flow/eliza/build-plugin.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
---
title: Eliza Plugin Guide
description: Learn how to build Eliza plugins for your AI Agent on Flow
sidebar_position: 2
keywords:
- AI
- AI Agent
- Eliza
- Eliza on Flow
- Plugin
- Flow Development
- Quickstart
---

# Eliza Plugin Development Guide

Plugins are a powerful way to extend the functionality of your Eliza AI agents. This guide will walk you through the process of creating custom plugins that can enhance your agent's capabilities, from simple utilities to complex integrations with external services. You'll learn how to leverage the plugin system to create modular and reusable components for your AI agents.

## Learning Objectives

By the end of this tutorial, you will be able to:

- Create a new plugin repository from the template
- Understand the plugin development workflow
- Implement custom actions and services
- Integrate plugins with your Eliza agent
- Register and publish plugins to the Eliza Plugin Registry
- Use dependency injection for better plugin architecture

## Prerequisites

Before getting started with Eliza, ensure you have:

- [Node.js 23+] (using [nvm] is recommended)
- [pnpm 9+]
- Git for version control
- A code editor ([VS Code], [Cursor] or [VSCodium] recommended)
- [Flow-cli] for Flow blockchain interaction.

> **Note for Windows Users:** [WSL 2] is required.

## Quickstart

Please follow the [Quickstart Guide] to set up your development environment.

## Plugin Development

### Create a Plugin repository from Template

Visit [Eliza Plugin Template] and click on the "Use this template" button to create a new repository.

Or you can create a new empty repository and copy the files from some examples at [Eliza Plugins] organization.

> Note: Flow's Eliza plugin template is using Dependency Injection(`@elizaos-plugins/plugin-di`), you can learn more about the Dependency Injection in the [plugin's README.md]. It allows you can use `Class` instead of `Object` for your `Actions`, `Providers`, `Services`, and etc. **If you don't want to use it, you can follow the other examples in Eliza Plugins organiazation.**

### Add the Plugin repository to your Eliza project

Let's say you created a repository named `username/plugin-foo`.

Use submodules to add the plugin repository to your Eliza project.

```bash
git submodule add https://github.com/username/plugin-foo.git packages/plugin-foo
```

Change the package's name in the plugin's `package.json` to `@elizaos-plugins/plugin-foo`.

```json
{
"name": "@elizaos-plugins/plugin-foo",
}
```

Add the plugin to agent's `package.json`

```bash
pnpm add @elizaos-plugins/plugin-foo@'workspace:*' --filter ./agent
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for changes now, but we need to agree on a package manager and use it consistently.

I can't see how this would be the case, but if this won't work with yarn or npm, I'd add pnpm as a prereq.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is project-related, and Eliza enforces only-allow pnpm.

By the way, both npm and yarn are actually quite outdated.

```

Check the `agent/package.json` to ensure the plugin is added, you should see something like this:

```json
{
"dependencies": {
"@elizaos-plugins/plugin-foo": "workspace:*"
}
}
```

### Build the Plugin

Build the plugin using the following command:

```bash
pnpm build --filter ./packages/plugin-foo

# Or build all packages
pnpm build
```

### Add Plugin to the `character.json` you want to use

Let's say you want to add the plugin to the `sample` character which is `characters/sample.character.json`.

```json
{
"name": "Sample",
"plugins": [
"@elizaos-plugins/plugin-foo"
]
}
```

:::warning

If you are using Dependency Injection(`@elizaos-plugins/plugin-di`) in your plugin, remember to add it to the `postProcessors` field. And **`clients` field is deprecated** in the latest version of Eliza, so if you want to add clients you also need to use `plugins` field.

:::

```json
{
"name": "Sample",
"plugins": [
"@elizaos-plugins/plugin-foo",
"@elizaos-plugins/client-discord"
],
"postProcessors": [
"@elizaos-plugins/plugin-di"
]
}
```

### Run the Eliza Agent with your Plugin

Run the Eliza agent to test the plugin.

```bash
pnpm start --character="characters/sample.character.json"

# Or with more debug logs
pnpm start:debug --character="characters/sample.character.json"
```

### Interact with the Agent

Now, you're ready to start a conversation with your agent.

Open a new terminal window and run the client's http server.

```bash
pnpm start:client
```

## Plugin Registration

You need to register your plugin in the [Eliza Plugin Registry] to make it available for other users.

Please follow the guide there, modify the [index.json] and submit a PR to the registry repository.

## Conclusion

In this tutorial, you've learned how to develop custom plugins for Eliza. You've gained experience with creating plugin repositories, implementing custom actions and services, integrating plugins with agents, and using dependency injection for better architecture.

Eliza's plugin system provides a powerful way to extend the functionality of your AI agents. With the knowledge gained from this tutorial, you can now develop more sophisticated plugins, create reusable components, and share your work through the plugin registry.

[Node.js 23+]: https://docs.npmjs.com/downloading-and-installing-node-js-and-npm
[nvm]: https://github.com/nvm-sh/nvm
[pnpm 9+]: https://pnpm.io/installation
[VS Code]: https://code.visualstudio.com/
[Cursor]: https://cursor.com/
[VSCodium]: https://vscodium.com
[Flow-cli]: https://developers.flow.com/tools/flow-cli
[WSL 2]: https://learn.microsoft.com/en-us/windows/wsl/install-manual
[Quickstart Guide]: ./index.md
[Eliza Plugin Template]: https://github.com/onflow/eliza-plugin-template
[Eliza Plugins]: https://github.com/elizaos-plugins
[plugin's README.md]: https://github.com/fixes-world/plugin-di
[Eliza Plugin Registry]: https://github.com/elizaos-plugins/registry
[index.json]: https://github.com/elizaos-plugins/registry/blob/main/index.json
Loading
Loading