An example plugin for the Hedera Agent Kit demonstrating the v4 BaseTool pattern. Use it as a template when building and publishing your own plugin.
| Tool method | Class | Type | Description |
|---|---|---|---|
example_greeting_tool |
ExampleGreetingTool |
Query | Generates a personalised greeting in English, Spanish, or French. No on-chain action. |
example_hbar_transfer_tool |
ExampleHbarTransferTool |
Transaction | Transfers HBAR to account 0.0.800. Supports AUTONOMOUS and RETURN_BYTES modes. |
npm install @hashgraph/hedera-agent-kit @hiero-ledger/sdk
# or
pnpm add @hashgraph/hedera-agent-kit @hiero-ledger/sdkWhen publishing your own plugin as an npm package, declare both as peer dependencies:
{
"peerDependencies": {
"@hashgraph/hedera-agent-kit": ">=5.0.0",
"@hiero-ledger/sdk": ">=2.0.0"
}
}import { HederaAgentKit, AgentMode } from '@hashgraph/hedera-agent-kit';
import { Client } from '@hiero-ledger/sdk';
import examplePlugin from '@your-org/example-plugin'; // or './index'
const client = Client.forTestnet().setOperator(accountId, privateKey);
const kit = new HederaAgentKit(client, {
mode: AgentMode.AUTONOMOUS,
plugins: [examplePlugin],
});import {
examplePlugin,
exampleGreetingTool,
exampleHbarTransferTool,
EXAMPLE_GREETING_TOOL,
EXAMPLE_HBAR_TRANSFER_TOOL,
examplePluginToolNames,
} from '@your-org/example-plugin';
// Use constants to reference tools without magic strings
console.log(EXAMPLE_GREETING_TOOL); // 'example_greeting_tool'
console.log(examplePluginToolNames);
// { EXAMPLE_GREETING_TOOL: 'example_greeting_tool', EXAMPLE_HBAR_TRANSFER_TOOL: 'example_hbar_transfer_tool' }examples/plugin/
├── index.ts # Plugin definition + re-exports
├── tools/
│ ├── greeting/
│ │ └── example-greeting-tool.ts # Query tool (no transaction)
│ └── hbar/
│ └── example-hbar-transfer-tool.ts # Transaction tool
├── smoke-test.ts # Runnable test (no LLM, no funds)
└── README.md
Each tool file exports:
- A
stringconstant for the tool method name (e.g.EXAMPLE_GREETING_TOOL) - A named class extending
BaseTool(e.g.ExampleGreetingTool) - A default factory function
(context: Context) => BaseTool
index.ts re-exports everything and defines the examplePlugin object (default export).
import { BaseTool, untypedQueryOutputParser } from '@hashgraph/hedera-agent-kit';
export const MY_QUERY_TOOL = 'my_query_tool';
export class MyQueryTool extends BaseTool {
method = MY_QUERY_TOOL;
outputParser = untypedQueryOutputParser; // required for framework adapters
async coreAction(params, _context, _client) {
const result = `Result for ${params.requiredParam}`;
return { raw: { result }, humanMessage: result };
}
async shouldSecondaryAction() { return false; } // skip stage 6
}
const tool = (_context) => new MyQueryTool();
export default tool;import { BaseTransactionTool, handleTransaction, transactionToolOutputParser } from '@hashgraph/hedera-agent-kit';
export const MY_TX_TOOL = 'my_tx_tool';
const postProcess = (response) => `Operation completed. Transaction ID: ${response.transactionId}`;
export class MyTxTool extends BaseTransactionTool {
method = MY_TX_TOOL;
outputParser = transactionToolOutputParser; // required for framework adapters
async coreAction(params, _context, _client) {
return HederaBuilder.xxx(params); // BUILD only — do not submit here
}
async secondaryAction(transaction, client, context) {
return await handleTransaction(transaction, client, context, postProcess);
}
}
const tool = (context) => new MyTxTool(context);
export default tool;Important
Transaction tools must build in coreAction and dispatch in secondaryAction. Do not override shouldSecondaryAction — the default true keeps both stages active. This split lets hooks and policies inspect the unsigned transaction before submission (stage 5, postCoreActionHook).
Run the smoke test — no operator credentials, no funds, no network access required:
npx tsx smoke-test.tsThe smoke test:
- Checks the plugin shape and tool count.
- Calls the greeting tool directly via
tool.execute(). - Dry-runs the HBAR transfer in
RETURN_BYTESmode — returns frozen bytes without submitting. - Verifies that a lifecycle hook fires correctly.
package.json— set"main","module", and"types"to point at your built output; list@hashgraph/hedera-agent-kitand@hiero-ledger/sdkaspeerDependencies.- TypeScript — ship
.d.tsdeclarations alongside your compiled JS. - Exports — re-export everything from
index.tsso consumers can import factories, classes, and string constants individually. - Versioning — follow semantic versioning; a breaking change to a tool's parameters or method name is a major bump.
- README — document each tool's parameters, output shape, and any
Contextfields your plugin reads.
See docs/PLUGINS.md for the full plugin authoring guide, including the complete BaseTool lifecycle and hook/policy integration.