@hashgraphonline/conversational-agent 0.0.1
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/LICENSE +189 -0
- package/README.md +387 -0
- package/dist/cjs/config/system-message.d.ts +1 -0
- package/dist/cjs/conversational-agent.d.ts +92 -0
- package/dist/cjs/index.cjs +2 -0
- package/dist/cjs/index.cjs.map +1 -0
- package/dist/cjs/index.d.ts +7 -0
- package/dist/cjs/plugins/hcs-10/HCS10Plugin.d.ts +18 -0
- package/dist/cjs/plugins/hcs-10/index.d.ts +1 -0
- package/dist/cjs/plugins/hcs-2/HCS2Plugin.d.ts +18 -0
- package/dist/cjs/plugins/hcs-2/index.d.ts +1 -0
- package/dist/cjs/plugins/index.d.ts +3 -0
- package/dist/cjs/plugins/inscribe/InscribePlugin.d.ts +18 -0
- package/dist/cjs/plugins/inscribe/index.d.ts +1 -0
- package/dist/esm/index.js +12 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/index2.js +122 -0
- package/dist/esm/index2.js.map +1 -0
- package/dist/esm/index3.js +87 -0
- package/dist/esm/index3.js.map +1 -0
- package/dist/esm/index4.js +82 -0
- package/dist/esm/index4.js.map +1 -0
- package/dist/esm/index5.js +217 -0
- package/dist/esm/index5.js.map +1 -0
- package/dist/esm/index6.js +16 -0
- package/dist/esm/index6.js.map +1 -0
- package/dist/types/config/system-message.d.ts +1 -0
- package/dist/types/conversational-agent.d.ts +92 -0
- package/dist/types/index.d.ts +7 -0
- package/dist/types/plugins/hcs-10/HCS10Plugin.d.ts +18 -0
- package/dist/types/plugins/hcs-10/index.d.ts +1 -0
- package/dist/types/plugins/hcs-2/HCS2Plugin.d.ts +18 -0
- package/dist/types/plugins/hcs-2/index.d.ts +1 -0
- package/dist/types/plugins/index.d.ts +3 -0
- package/dist/types/plugins/inscribe/InscribePlugin.d.ts +18 -0
- package/dist/types/plugins/inscribe/index.d.ts +1 -0
- package/package.json +103 -0
- package/src/config/system-message.ts +12 -0
- package/src/conversational-agent.ts +309 -0
- package/src/index.ts +9 -0
- package/src/plugins/hcs-10/HCS10Plugin.ts +152 -0
- package/src/plugins/hcs-10/index.ts +1 -0
- package/src/plugins/hcs-2/HCS2Plugin.ts +108 -0
- package/src/plugins/hcs-2/index.ts +1 -0
- package/src/plugins/index.ts +3 -0
- package/src/plugins/inscribe/InscribePlugin.ts +102 -0
- package/src/plugins/inscribe/index.ts +1 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
SPDX-License-Identifier: Apache-2.0
|
package/README.md
ADDED
|
@@ -0,0 +1,387 @@
|
|
|
1
|
+
# Hashgraph Online Conversational Agent
|
|
2
|
+
|
|
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
|
+
| :-------------------------------------------- | :-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
5
|
+
|
|
6
|
+
## Overview
|
|
7
|
+
|
|
8
|
+
The Hashgraph Online Conversational Agent provides a comprehensive AI agent implementation that supports:
|
|
9
|
+
|
|
10
|
+
- **HCS-10**: AI Agent Communication standard for trustless peer-to-peer messaging
|
|
11
|
+
- **HCS-2**: Registry management for decentralized data storage
|
|
12
|
+
- **Inscription**: Content inscription following Hashgraph Consensus Standards
|
|
13
|
+
|
|
14
|
+
### Important Compatibility Note
|
|
15
|
+
|
|
16
|
+
This package is designed to work as a standalone conversational agent. While it can be used with `hedera-agent-kit` version 2.0.3 **only** (version 3.x no longer supports the plugin architecture), the recommended approach is to use the `ConversationalAgent` class directly.
|
|
17
|
+
|
|
18
|
+
## Installation
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
# Install the conversational agent
|
|
22
|
+
npm install @hashgraphonline/conversational-agent
|
|
23
|
+
|
|
24
|
+
# Required dependencies
|
|
25
|
+
npm install @hashgraph/sdk @hashgraphonline/standards-sdk
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Quick Start
|
|
29
|
+
|
|
30
|
+
```typescript
|
|
31
|
+
import { ConversationalAgent } from '@hashgraphonline/conversational-agent';
|
|
32
|
+
|
|
33
|
+
// Initialize the agent
|
|
34
|
+
const agent = new ConversationalAgent({
|
|
35
|
+
accountId: process.env.HEDERA_ACCOUNT_ID!,
|
|
36
|
+
privateKey: process.env.HEDERA_PRIVATE_KEY!,
|
|
37
|
+
network: 'testnet',
|
|
38
|
+
openAIApiKey: process.env.OPENAI_API_KEY!,
|
|
39
|
+
openAIModelName: 'gpt-4o',
|
|
40
|
+
verbose: true
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
// Initialize (automatically detects key type)
|
|
44
|
+
await agent.initialize();
|
|
45
|
+
|
|
46
|
+
// Process a message
|
|
47
|
+
const response = await agent.processMessage(
|
|
48
|
+
'Register me as an AI agent with the name TestBot, a random unique alias, and description "A test bot"'
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
console.log(response.response);
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## Features
|
|
55
|
+
|
|
56
|
+
- **Automatic Key Detection**: Smart detection of ED25519 and ECDSA key types via mirror node
|
|
57
|
+
- **Multiple HCS Standards**: Built-in support for HCS-10, HCS-2, and inscription standards
|
|
58
|
+
- **Three Plugin System**: HCS10Plugin, HCS2Plugin, and InscribePlugin
|
|
59
|
+
- **TypeScript Support**: Full type definitions for all components
|
|
60
|
+
- **State Management**: Integrated state management for agent operations
|
|
61
|
+
- **CLI Interface**: Beautiful terminal interface for interactive agent communication
|
|
62
|
+
|
|
63
|
+
## Available Tools
|
|
64
|
+
|
|
65
|
+
The Conversational Agent includes all tools from the `@hashgraphonline/hedera-agent-kit` package, providing comprehensive access to Hedera network functionality:
|
|
66
|
+
|
|
67
|
+
### Core Hedera Tools (from hedera-agent-kit)
|
|
68
|
+
- **Account Management**: Create accounts, transfer HBAR, manage allowances, get account info
|
|
69
|
+
- **Token Service (HTS)**: Create tokens/NFTs, mint, burn, transfer, manage token properties
|
|
70
|
+
- **Smart Contract Service**: Deploy contracts, execute functions, query contract state
|
|
71
|
+
- **File Service**: Create, append, update, delete files on Hedera
|
|
72
|
+
- **Consensus Service**: Create topics, submit messages, retrieve topic info
|
|
73
|
+
- **Network Queries**: Get network info, HBAR price, transaction details
|
|
74
|
+
|
|
75
|
+
### HCS-10 Agent Communication Tools
|
|
76
|
+
- **RegisterAgentTool**: Register new agents with capabilities and tags
|
|
77
|
+
- **FindRegistrationsTool**: Search for agents by account ID or tags
|
|
78
|
+
- **RetrieveProfileTool**: Get detailed agent profiles
|
|
79
|
+
- **InitiateConnectionTool**: Start connections with other agents
|
|
80
|
+
- **ListConnectionsTool**: View active connections
|
|
81
|
+
- **ConnectionMonitorTool**: Monitor for incoming connection requests
|
|
82
|
+
- **ManageConnectionRequestsTool**: Handle pending connections
|
|
83
|
+
- **AcceptConnectionRequestTool**: Accept incoming connections
|
|
84
|
+
- **ListUnapprovedConnectionRequestsTool**: View pending requests
|
|
85
|
+
- **SendMessageToConnectionTool**: Send messages to connected agents
|
|
86
|
+
- **CheckMessagesTool**: Retrieve messages from connections
|
|
87
|
+
|
|
88
|
+
### HCS-2 Registry Tools
|
|
89
|
+
- **CreateRegistryTool**: Create new HCS-2 registry topics
|
|
90
|
+
- **RegisterEntryTool**: Add entries to existing registries
|
|
91
|
+
- **UpdateEntryTool**: Modify existing entries in registries
|
|
92
|
+
- **DeleteEntryTool**: Remove entries from registries
|
|
93
|
+
- **MigrateRegistryTool**: Move registries to new topics
|
|
94
|
+
- **QueryRegistryTool**: Retrieve entries from registries
|
|
95
|
+
|
|
96
|
+
### Inscription Tools
|
|
97
|
+
- **InscribeFromUrlTool**: Inscribe content from URLs
|
|
98
|
+
- **InscribeFromFileTool**: Inscribe content from local files
|
|
99
|
+
- **InscribeFromBufferTool**: Inscribe content from memory buffers
|
|
100
|
+
- **InscribeHashinalTool**: Create Hashinal NFTs with specific attributes
|
|
101
|
+
- **RetrieveInscriptionTool**: Get details of existing inscriptions
|
|
102
|
+
|
|
103
|
+
## Command Line Interface (CLI)
|
|
104
|
+
|
|
105
|
+
This package includes a beautiful terminal interface built with [Ink](https://github.com/vadimdemedes/ink) that follows Hashgraph Consensus Standards design patterns.
|
|
106
|
+
|
|
107
|
+
```bash
|
|
108
|
+
# Run the interactive CLI
|
|
109
|
+
pnpm cli
|
|
110
|
+
|
|
111
|
+
# Or with environment variables
|
|
112
|
+
export HEDERA_ACCOUNT_ID=0.0.12345
|
|
113
|
+
export HEDERA_PRIVATE_KEY=your-private-key
|
|
114
|
+
export OPENAI_API_KEY=sk-your-openai-key
|
|
115
|
+
pnpm cli
|
|
116
|
+
|
|
117
|
+
# Or with command line arguments
|
|
118
|
+
pnpm cli -- --account-id=0.0.12345 --private-key=... --openai-api-key=sk-...
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
### CLI Features
|
|
122
|
+
|
|
123
|
+
- 🎨 **Beautiful Terminal UI** - Styled with Hashgraph Consensus Standards improvement proposals design patterns
|
|
124
|
+
- 💬 **Interactive Chat** - Chat with your Hashgraph Online agent in a clean terminal interface
|
|
125
|
+
- 🔐 **Secure Configuration** - Masked input for sensitive credentials
|
|
126
|
+
- 🌈 **Gradient Text & Colors** - Brand-consistent color scheme
|
|
127
|
+
- 🚀 **Fast & Responsive** - Built with React for smooth interactions
|
|
128
|
+
- 📊 **Transaction Details** - See transaction IDs and network responses
|
|
129
|
+
|
|
130
|
+
## Creating Custom Plugins
|
|
131
|
+
|
|
132
|
+
You can extend the conversational agent with custom plugins. Here's how to create one:
|
|
133
|
+
|
|
134
|
+
### Plugin Structure
|
|
135
|
+
|
|
136
|
+
See our comprehensive [Plugin Development Guide](docs/PLUGIN_DEVELOPMENT.md) for detailed instructions.
|
|
137
|
+
|
|
138
|
+
```typescript
|
|
139
|
+
import {
|
|
140
|
+
GenericPluginContext,
|
|
141
|
+
HederaTool,
|
|
142
|
+
BasePlugin,
|
|
143
|
+
HederaAgentKit,
|
|
144
|
+
} from 'hedera-agent-kit';
|
|
145
|
+
|
|
146
|
+
export class MyCustomPlugin extends BasePlugin {
|
|
147
|
+
id = 'my-plugin';
|
|
148
|
+
name = 'MyCustomPlugin';
|
|
149
|
+
description = 'A custom plugin for specific functionality';
|
|
150
|
+
version = '1.0.0';
|
|
151
|
+
author = 'Your Name';
|
|
152
|
+
namespace = 'myplugin';
|
|
153
|
+
|
|
154
|
+
private tools: HederaTool[] = [];
|
|
155
|
+
|
|
156
|
+
override async initialize(context: GenericPluginContext): Promise<void> {
|
|
157
|
+
await super.initialize(context);
|
|
158
|
+
// Initialize your plugin and tools
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
getTools(): HederaTool[] {
|
|
162
|
+
return this.tools;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
### Creating a Custom Tool
|
|
168
|
+
|
|
169
|
+
Tools extend either `BaseHederaTransactionTool` or `BaseHederaQueryTool`:
|
|
170
|
+
|
|
171
|
+
```typescript
|
|
172
|
+
import { z } from 'zod';
|
|
173
|
+
import {
|
|
174
|
+
BaseHederaTransactionTool,
|
|
175
|
+
BaseHederaTransactionToolParams,
|
|
176
|
+
BaseServiceBuilder,
|
|
177
|
+
} from 'hedera-agent-kit';
|
|
178
|
+
|
|
179
|
+
const MyToolSchema = z.object({
|
|
180
|
+
param1: z.string().describe('First parameter'),
|
|
181
|
+
param2: z.number().optional().describe('Optional second parameter'),
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
export class MyCustomTool extends BaseHederaTransactionTool<typeof MyToolSchema> {
|
|
185
|
+
name = 'my-custom-tool';
|
|
186
|
+
description = 'Performs a custom Hedera transaction';
|
|
187
|
+
specificInputSchema = MyToolSchema;
|
|
188
|
+
namespace = 'custom';
|
|
189
|
+
|
|
190
|
+
constructor(params: BaseHederaTransactionToolParams) {
|
|
191
|
+
super(params);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
protected getServiceBuilder(): BaseServiceBuilder {
|
|
195
|
+
return this.hederaKit.consensus(); // or hts(), account(), etc.
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
protected async callBuilderMethod(
|
|
199
|
+
builder: BaseServiceBuilder,
|
|
200
|
+
specificArgs: z.infer<typeof MyToolSchema>
|
|
201
|
+
): Promise<void> {
|
|
202
|
+
// Implement your transaction logic
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
### Using Custom Plugins
|
|
208
|
+
|
|
209
|
+
```typescript
|
|
210
|
+
import { ConversationalAgent } from '@hashgraphonline/conversational-agent';
|
|
211
|
+
import { MyCustomPlugin } from './plugins/MyCustomPlugin';
|
|
212
|
+
|
|
213
|
+
const agent = new ConversationalAgent({
|
|
214
|
+
accountId: process.env.HEDERA_ACCOUNT_ID!,
|
|
215
|
+
privateKey: process.env.HEDERA_PRIVATE_KEY!,
|
|
216
|
+
network: 'testnet',
|
|
217
|
+
openAIApiKey: process.env.OPENAI_API_KEY!,
|
|
218
|
+
// Add your custom plugins
|
|
219
|
+
additionalPlugins: [new MyCustomPlugin()]
|
|
220
|
+
});
|
|
221
|
+
|
|
222
|
+
await agent.initialize();
|
|
223
|
+
|
|
224
|
+
// Your custom tools are now available to the agent
|
|
225
|
+
const response = await agent.processMessage('Use my custom tool with param1 "test"');
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
### Plugin Best Practices
|
|
229
|
+
|
|
230
|
+
1. **Extend Correct Base Classes**: Use `BaseHederaTransactionTool` or `BaseHederaQueryTool` for tools
|
|
231
|
+
2. **Define Clear Schemas**: Use Zod schemas to clearly define tool inputs
|
|
232
|
+
3. **Error Handling**: Always handle errors gracefully and return meaningful messages
|
|
233
|
+
4. **State Management**: If your plugin needs state, consider implementing a custom state manager
|
|
234
|
+
5. **Documentation**: Provide clear descriptions for your plugin and tools
|
|
235
|
+
|
|
236
|
+
For more details, see our [Plugin Development Guide](docs/PLUGIN_DEVELOPMENT.md).
|
|
237
|
+
|
|
238
|
+
## Configuration Options
|
|
239
|
+
|
|
240
|
+
| Option | Type | Default | Description |
|
|
241
|
+
|--------|------|---------|-------------|
|
|
242
|
+
| `accountId` | string | **required** | Hedera account ID (e.g., '0.0.12345') |
|
|
243
|
+
| `privateKey` | string | **required** | Private key for the account |
|
|
244
|
+
| `network` | NetworkType | 'testnet' | Network to connect to ('mainnet' or 'testnet') |
|
|
245
|
+
| `openAIApiKey` | string | **required** | OpenAI API key for the LLM |
|
|
246
|
+
| `openAIModelName` | string | 'gpt-4o' | OpenAI model to use |
|
|
247
|
+
| `verbose` | boolean | false | Enable verbose logging |
|
|
248
|
+
| `operationalMode` | AgentOperationalMode | 'autonomous' | 'autonomous' or 'returnBytes' |
|
|
249
|
+
| `userAccountId` | string | undefined | User's account ID for transaction context |
|
|
250
|
+
| `customSystemMessagePreamble` | string | instructions | Custom system message prefix |
|
|
251
|
+
| `customSystemMessagePostamble` | string | undefined | Custom system message suffix |
|
|
252
|
+
| `additionalPlugins` | BasePlugin[] | [] | Additional plugins to load |
|
|
253
|
+
| `stateManager` | IStateManager | OpenConvaiState | Custom state manager |
|
|
254
|
+
| `scheduleUserTransactionsInBytesMode` | boolean | false | Schedule transactions in bytes mode |
|
|
255
|
+
| `mirrorNodeConfig` | MirrorNodeConfig | undefined | Custom mirror node configuration |
|
|
256
|
+
| `disableLogging` | boolean | false | Disable all logging |
|
|
257
|
+
| `enabledPlugins` | string[] | undefined | Filter which plugins to enable by ID |
|
|
258
|
+
|
|
259
|
+
## Environment Variables
|
|
260
|
+
|
|
261
|
+
```bash
|
|
262
|
+
# Required
|
|
263
|
+
HEDERA_ACCOUNT_ID=0.0.12345
|
|
264
|
+
HEDERA_PRIVATE_KEY=your_private_key_here
|
|
265
|
+
OPENAI_API_KEY=your_openai_api_key
|
|
266
|
+
|
|
267
|
+
# Optional
|
|
268
|
+
HEDERA_NETWORK=testnet # defaults to testnet
|
|
269
|
+
```
|
|
270
|
+
|
|
271
|
+
## Advanced Usage
|
|
272
|
+
|
|
273
|
+
### Direct Plugin Access
|
|
274
|
+
|
|
275
|
+
```typescript
|
|
276
|
+
const agent = new ConversationalAgent({ /* config */ });
|
|
277
|
+
await agent.initialize();
|
|
278
|
+
|
|
279
|
+
// Access plugins directly
|
|
280
|
+
const hcs10Plugin = agent.hcs10Plugin;
|
|
281
|
+
const hcs2Plugin = agent.hcs2Plugin;
|
|
282
|
+
const inscribePlugin = agent.inscribePlugin;
|
|
283
|
+
|
|
284
|
+
// Access the underlying Hedera agent
|
|
285
|
+
const hederaAgent = agent.getConversationalAgent();
|
|
286
|
+
|
|
287
|
+
// Access state manager
|
|
288
|
+
const stateManager = agent.getStateManager();
|
|
289
|
+
```
|
|
290
|
+
|
|
291
|
+
### Custom State Management
|
|
292
|
+
|
|
293
|
+
```typescript
|
|
294
|
+
import { OpenConvaiState } from '@hashgraphonline/standards-agent-kit';
|
|
295
|
+
|
|
296
|
+
// Create custom state manager
|
|
297
|
+
const customStateManager = new OpenConvaiState();
|
|
298
|
+
|
|
299
|
+
const agent = new ConversationalAgent({
|
|
300
|
+
// ... other config
|
|
301
|
+
stateManager: customStateManager
|
|
302
|
+
});
|
|
303
|
+
```
|
|
304
|
+
|
|
305
|
+
### Using Plugin Presets
|
|
306
|
+
|
|
307
|
+
The ConversationalAgent provides static helper functions to create agents with specific plugin configurations:
|
|
308
|
+
|
|
309
|
+
```typescript
|
|
310
|
+
// Create agent with only HTS (Hedera Token Service) tools
|
|
311
|
+
const htsAgent = ConversationalAgent.withHTS({
|
|
312
|
+
accountId: process.env.HEDERA_ACCOUNT_ID!,
|
|
313
|
+
privateKey: process.env.HEDERA_PRIVATE_KEY!,
|
|
314
|
+
network: 'testnet',
|
|
315
|
+
openAIApiKey: process.env.OPENAI_API_KEY!
|
|
316
|
+
});
|
|
317
|
+
|
|
318
|
+
// Create agent with only HCS-2 registry tools
|
|
319
|
+
const hcs2Agent = ConversationalAgent.withHCS2({
|
|
320
|
+
accountId: process.env.HEDERA_ACCOUNT_ID!,
|
|
321
|
+
privateKey: process.env.HEDERA_PRIVATE_KEY!,
|
|
322
|
+
network: 'testnet',
|
|
323
|
+
openAIApiKey: process.env.OPENAI_API_KEY!
|
|
324
|
+
});
|
|
325
|
+
|
|
326
|
+
// Other presets available:
|
|
327
|
+
// ConversationalAgent.withHCS10() - Only HCS-10 agent communication tools
|
|
328
|
+
// ConversationalAgent.withInscribe() - Only inscription tools
|
|
329
|
+
// ConversationalAgent.withAccount() - Only account management tools
|
|
330
|
+
// ConversationalAgent.withFileService() - Only file service tools
|
|
331
|
+
// ConversationalAgent.withConsensusService() - Only consensus service tools
|
|
332
|
+
// ConversationalAgent.withSmartContract() - Only smart contract tools
|
|
333
|
+
// ConversationalAgent.withAllStandards() - All HCS standards plugins (HCS-10, HCS-2, Inscribe)
|
|
334
|
+
// ConversationalAgent.minimal() - Only basic account tools
|
|
335
|
+
```
|
|
336
|
+
|
|
337
|
+
### Plugin Filtering
|
|
338
|
+
|
|
339
|
+
You can also manually specify which plugins to enable using the `enabledPlugins` option:
|
|
340
|
+
|
|
341
|
+
```typescript
|
|
342
|
+
const agent = new ConversationalAgent({
|
|
343
|
+
accountId: process.env.HEDERA_ACCOUNT_ID!,
|
|
344
|
+
privateKey: process.env.HEDERA_PRIVATE_KEY!,
|
|
345
|
+
network: 'testnet',
|
|
346
|
+
openAIApiKey: process.env.OPENAI_API_KEY!,
|
|
347
|
+
// Only enable specific plugins by their ID
|
|
348
|
+
enabledPlugins: ['hcs-10', 'hts-token', 'account']
|
|
349
|
+
});
|
|
350
|
+
```
|
|
351
|
+
|
|
352
|
+
Available plugin IDs:
|
|
353
|
+
- Standard plugins: `hcs-10`, `hcs-2`, `inscribe`
|
|
354
|
+
- Core Hedera plugins: `hts-token`, `account`, `file-service`, `consensus-service`, `smart-contract`, `network`
|
|
355
|
+
|
|
356
|
+
### Legacy Plugin Usage (hedera-agent-kit 2.0.3 only)
|
|
357
|
+
|
|
358
|
+
If you need to use this with hedera-agent-kit 2.0.3:
|
|
359
|
+
|
|
360
|
+
```typescript
|
|
361
|
+
import { HederaConversationalAgent, ServerSigner } from 'hedera-agent-kit';
|
|
362
|
+
import { HCS10Plugin, HCS2Plugin, InscribePlugin } from '@hashgraphonline/conversational-agent';
|
|
363
|
+
|
|
364
|
+
const signer = new ServerSigner(accountId, privateKey, network);
|
|
365
|
+
|
|
366
|
+
const agent = new HederaConversationalAgent(signer, {
|
|
367
|
+
pluginConfig: {
|
|
368
|
+
plugins: [
|
|
369
|
+
new HCS10Plugin(),
|
|
370
|
+
new HCS2Plugin(),
|
|
371
|
+
new InscribePlugin()
|
|
372
|
+
]
|
|
373
|
+
},
|
|
374
|
+
openAIApiKey: process.env.OPENAI_API_KEY!
|
|
375
|
+
});
|
|
376
|
+
```
|
|
377
|
+
|
|
378
|
+
## Resources
|
|
379
|
+
|
|
380
|
+
- [Conversational Agent Documentation](https://hashgraphonline.com/docs/libraries/conversational-agent/)
|
|
381
|
+
- [Standards Agent Kit Documentation](https://hashgraphonline.com/docs/libraries/standards-agent-kit/)
|
|
382
|
+
- [HCS Standards Documentation](https://hcs-improvement-proposals.pages.dev/docs/standards)
|
|
383
|
+
- [GitHub Repository](https://github.com/hashgraph-online/conversational-agent)
|
|
384
|
+
|
|
385
|
+
## License
|
|
386
|
+
|
|
387
|
+
Apache-2.0
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const SYSTEM_MESSAGE: string;
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { HederaConversationalAgent, BasePlugin, AgentOperationalMode, AgentResponse, MirrorNodeConfig } from 'hedera-agent-kit';
|
|
2
|
+
import { HCS10Plugin } from './plugins/hcs-10/HCS10Plugin';
|
|
3
|
+
import { HCS2Plugin } from './plugins/hcs-2/HCS2Plugin';
|
|
4
|
+
import { InscribePlugin } from './plugins/inscribe/InscribePlugin';
|
|
5
|
+
import { IStateManager } from '@hashgraphonline/standards-agent-kit';
|
|
6
|
+
import { NetworkType } from '@hashgraphonline/standards-sdk';
|
|
7
|
+
|
|
8
|
+
export interface ConversationalAgentOptions {
|
|
9
|
+
accountId: string;
|
|
10
|
+
privateKey: string;
|
|
11
|
+
network?: NetworkType;
|
|
12
|
+
openAIApiKey: string;
|
|
13
|
+
openAIModelName?: string;
|
|
14
|
+
verbose?: boolean;
|
|
15
|
+
operationalMode?: AgentOperationalMode;
|
|
16
|
+
userAccountId?: string;
|
|
17
|
+
customSystemMessagePreamble?: string;
|
|
18
|
+
customSystemMessagePostamble?: string;
|
|
19
|
+
additionalPlugins?: BasePlugin[];
|
|
20
|
+
stateManager?: IStateManager;
|
|
21
|
+
scheduleUserTransactionsInBytesMode?: boolean;
|
|
22
|
+
mirrorNodeConfig?: MirrorNodeConfig;
|
|
23
|
+
disableLogging?: boolean;
|
|
24
|
+
enabledPlugins?: string[];
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* The ConversationalAgent class is an optional wrapper around the HederaConversationalAgent class,
|
|
28
|
+
* which includes the OpenConvAIPlugin and the OpenConvaiState by default.
|
|
29
|
+
* If you want to use a different plugin or state manager, you can pass them in the options.
|
|
30
|
+
* This class is not required and the plugin can be used directly with the HederaConversationalAgent class.
|
|
31
|
+
*
|
|
32
|
+
* @param options - The options for the ConversationalAgent.
|
|
33
|
+
* @returns A new instance of the ConversationalAgent class.
|
|
34
|
+
*/
|
|
35
|
+
export declare class ConversationalAgent {
|
|
36
|
+
conversationalAgent?: HederaConversationalAgent;
|
|
37
|
+
hcs10Plugin: HCS10Plugin;
|
|
38
|
+
hcs2Plugin: HCS2Plugin;
|
|
39
|
+
inscribePlugin: InscribePlugin;
|
|
40
|
+
stateManager: IStateManager;
|
|
41
|
+
private options;
|
|
42
|
+
private logger;
|
|
43
|
+
constructor(options: ConversationalAgentOptions);
|
|
44
|
+
initialize(): Promise<void>;
|
|
45
|
+
getPlugin(): HCS10Plugin;
|
|
46
|
+
getStateManager(): IStateManager;
|
|
47
|
+
getConversationalAgent(): HederaConversationalAgent;
|
|
48
|
+
processMessage(message: string, chatHistory?: {
|
|
49
|
+
type: 'human' | 'ai';
|
|
50
|
+
content: string;
|
|
51
|
+
}[]): Promise<AgentResponse>;
|
|
52
|
+
/**
|
|
53
|
+
* Create a ConversationalAgent with only HTS (Hedera Token Service) tools enabled
|
|
54
|
+
*/
|
|
55
|
+
static withHTS(options: ConversationalAgentOptions): ConversationalAgent;
|
|
56
|
+
/**
|
|
57
|
+
* Create a ConversationalAgent with only HCS-2 tools enabled
|
|
58
|
+
*/
|
|
59
|
+
static withHCS2(options: ConversationalAgentOptions): ConversationalAgent;
|
|
60
|
+
/**
|
|
61
|
+
* Create a ConversationalAgent with only HCS-10 tools enabled
|
|
62
|
+
*/
|
|
63
|
+
static withHCS10(options: ConversationalAgentOptions): ConversationalAgent;
|
|
64
|
+
/**
|
|
65
|
+
* Create a ConversationalAgent with only inscription tools enabled
|
|
66
|
+
*/
|
|
67
|
+
static withInscribe(options: ConversationalAgentOptions): ConversationalAgent;
|
|
68
|
+
/**
|
|
69
|
+
* Create a ConversationalAgent with only account management tools enabled
|
|
70
|
+
*/
|
|
71
|
+
static withAccount(options: ConversationalAgentOptions): ConversationalAgent;
|
|
72
|
+
/**
|
|
73
|
+
* Create a ConversationalAgent with only file service tools enabled
|
|
74
|
+
*/
|
|
75
|
+
static withFileService(options: ConversationalAgentOptions): ConversationalAgent;
|
|
76
|
+
/**
|
|
77
|
+
* Create a ConversationalAgent with only consensus service tools enabled
|
|
78
|
+
*/
|
|
79
|
+
static withConsensusService(options: ConversationalAgentOptions): ConversationalAgent;
|
|
80
|
+
/**
|
|
81
|
+
* Create a ConversationalAgent with only smart contract tools enabled
|
|
82
|
+
*/
|
|
83
|
+
static withSmartContract(options: ConversationalAgentOptions): ConversationalAgent;
|
|
84
|
+
/**
|
|
85
|
+
* Create a ConversationalAgent with all HCS standards plugins
|
|
86
|
+
*/
|
|
87
|
+
static withAllStandards(options: ConversationalAgentOptions): ConversationalAgent;
|
|
88
|
+
/**
|
|
89
|
+
* Create a ConversationalAgent with minimal Hedera tools (no HCS standards)
|
|
90
|
+
*/
|
|
91
|
+
static minimal(options: ConversationalAgentOptions): ConversationalAgent;
|
|
92
|
+
}
|