@hashgraphonline/conversational-agent 0.0.1 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +206 -38
- package/dist/cjs/agent-factory.d.ts +5 -0
- package/dist/cjs/base-agent.d.ts +95 -0
- package/dist/cjs/config/system-message.d.ts +1 -1
- package/dist/cjs/conversational-agent.d.ts +62 -5
- package/dist/cjs/index.cjs +1 -1
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.ts +8 -0
- package/dist/cjs/langchain-agent.d.ts +22 -0
- package/dist/cjs/mcp/MCPClientManager.d.ts +40 -0
- package/dist/cjs/mcp/adapters/langchain.d.ts +8 -0
- package/dist/cjs/mcp/helpers.d.ts +45 -0
- package/dist/cjs/mcp/types.d.ts +27 -0
- package/dist/cjs/plugins/hbar-transfer/AccountBuilder.d.ts +13 -0
- package/dist/cjs/plugins/hbar-transfer/HbarTransferPlugin.d.ts +15 -0
- package/dist/cjs/plugins/hbar-transfer/TransferHbarTool.d.ts +61 -0
- package/dist/cjs/plugins/hbar-transfer/index.d.ts +1 -0
- package/dist/cjs/plugins/hbar-transfer/types.d.ts +10 -0
- package/dist/cjs/plugins/index.d.ts +1 -0
- package/dist/cjs/providers.d.ts +48 -0
- package/dist/esm/index.js +18 -3
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/index10.js +22 -0
- package/dist/esm/index10.js.map +1 -0
- package/dist/esm/index11.js +104 -0
- package/dist/esm/index11.js.map +1 -0
- package/dist/esm/index12.js +36 -0
- package/dist/esm/index12.js.map +1 -0
- package/dist/esm/index13.js +16 -0
- package/dist/esm/index13.js.map +1 -0
- package/dist/esm/index14.js +127 -0
- package/dist/esm/index14.js.map +1 -0
- package/dist/esm/index15.js +132 -0
- package/dist/esm/index15.js.map +1 -0
- package/dist/esm/index16.js +95 -0
- package/dist/esm/index16.js.map +1 -0
- package/dist/esm/index5.js +42 -202
- package/dist/esm/index5.js.map +1 -1
- package/dist/esm/index6.js +295 -13
- package/dist/esm/index6.js.map +1 -1
- package/dist/esm/index7.js +87 -0
- package/dist/esm/index7.js.map +1 -0
- package/dist/esm/index8.js +255 -0
- package/dist/esm/index8.js.map +1 -0
- package/dist/esm/index9.js +18 -0
- package/dist/esm/index9.js.map +1 -0
- package/dist/types/agent-factory.d.ts +5 -0
- package/dist/types/base-agent.d.ts +95 -0
- package/dist/types/config/system-message.d.ts +1 -1
- package/dist/types/conversational-agent.d.ts +62 -5
- package/dist/types/index.d.ts +8 -0
- package/dist/types/langchain-agent.d.ts +22 -0
- package/dist/types/mcp/MCPClientManager.d.ts +40 -0
- package/dist/types/mcp/adapters/langchain.d.ts +8 -0
- package/dist/types/mcp/helpers.d.ts +45 -0
- package/dist/types/mcp/types.d.ts +27 -0
- package/dist/types/plugins/hbar-transfer/AccountBuilder.d.ts +13 -0
- package/dist/types/plugins/hbar-transfer/HbarTransferPlugin.d.ts +15 -0
- package/dist/types/plugins/hbar-transfer/TransferHbarTool.d.ts +61 -0
- package/dist/types/plugins/hbar-transfer/index.d.ts +1 -0
- package/dist/types/plugins/hbar-transfer/types.d.ts +10 -0
- package/dist/types/plugins/index.d.ts +1 -0
- package/dist/types/providers.d.ts +48 -0
- package/package.json +35 -27
- package/src/agent-factory.ts +21 -0
- package/src/base-agent.ts +222 -0
- package/src/config/system-message.ts +1 -1
- package/src/conversational-agent.ts +205 -103
- package/src/index.ts +24 -0
- package/src/langchain-agent.ts +333 -0
- package/src/mcp/MCPClientManager.ts +148 -0
- package/src/mcp/adapters/langchain.ts +185 -0
- package/src/mcp/helpers.ts +122 -0
- package/src/mcp/types.ts +29 -0
- package/src/plugins/hbar-transfer/AccountBuilder.ts +154 -0
- package/src/plugins/hbar-transfer/HbarTransferPlugin.ts +66 -0
- package/src/plugins/hbar-transfer/TransferHbarTool.ts +49 -0
- package/src/plugins/hbar-transfer/index.ts +1 -0
- package/src/plugins/hbar-transfer/types.ts +11 -0
- package/src/plugins/index.ts +2 -1
- package/src/providers.ts +82 -0
package/README.md
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
# Hashgraph Online Conversational Agent
|
|
2
2
|
|
|
3
3
|
|  | A conversational AI agent that implements Hashgraph Consensus Standards (HCS) for agent communication, registry management, and content inscription on the Hedera network.<br><br>This package is built and maintained by [Hashgraph Online](https://hashgraphonline.com), a consortium of leading Hashgraph organizations within the Hedera ecosystem.<br><br>[📚 Conversational Agent Documentation](https://hashgraphonline.com/docs/libraries/conversational-agent/)<br>[📖 HCS Standards Documentation](https://hcs-improvement-proposals.pages.dev/docs/standards) |
|
|
4
|
-
|
|
|
4
|
+
| :-------------------------- | :----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
5
|
+
|
|
6
|
+

|
|
5
7
|
|
|
6
8
|
## Overview
|
|
7
9
|
|
|
8
|
-
The Hashgraph Online Conversational Agent provides a comprehensive AI agent implementation that supports:
|
|
10
|
+
The Hashgraph Online Conversational Agent provides a comprehensive AI agent implementation that supports all tools from the `hedera-agent-kit` v2 package and the following HCS standards:
|
|
9
11
|
|
|
10
12
|
- **HCS-10**: AI Agent Communication standard for trustless peer-to-peer messaging
|
|
11
13
|
- **HCS-2**: Registry management for decentralized data storage
|
|
@@ -37,7 +39,7 @@ const agent = new ConversationalAgent({
|
|
|
37
39
|
network: 'testnet',
|
|
38
40
|
openAIApiKey: process.env.OPENAI_API_KEY!,
|
|
39
41
|
openAIModelName: 'gpt-4o',
|
|
40
|
-
verbose: true
|
|
42
|
+
verbose: true,
|
|
41
43
|
});
|
|
42
44
|
|
|
43
45
|
// Initialize (automatically detects key type)
|
|
@@ -48,9 +50,85 @@ const response = await agent.processMessage(
|
|
|
48
50
|
'Register me as an AI agent with the name TestBot, a random unique alias, and description "A test bot"'
|
|
49
51
|
);
|
|
50
52
|
|
|
53
|
+
// Transfer HBAR
|
|
54
|
+
const transferResponse = await agent.processMessage(
|
|
55
|
+
'I want to transfer 1 HBAR to the account 0.0.800'
|
|
56
|
+
);
|
|
57
|
+
|
|
51
58
|
console.log(response.response);
|
|
59
|
+
|
|
60
|
+
// Or use returnBytes mode for external signing
|
|
61
|
+
const bytesAgent = new ConversationalAgent({
|
|
62
|
+
accountId: process.env.HEDERA_ACCOUNT_ID!,
|
|
63
|
+
privateKey: process.env.HEDERA_PRIVATE_KEY!,
|
|
64
|
+
network: 'testnet',
|
|
65
|
+
openAIApiKey: process.env.OPENAI_API_KEY!,
|
|
66
|
+
operationalMode: 'returnBytes',
|
|
67
|
+
userAccountId: '0.0.12345',
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
await bytesAgent.initialize();
|
|
71
|
+
|
|
72
|
+
const bytesResponse = await bytesAgent.processMessage(
|
|
73
|
+
'Transfer 5 HBAR to 0.0.98765'
|
|
74
|
+
);
|
|
75
|
+
|
|
76
|
+
if (bytesResponse.transactionBytes) {
|
|
77
|
+
console.log('Transaction bytes:', bytesResponse.transactionBytes);
|
|
78
|
+
}
|
|
52
79
|
```
|
|
53
80
|
|
|
81
|
+
### Using returnBytes Mode
|
|
82
|
+
|
|
83
|
+
The agent can be configured to return transaction bytes instead of executing them directly. This is useful when you want to review or sign transactions externally. Here's how to execute the transaction after getting the bytes:
|
|
84
|
+
|
|
85
|
+
```typescript
|
|
86
|
+
import { ConversationalAgent } from '@hashgraphonline/conversational-agent';
|
|
87
|
+
import { Client, Transaction, PrivateKey } from '@hashgraph/sdk';
|
|
88
|
+
|
|
89
|
+
const agent = new ConversationalAgent({
|
|
90
|
+
accountId: process.env.HEDERA_ACCOUNT_ID!,
|
|
91
|
+
privateKey: process.env.HEDERA_PRIVATE_KEY!,
|
|
92
|
+
network: 'testnet',
|
|
93
|
+
openAIApiKey: process.env.OPENAI_API_KEY!,
|
|
94
|
+
operationalMode: 'returnBytes', // Return transaction bytes instead of executing
|
|
95
|
+
userAccountId: '0.0.12345', // The account that will sign the transaction
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
await agent.initialize();
|
|
99
|
+
|
|
100
|
+
// The agent will return transaction bytes for operations
|
|
101
|
+
const response = await agent.processMessage('Transfer 5 HBAR to 0.0.98765');
|
|
102
|
+
|
|
103
|
+
if (response.transactionBytes) {
|
|
104
|
+
// Decode the transaction bytes
|
|
105
|
+
const transaction = Transaction.fromBytes(
|
|
106
|
+
Buffer.from(response.transactionBytes, 'base64')
|
|
107
|
+
);
|
|
108
|
+
|
|
109
|
+
// Sign the transaction with your private key
|
|
110
|
+
const privateKey = PrivateKey.fromString(process.env.USER_PRIVATE_KEY!);
|
|
111
|
+
const signedTransaction = transaction.sign(privateKey);
|
|
112
|
+
|
|
113
|
+
// Submit to the Hedera network
|
|
114
|
+
const client = Client.forTestnet();
|
|
115
|
+
client.setOperator('0.0.12345', privateKey);
|
|
116
|
+
|
|
117
|
+
const txResponse = await signedTransaction.execute(client);
|
|
118
|
+
const receipt = await txResponse.getReceipt(client);
|
|
119
|
+
|
|
120
|
+
console.log('Transaction status:', receipt.status.toString());
|
|
121
|
+
console.log('Transaction ID:', txResponse.transactionId.toString());
|
|
122
|
+
}
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
When using `returnBytes` mode:
|
|
126
|
+
|
|
127
|
+
- The agent prepares transactions but doesn't execute them
|
|
128
|
+
- Transaction bytes are returned as base64-encoded strings
|
|
129
|
+
- You can decode, sign, and submit the transaction using the Hedera SDK
|
|
130
|
+
- This mode is ideal for wallet integrations, multi-signature scenarios, and when you need transaction review before execution
|
|
131
|
+
|
|
54
132
|
## Features
|
|
55
133
|
|
|
56
134
|
- **Automatic Key Detection**: Smart detection of ED25519 and ECDSA key types via mirror node
|
|
@@ -59,12 +137,14 @@ console.log(response.response);
|
|
|
59
137
|
- **TypeScript Support**: Full type definitions for all components
|
|
60
138
|
- **State Management**: Integrated state management for agent operations
|
|
61
139
|
- **CLI Interface**: Beautiful terminal interface for interactive agent communication
|
|
140
|
+
- **MCP Support**: Extend agent capabilities with Model Context Protocol servers
|
|
62
141
|
|
|
63
142
|
## Available Tools
|
|
64
143
|
|
|
65
|
-
The Conversational Agent includes all tools from the
|
|
144
|
+
The Conversational Agent includes all tools from the `hedera-agent-kit` v2 package, providing comprehensive access to Hedera network functionality:
|
|
66
145
|
|
|
67
146
|
### Core Hedera Tools (from hedera-agent-kit)
|
|
147
|
+
|
|
68
148
|
- **Account Management**: Create accounts, transfer HBAR, manage allowances, get account info
|
|
69
149
|
- **Token Service (HTS)**: Create tokens/NFTs, mint, burn, transfer, manage token properties
|
|
70
150
|
- **Smart Contract Service**: Deploy contracts, execute functions, query contract state
|
|
@@ -73,6 +153,7 @@ The Conversational Agent includes all tools from the `@hashgraphonline/hedera-ag
|
|
|
73
153
|
- **Network Queries**: Get network info, HBAR price, transaction details
|
|
74
154
|
|
|
75
155
|
### HCS-10 Agent Communication Tools
|
|
156
|
+
|
|
76
157
|
- **RegisterAgentTool**: Register new agents with capabilities and tags
|
|
77
158
|
- **FindRegistrationsTool**: Search for agents by account ID or tags
|
|
78
159
|
- **RetrieveProfileTool**: Get detailed agent profiles
|
|
@@ -86,6 +167,7 @@ The Conversational Agent includes all tools from the `@hashgraphonline/hedera-ag
|
|
|
86
167
|
- **CheckMessagesTool**: Retrieve messages from connections
|
|
87
168
|
|
|
88
169
|
### HCS-2 Registry Tools
|
|
170
|
+
|
|
89
171
|
- **CreateRegistryTool**: Create new HCS-2 registry topics
|
|
90
172
|
- **RegisterEntryTool**: Add entries to existing registries
|
|
91
173
|
- **UpdateEntryTool**: Modify existing entries in registries
|
|
@@ -94,6 +176,7 @@ The Conversational Agent includes all tools from the `@hashgraphonline/hedera-ag
|
|
|
94
176
|
- **QueryRegistryTool**: Retrieve entries from registries
|
|
95
177
|
|
|
96
178
|
### Inscription Tools
|
|
179
|
+
|
|
97
180
|
- **InscribeFromUrlTool**: Inscribe content from URLs
|
|
98
181
|
- **InscribeFromFileTool**: Inscribe content from local files
|
|
99
182
|
- **InscribeFromBufferTool**: Inscribe content from memory buffers
|
|
@@ -181,7 +264,9 @@ const MyToolSchema = z.object({
|
|
|
181
264
|
param2: z.number().optional().describe('Optional second parameter'),
|
|
182
265
|
});
|
|
183
266
|
|
|
184
|
-
export class MyCustomTool extends BaseHederaTransactionTool<
|
|
267
|
+
export class MyCustomTool extends BaseHederaTransactionTool<
|
|
268
|
+
typeof MyToolSchema
|
|
269
|
+
> {
|
|
185
270
|
name = 'my-custom-tool';
|
|
186
271
|
description = 'Performs a custom Hedera transaction';
|
|
187
272
|
specificInputSchema = MyToolSchema;
|
|
@@ -216,13 +301,15 @@ const agent = new ConversationalAgent({
|
|
|
216
301
|
network: 'testnet',
|
|
217
302
|
openAIApiKey: process.env.OPENAI_API_KEY!,
|
|
218
303
|
// Add your custom plugins
|
|
219
|
-
additionalPlugins: [new MyCustomPlugin()]
|
|
304
|
+
additionalPlugins: [new MyCustomPlugin()],
|
|
220
305
|
});
|
|
221
306
|
|
|
222
307
|
await agent.initialize();
|
|
223
308
|
|
|
224
309
|
// Your custom tools are now available to the agent
|
|
225
|
-
const response = await agent.processMessage(
|
|
310
|
+
const response = await agent.processMessage(
|
|
311
|
+
'Use my custom tool with param1 "test"'
|
|
312
|
+
);
|
|
226
313
|
```
|
|
227
314
|
|
|
228
315
|
### Plugin Best Practices
|
|
@@ -237,24 +324,24 @@ For more details, see our [Plugin Development Guide](docs/PLUGIN_DEVELOPMENT.md)
|
|
|
237
324
|
|
|
238
325
|
## Configuration Options
|
|
239
326
|
|
|
240
|
-
| Option
|
|
241
|
-
|
|
242
|
-
| `accountId`
|
|
243
|
-
| `privateKey`
|
|
244
|
-
| `network`
|
|
245
|
-
| `openAIApiKey`
|
|
246
|
-
| `openAIModelName`
|
|
247
|
-
| `verbose`
|
|
248
|
-
| `operationalMode`
|
|
249
|
-
| `userAccountId`
|
|
250
|
-
| `customSystemMessagePreamble`
|
|
251
|
-
| `customSystemMessagePostamble`
|
|
252
|
-
| `additionalPlugins`
|
|
253
|
-
| `stateManager`
|
|
254
|
-
| `scheduleUserTransactionsInBytesMode` | boolean
|
|
255
|
-
| `mirrorNodeConfig`
|
|
256
|
-
| `disableLogging`
|
|
257
|
-
| `enabledPlugins`
|
|
327
|
+
| Option | Type | Default | Description |
|
|
328
|
+
| ------------------------------------- | -------------------- | --------------- | ---------------------------------------------- |
|
|
329
|
+
| `accountId` | string | **required** | Hedera account ID (e.g., '0.0.12345') |
|
|
330
|
+
| `privateKey` | string | **required** | Private key for the account |
|
|
331
|
+
| `network` | NetworkType | 'testnet' | Network to connect to ('mainnet' or 'testnet') |
|
|
332
|
+
| `openAIApiKey` | string | **required** | OpenAI API key for the LLM |
|
|
333
|
+
| `openAIModelName` | string | 'gpt-4o' | OpenAI model to use |
|
|
334
|
+
| `verbose` | boolean | false | Enable verbose logging |
|
|
335
|
+
| `operationalMode` | AgentOperationalMode | 'autonomous' | 'autonomous' or 'returnBytes' |
|
|
336
|
+
| `userAccountId` | string | undefined | User's account ID for transaction context |
|
|
337
|
+
| `customSystemMessagePreamble` | string | instructions | Custom system message prefix |
|
|
338
|
+
| `customSystemMessagePostamble` | string | undefined | Custom system message suffix |
|
|
339
|
+
| `additionalPlugins` | BasePlugin[] | [] | Additional plugins to load |
|
|
340
|
+
| `stateManager` | IStateManager | OpenConvaiState | Custom state manager |
|
|
341
|
+
| `scheduleUserTransactionsInBytesMode` | boolean | false | Schedule transactions in bytes mode |
|
|
342
|
+
| `mirrorNodeConfig` | MirrorNodeConfig | undefined | Custom mirror node configuration |
|
|
343
|
+
| `disableLogging` | boolean | false | Disable all logging |
|
|
344
|
+
| `enabledPlugins` | string[] | undefined | Filter which plugins to enable by ID |
|
|
258
345
|
|
|
259
346
|
## Environment Variables
|
|
260
347
|
|
|
@@ -273,7 +360,9 @@ HEDERA_NETWORK=testnet # defaults to testnet
|
|
|
273
360
|
### Direct Plugin Access
|
|
274
361
|
|
|
275
362
|
```typescript
|
|
276
|
-
const agent = new ConversationalAgent({
|
|
363
|
+
const agent = new ConversationalAgent({
|
|
364
|
+
/* config */
|
|
365
|
+
});
|
|
277
366
|
await agent.initialize();
|
|
278
367
|
|
|
279
368
|
// Access plugins directly
|
|
@@ -298,7 +387,7 @@ const customStateManager = new OpenConvaiState();
|
|
|
298
387
|
|
|
299
388
|
const agent = new ConversationalAgent({
|
|
300
389
|
// ... other config
|
|
301
|
-
stateManager: customStateManager
|
|
390
|
+
stateManager: customStateManager,
|
|
302
391
|
});
|
|
303
392
|
```
|
|
304
393
|
|
|
@@ -312,7 +401,7 @@ const htsAgent = ConversationalAgent.withHTS({
|
|
|
312
401
|
accountId: process.env.HEDERA_ACCOUNT_ID!,
|
|
313
402
|
privateKey: process.env.HEDERA_PRIVATE_KEY!,
|
|
314
403
|
network: 'testnet',
|
|
315
|
-
openAIApiKey: process.env.OPENAI_API_KEY
|
|
404
|
+
openAIApiKey: process.env.OPENAI_API_KEY!,
|
|
316
405
|
});
|
|
317
406
|
|
|
318
407
|
// Create agent with only HCS-2 registry tools
|
|
@@ -320,7 +409,7 @@ const hcs2Agent = ConversationalAgent.withHCS2({
|
|
|
320
409
|
accountId: process.env.HEDERA_ACCOUNT_ID!,
|
|
321
410
|
privateKey: process.env.HEDERA_PRIVATE_KEY!,
|
|
322
411
|
network: 'testnet',
|
|
323
|
-
openAIApiKey: process.env.OPENAI_API_KEY
|
|
412
|
+
openAIApiKey: process.env.OPENAI_API_KEY!,
|
|
324
413
|
});
|
|
325
414
|
|
|
326
415
|
// Other presets available:
|
|
@@ -345,11 +434,12 @@ const agent = new ConversationalAgent({
|
|
|
345
434
|
network: 'testnet',
|
|
346
435
|
openAIApiKey: process.env.OPENAI_API_KEY!,
|
|
347
436
|
// Only enable specific plugins by their ID
|
|
348
|
-
enabledPlugins: ['hcs-10', 'hts-token', 'account']
|
|
437
|
+
enabledPlugins: ['hcs-10', 'hts-token', 'account'],
|
|
349
438
|
});
|
|
350
439
|
```
|
|
351
440
|
|
|
352
441
|
Available plugin IDs:
|
|
442
|
+
|
|
353
443
|
- Standard plugins: `hcs-10`, `hcs-2`, `inscribe`
|
|
354
444
|
- Core Hedera plugins: `hts-token`, `account`, `file-service`, `consensus-service`, `smart-contract`, `network`
|
|
355
445
|
|
|
@@ -359,19 +449,19 @@ If you need to use this with hedera-agent-kit 2.0.3:
|
|
|
359
449
|
|
|
360
450
|
```typescript
|
|
361
451
|
import { HederaConversationalAgent, ServerSigner } from 'hedera-agent-kit';
|
|
362
|
-
import {
|
|
452
|
+
import {
|
|
453
|
+
HCS10Plugin,
|
|
454
|
+
HCS2Plugin,
|
|
455
|
+
InscribePlugin,
|
|
456
|
+
} from '@hashgraphonline/conversational-agent';
|
|
363
457
|
|
|
364
458
|
const signer = new ServerSigner(accountId, privateKey, network);
|
|
365
459
|
|
|
366
460
|
const agent = new HederaConversationalAgent(signer, {
|
|
367
461
|
pluginConfig: {
|
|
368
|
-
plugins: [
|
|
369
|
-
new HCS10Plugin(),
|
|
370
|
-
new HCS2Plugin(),
|
|
371
|
-
new InscribePlugin()
|
|
372
|
-
]
|
|
462
|
+
plugins: [new HCS10Plugin(), new HCS2Plugin(), new InscribePlugin()],
|
|
373
463
|
},
|
|
374
|
-
openAIApiKey: process.env.OPENAI_API_KEY
|
|
464
|
+
openAIApiKey: process.env.OPENAI_API_KEY!,
|
|
375
465
|
});
|
|
376
466
|
```
|
|
377
467
|
|
|
@@ -380,8 +470,86 @@ const agent = new HederaConversationalAgent(signer, {
|
|
|
380
470
|
- [Conversational Agent Documentation](https://hashgraphonline.com/docs/libraries/conversational-agent/)
|
|
381
471
|
- [Standards Agent Kit Documentation](https://hashgraphonline.com/docs/libraries/standards-agent-kit/)
|
|
382
472
|
- [HCS Standards Documentation](https://hcs-improvement-proposals.pages.dev/docs/standards)
|
|
473
|
+
- [MCP Integration Guide](./docs/MCP_INTEGRATION.md)
|
|
383
474
|
- [GitHub Repository](https://github.com/hashgraph-online/conversational-agent)
|
|
384
475
|
|
|
476
|
+
## Contributing
|
|
477
|
+
|
|
478
|
+
We welcome contributions from the community! Whether you're fixing bugs, adding features, or creating new plugins, your contributions help make the Conversational Agent better for everyone.
|
|
479
|
+
|
|
480
|
+
### Contributing a Plugin
|
|
481
|
+
|
|
482
|
+
If you've created a plugin that extends the Conversational Agent's capabilities, we'd love to include it in the repository. Here's how:
|
|
483
|
+
|
|
484
|
+
1. **Fork the Repository**
|
|
485
|
+
```bash
|
|
486
|
+
git clone https://github.com/hashgraph-online/conversational-agent.git
|
|
487
|
+
cd conversational-agent
|
|
488
|
+
pnpm install
|
|
489
|
+
```
|
|
490
|
+
|
|
491
|
+
2. **Create Your Plugin**
|
|
492
|
+
- Place your plugin in `src/plugins/community/[your-plugin-name]/`
|
|
493
|
+
- Follow the plugin structure outlined in the [Plugin Development Guide](docs/PLUGIN_DEVELOPMENT.md)
|
|
494
|
+
- Include comprehensive tests in `src/plugins/community/[your-plugin-name]/__tests__/`
|
|
495
|
+
- Add documentation in `src/plugins/community/[your-plugin-name]/README.md`
|
|
496
|
+
|
|
497
|
+
3. **Plugin Requirements**
|
|
498
|
+
- Must extend `BasePlugin` from hedera-agent-kit
|
|
499
|
+
- Include clear tool descriptions for AI understanding
|
|
500
|
+
- Add proper error handling and validation
|
|
501
|
+
- Follow TypeScript best practices
|
|
502
|
+
- Include unit tests with >80% coverage
|
|
503
|
+
- Document all configuration options
|
|
504
|
+
- Add usage examples
|
|
505
|
+
|
|
506
|
+
4. **Submit a Pull Request**
|
|
507
|
+
- Create a feature branch: `git checkout -b feature/add-[plugin-name]-plugin`
|
|
508
|
+
- Commit your changes with clear messages
|
|
509
|
+
- Push to your fork and create a PR
|
|
510
|
+
- Include a description of what your plugin does and why it's useful
|
|
511
|
+
- Link to any relevant HCS standards or documentation
|
|
512
|
+
|
|
513
|
+
### Plugin Review Process
|
|
514
|
+
|
|
515
|
+
1. **Code Review**: Maintainers will review your code for quality, security, and adherence to standards
|
|
516
|
+
2. **Testing**: All tests must pass, and the plugin must work with the latest agent version
|
|
517
|
+
3. **Documentation**: Clear documentation and examples are required
|
|
518
|
+
4. **Integration**: Once approved, your plugin will be added to the community plugins directory
|
|
519
|
+
|
|
520
|
+
### Example Plugin Structure
|
|
521
|
+
|
|
522
|
+
```
|
|
523
|
+
src/plugins/community/your-plugin/
|
|
524
|
+
├── index.ts # Main plugin export
|
|
525
|
+
├── YourPlugin.ts # Plugin implementation
|
|
526
|
+
├── tools/ # Tool implementations
|
|
527
|
+
│ ├── YourTool1.ts
|
|
528
|
+
│ └── YourTool2.ts
|
|
529
|
+
├── __tests__/ # Test files
|
|
530
|
+
│ ├── YourPlugin.test.ts
|
|
531
|
+
│ └── tools/
|
|
532
|
+
│ ├── YourTool1.test.ts
|
|
533
|
+
│ └── YourTool2.test.ts
|
|
534
|
+
├── README.md # Plugin documentation
|
|
535
|
+
└── package.json # Plugin metadata (optional)
|
|
536
|
+
```
|
|
537
|
+
|
|
538
|
+
### General Contribution Guidelines
|
|
539
|
+
|
|
540
|
+
- **Code Style**: Follow the existing code style and linting rules
|
|
541
|
+
- **Commits**: Use clear, descriptive commit messages
|
|
542
|
+
- **Documentation**: Update relevant documentation for any changes
|
|
543
|
+
- **Tests**: Add tests for new functionality
|
|
544
|
+
- **Issues**: Open an issue before working on major changes
|
|
545
|
+
|
|
546
|
+
### Getting Help
|
|
547
|
+
|
|
548
|
+
- Join our [Discord community](https://discord.gg/hashgraphonline) for discussions
|
|
549
|
+
- Check existing issues and PRs before starting work
|
|
550
|
+
- Ask questions in the #development channel
|
|
551
|
+
- Review the [HCS Standards](https://hcs-improvement-proposals.pages.dev/docs/standards) for protocol details
|
|
552
|
+
|
|
385
553
|
## License
|
|
386
554
|
|
|
387
|
-
Apache-2.0
|
|
555
|
+
Apache-2.0
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { BaseMessage } from '@langchain/core/messages';
|
|
2
|
+
import { StructuredTool } from '@langchain/core/tools';
|
|
3
|
+
import { TransactionReceipt } from '@hashgraph/sdk';
|
|
4
|
+
import { HederaAgentKit, ServerSigner, TokenUsageCallbackHandler, TokenUsage, BasePlugin, CostCalculation } from 'hedera-agent-kit';
|
|
5
|
+
import { AIProvider, VercelAIProvider, BAMLProvider } from './providers';
|
|
6
|
+
import { Logger } from '@hashgraphonline/standards-sdk';
|
|
7
|
+
import { MCPServerConfig } from './mcp/types';
|
|
8
|
+
|
|
9
|
+
export interface ToolFilterConfig {
|
|
10
|
+
namespaceWhitelist?: string[];
|
|
11
|
+
toolBlacklist?: string[];
|
|
12
|
+
toolPredicate?: (tool: StructuredTool) => boolean;
|
|
13
|
+
}
|
|
14
|
+
export type ExecutionMode = 'direct' | 'bytes';
|
|
15
|
+
export type OperationalMode = 'autonomous' | 'returnBytes';
|
|
16
|
+
export interface HederaAgentConfiguration {
|
|
17
|
+
signer: ServerSigner;
|
|
18
|
+
execution?: {
|
|
19
|
+
mode?: ExecutionMode;
|
|
20
|
+
operationalMode?: OperationalMode;
|
|
21
|
+
userAccountId?: string;
|
|
22
|
+
scheduleUserTransactions?: boolean;
|
|
23
|
+
scheduleUserTransactionsInBytesMode?: boolean;
|
|
24
|
+
};
|
|
25
|
+
ai?: {
|
|
26
|
+
provider?: AIProvider;
|
|
27
|
+
llm?: unknown;
|
|
28
|
+
apiKey?: string;
|
|
29
|
+
modelName?: string;
|
|
30
|
+
temperature?: number;
|
|
31
|
+
};
|
|
32
|
+
filtering?: ToolFilterConfig;
|
|
33
|
+
messaging?: {
|
|
34
|
+
systemPreamble?: string;
|
|
35
|
+
systemPostamble?: string;
|
|
36
|
+
conciseMode?: boolean;
|
|
37
|
+
};
|
|
38
|
+
extensions?: {
|
|
39
|
+
plugins?: BasePlugin[];
|
|
40
|
+
mirrorConfig?: Record<string, unknown>;
|
|
41
|
+
modelCapability?: string;
|
|
42
|
+
};
|
|
43
|
+
mcp?: {
|
|
44
|
+
servers?: MCPServerConfig[];
|
|
45
|
+
autoConnect?: boolean;
|
|
46
|
+
};
|
|
47
|
+
debug?: {
|
|
48
|
+
verbose?: boolean;
|
|
49
|
+
silent?: boolean;
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
export interface ConversationContext {
|
|
53
|
+
messages: BaseMessage[];
|
|
54
|
+
metadata?: Record<string, unknown>;
|
|
55
|
+
}
|
|
56
|
+
export interface ChatResponse {
|
|
57
|
+
output: string;
|
|
58
|
+
message?: string;
|
|
59
|
+
transactionBytes?: string;
|
|
60
|
+
receipt?: TransactionReceipt | object;
|
|
61
|
+
scheduleId?: string;
|
|
62
|
+
transactionId?: string;
|
|
63
|
+
notes?: string[];
|
|
64
|
+
error?: string;
|
|
65
|
+
intermediateSteps?: unknown;
|
|
66
|
+
rawToolOutput?: unknown;
|
|
67
|
+
tokenUsage?: TokenUsage;
|
|
68
|
+
cost?: CostCalculation;
|
|
69
|
+
metadata?: Record<string, unknown>;
|
|
70
|
+
[key: string]: unknown;
|
|
71
|
+
}
|
|
72
|
+
export interface UsageStats extends TokenUsage {
|
|
73
|
+
cost: CostCalculation;
|
|
74
|
+
}
|
|
75
|
+
export declare abstract class BaseAgent {
|
|
76
|
+
protected config: HederaAgentConfiguration;
|
|
77
|
+
protected logger: Logger;
|
|
78
|
+
protected agentKit: HederaAgentKit | undefined;
|
|
79
|
+
protected tools: StructuredTool[];
|
|
80
|
+
protected initialized: boolean;
|
|
81
|
+
protected tokenTracker: TokenUsageCallbackHandler | undefined;
|
|
82
|
+
constructor(config: HederaAgentConfiguration);
|
|
83
|
+
abstract boot(): Promise<void>;
|
|
84
|
+
abstract chat(message: string, context?: ConversationContext): Promise<ChatResponse>;
|
|
85
|
+
abstract shutdown(): Promise<void>;
|
|
86
|
+
abstract switchMode(mode: OperationalMode): void;
|
|
87
|
+
abstract getUsageStats(): UsageStats;
|
|
88
|
+
abstract getUsageLog(): UsageStats[];
|
|
89
|
+
abstract clearUsageStats(): void;
|
|
90
|
+
getCore(): HederaAgentKit | undefined;
|
|
91
|
+
protected filterTools(tools: StructuredTool[]): StructuredTool[];
|
|
92
|
+
protected buildSystemPrompt(): string;
|
|
93
|
+
isReady(): boolean;
|
|
94
|
+
}
|
|
95
|
+
export type { AIProvider, VercelAIProvider, BAMLProvider };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const
|
|
1
|
+
export declare const getSystemMessage: (accountId: string) => string;
|
|
@@ -1,9 +1,13 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { BasePlugin, AgentOperationalMode, MirrorNodeConfig } from 'hedera-agent-kit';
|
|
2
|
+
import { NetworkType } from '@hashgraphonline/standards-sdk';
|
|
3
|
+
import { createAgent } from './agent-factory';
|
|
4
|
+
import { ChatResponse } from './base-agent';
|
|
2
5
|
import { HCS10Plugin } from './plugins/hcs-10/HCS10Plugin';
|
|
3
6
|
import { HCS2Plugin } from './plugins/hcs-2/HCS2Plugin';
|
|
4
7
|
import { InscribePlugin } from './plugins/inscribe/InscribePlugin';
|
|
8
|
+
import { HbarTransferPlugin } from './plugins/hbar-transfer/HbarTransferPlugin';
|
|
5
9
|
import { IStateManager } from '@hashgraphonline/standards-agent-kit';
|
|
6
|
-
import {
|
|
10
|
+
import { MCPServerConfig } from './mcp/types';
|
|
7
11
|
|
|
8
12
|
export interface ConversationalAgentOptions {
|
|
9
13
|
accountId: string;
|
|
@@ -22,6 +26,11 @@ export interface ConversationalAgentOptions {
|
|
|
22
26
|
mirrorNodeConfig?: MirrorNodeConfig;
|
|
23
27
|
disableLogging?: boolean;
|
|
24
28
|
enabledPlugins?: string[];
|
|
29
|
+
toolFilter?: (tool: {
|
|
30
|
+
name: string;
|
|
31
|
+
namespace?: string;
|
|
32
|
+
}) => boolean;
|
|
33
|
+
mcpServers?: MCPServerConfig[];
|
|
25
34
|
}
|
|
26
35
|
/**
|
|
27
36
|
* The ConversationalAgent class is an optional wrapper around the HederaConversationalAgent class,
|
|
@@ -33,22 +42,58 @@ export interface ConversationalAgentOptions {
|
|
|
33
42
|
* @returns A new instance of the ConversationalAgent class.
|
|
34
43
|
*/
|
|
35
44
|
export declare class ConversationalAgent {
|
|
36
|
-
|
|
45
|
+
private agent?;
|
|
37
46
|
hcs10Plugin: HCS10Plugin;
|
|
38
47
|
hcs2Plugin: HCS2Plugin;
|
|
39
48
|
inscribePlugin: InscribePlugin;
|
|
49
|
+
hbarTransferPlugin: HbarTransferPlugin;
|
|
40
50
|
stateManager: IStateManager;
|
|
41
51
|
private options;
|
|
42
52
|
private logger;
|
|
43
53
|
constructor(options: ConversationalAgentOptions);
|
|
54
|
+
/**
|
|
55
|
+
* Initialize the conversational agent with Hedera network connection and AI configuration
|
|
56
|
+
* @throws {Error} If account ID or private key is missing
|
|
57
|
+
* @throws {Error} If initialization fails
|
|
58
|
+
*/
|
|
44
59
|
initialize(): Promise<void>;
|
|
60
|
+
/**
|
|
61
|
+
* Get the HCS-10 plugin instance
|
|
62
|
+
* @returns {HCS10Plugin} The HCS-10 plugin instance
|
|
63
|
+
*/
|
|
45
64
|
getPlugin(): HCS10Plugin;
|
|
65
|
+
/**
|
|
66
|
+
* Get the state manager instance
|
|
67
|
+
* @returns {IStateManager} The state manager instance
|
|
68
|
+
*/
|
|
46
69
|
getStateManager(): IStateManager;
|
|
47
|
-
|
|
70
|
+
/**
|
|
71
|
+
* Get the underlying agent instance
|
|
72
|
+
* @returns {ReturnType<typeof createAgent>} The agent instance
|
|
73
|
+
* @throws {Error} If agent is not initialized
|
|
74
|
+
*/
|
|
75
|
+
getAgent(): ReturnType<typeof createAgent>;
|
|
76
|
+
/**
|
|
77
|
+
* Get the conversational agent instance (alias for getAgent)
|
|
78
|
+
* @returns {ReturnType<typeof createAgent>} The agent instance
|
|
79
|
+
* @throws {Error} If agent is not initialized
|
|
80
|
+
*/
|
|
81
|
+
getConversationalAgent(): ReturnType<typeof createAgent>;
|
|
82
|
+
/**
|
|
83
|
+
* Process a message through the conversational agent
|
|
84
|
+
* @param {string} message - The message to process
|
|
85
|
+
* @param {Array<{type: 'human' | 'ai'; content: string}>} chatHistory - Previous chat history
|
|
86
|
+
* @returns {Promise<ChatResponse>} The agent's response
|
|
87
|
+
* @throws {Error} If agent is not initialized
|
|
88
|
+
*/
|
|
48
89
|
processMessage(message: string, chatHistory?: {
|
|
49
90
|
type: 'human' | 'ai';
|
|
50
91
|
content: string;
|
|
51
|
-
}[]): Promise<
|
|
92
|
+
}[]): Promise<ChatResponse>;
|
|
93
|
+
/**
|
|
94
|
+
* Create a ConversationalAgent with specific plugins enabled
|
|
95
|
+
*/
|
|
96
|
+
private static withPlugins;
|
|
52
97
|
/**
|
|
53
98
|
* Create a ConversationalAgent with only HTS (Hedera Token Service) tools enabled
|
|
54
99
|
*/
|
|
@@ -89,4 +134,16 @@ export declare class ConversationalAgent {
|
|
|
89
134
|
* Create a ConversationalAgent with minimal Hedera tools (no HCS standards)
|
|
90
135
|
*/
|
|
91
136
|
static minimal(options: ConversationalAgentOptions): ConversationalAgent;
|
|
137
|
+
/**
|
|
138
|
+
* Create a ConversationalAgent with MCP servers configured
|
|
139
|
+
*/
|
|
140
|
+
static withMCP(options: ConversationalAgentOptions, mcpServers: MCPServerConfig[]): ConversationalAgent;
|
|
141
|
+
/**
|
|
142
|
+
* Detect the private key type by querying the account info from mirror node
|
|
143
|
+
* @param {string} accountId - The Hedera account ID
|
|
144
|
+
* @param {string} privateKey - The private key string
|
|
145
|
+
* @param {NetworkType} network - The Hedera network
|
|
146
|
+
* @returns {Promise<PrivateKey>} The appropriate PrivateKey instance
|
|
147
|
+
*/
|
|
148
|
+
private detectPrivateKeyType;
|
|
92
149
|
}
|