Creating a Plugin
Plugin Interface
Every plugin must implement the Plugin interface:Tool Interface
Each tool must implement theTool interface:
BaseTool (Recommended for v4)
This is NOT a breaking change.
BaseTool is an abstract class that implements the Tool interface — plain object tools continue to work exactly as before. However, they do not support the hooks and policies system introduced in v4 (e.g., HcsAuditTrailHook, MaxRecipientsPolicy, RejectToolPolicy). To enable those features, migrate your tool to BaseTool.BaseTool splits execution into a 7-stage lifecycle that hooks and policies tap into automatically — you never call them manually. For a detailed step-by-step guide on refactoring your tools, see the Migration Guide.
v3 (Tool object) | v4 (BaseTool class) | |
|---|---|---|
| Import | import type { Tool } | import { BaseTool } |
| Declaration | Object literal | Class extending BaseTool |
| Lifecycle | Single execute() | normalizeParams → coreAction → secondaryAction |
| Hooks & policies | ✗ None | ✓ Automatic at stages 1, 3, 5, 7 |
| Error handling | Manual try/catch in execute | Override handleError() |
| Breaking change | — | No |
Step-by-Step Guide
Step 1: Create Plugin Directory Structure
Step 2: Implement Your Tool
Create your tool file (e.g., tools/my-service/my-tool.ts):This example uses Hedera Agent Kit v4 which extends the BaseTool class to enable policies & hooks
Step 3: Create Plugin Definition
Create your plugin index file (index.ts):Best Practices
Parameter Validation- Use Zod schemas for robust input validation
- Provide clear descriptions for all parameters
- Mark required vs optional parameters appropriately
- Group related tools by service type
- Use consistent naming conventions
- Follow the established directory structure
- Use
handleTransaction()to facilitate human-in-the-loop and autonomous execution flows - Respect the AgentMode (
AUTONOMOUSvsRETURN_BYTES) - Implement proper transaction building patterns
Tool Output Parsing
The Hedera Agent Kit tools return a structured JSON output. Each tool returns:Using Your Custom Plugin
Examples and References
- See existing core plugins in typescript/src/plugins/core-*-plugin/
- Follow the patterns established in tools like transfer-hbar.ts
- See typescript/examples/langchain-v1/plugin-tool-calling-agent.ts for usage examples
Publish and Register Your Plugin
To create a plugin to be used with the Hedera Agent Kit, you will need to create a plugin in your own repository, publish a npm package, and provide a description of the functionality included in that plugin, as well as the required and optional parameters. Once you have a repository, published npm package, and a README with a description of the functionality included in that plugin in your plugin’s repo, as well as the required and optional parameters, you can add it to the Hedera Agent Kit by forking and opening a Pull Request to:- Include the plugin as a bullet point under the Available Third Party Plugin section under the Third Party Plugin section in the README.md in the hedera-agent-kit-js. Include the name, a brief description, and a link to the repository with the README, as well the URL linked to the published npm package.
-
If you would like to include your plugin functionality in the Hedera plugin built for ElizaOS simply make a PR to add your plugin name to the
pluginsarray in the Hedera ElizaOS plugin where the configuration is initiated. The hedera-agent-kit adaptor architecture means your plugin functionality will be usable with no additional configuration needed. - All commits for your plugin must be DCO signed, have the names of the tools & core actions exposed by the plugin, and point to the exact version of the npm packages. To avoid having pull requests blocked in the future, always include a sign-off:
Plugin is a unified SDK to the Bonzo protocol, exposing the core actions (deposit, withdraw, repay, borrow) for decentralised lending and borrowing on Hedera:
Plugin README Template
Resources
Examples and References
- See existing core plugins in the hedera agent kit examples
- Follow the patterns established in tools like transfer-hbar.ts
- See typescript/examples/langchain/tool-calling-agent.ts for usage examples