@hashgraphonline/standards-agent-kit 0.2.0 → 0.2.101
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 +137 -170
- package/dist/cjs/builders/hcs10/hcs10-builder.d.ts +4 -0
- package/dist/cjs/standards-agent-kit.cjs +1 -1
- package/dist/cjs/standards-agent-kit.cjs.map +1 -1
- package/dist/cjs/tools/hcs10/RegisterAgentTool.d.ts +14 -4
- package/dist/es/builders/hcs10/hcs10-builder.d.ts +4 -0
- package/dist/es/standards-agent-kit.es2.js +27 -13
- package/dist/es/standards-agent-kit.es2.js.map +1 -1
- package/dist/es/standards-agent-kit.es5.js +75 -2
- package/dist/es/standards-agent-kit.es5.js.map +1 -1
- package/dist/es/tools/hcs10/RegisterAgentTool.d.ts +14 -4
- package/dist/umd/builders/hcs10/hcs10-builder.d.ts +4 -0
- package/dist/umd/standards-agent-kit.umd.js +1 -1
- package/dist/umd/standards-agent-kit.umd.js.map +1 -1
- package/dist/umd/tools/hcs10/RegisterAgentTool.d.ts +14 -4
- package/package.json +4 -4
- package/src/builders/hcs10/hcs10-builder.ts +37 -16
- package/src/tools/hcs10/RegisterAgentTool.ts +111 -5
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { AIAgentCapability } from '@hashgraphonline/standards-sdk';
|
|
2
2
|
import { z } from 'zod';
|
|
3
3
|
import { BaseServiceBuilder } from 'hedera-agent-kit';
|
|
4
|
+
import { CallbackManagerForToolRun } from '@langchain/core/callbacks/manager';
|
|
4
5
|
import { BaseHCS10TransactionTool } from './base-hcs10-tools';
|
|
5
6
|
import { HCS10TransactionToolParams } from './hcs10-tool-params';
|
|
6
7
|
declare const RegisterAgentZodSchema: z.ZodObject<{
|
|
7
8
|
name: z.ZodString;
|
|
8
9
|
description: z.ZodOptional<z.ZodString>;
|
|
9
|
-
alias: z.ZodOptional<z.ZodString>;
|
|
10
|
+
alias: z.ZodEffects<z.ZodOptional<z.ZodString>, string, string | undefined>;
|
|
10
11
|
type: z.ZodOptional<z.ZodEnum<["autonomous", "manual"]>>;
|
|
11
12
|
model: z.ZodOptional<z.ZodString>;
|
|
12
13
|
capabilities: z.ZodOptional<z.ZodArray<z.ZodNativeEnum<typeof AIAgentCapability>, "many">>;
|
|
@@ -51,6 +52,7 @@ declare const RegisterAgentZodSchema: z.ZodObject<{
|
|
|
51
52
|
}>>;
|
|
52
53
|
}, "strip", z.ZodTypeAny, {
|
|
53
54
|
name: string;
|
|
55
|
+
alias: string;
|
|
54
56
|
tokenFees?: {
|
|
55
57
|
amount: number;
|
|
56
58
|
tokenId: string;
|
|
@@ -58,7 +60,6 @@ declare const RegisterAgentZodSchema: z.ZodObject<{
|
|
|
58
60
|
exemptAccountIds?: string[] | undefined;
|
|
59
61
|
type?: "autonomous" | "manual" | undefined;
|
|
60
62
|
description?: string | undefined;
|
|
61
|
-
alias?: string | undefined;
|
|
62
63
|
model?: string | undefined;
|
|
63
64
|
capabilities?: AIAgentCapability[] | undefined;
|
|
64
65
|
creator?: string | undefined;
|
|
@@ -112,7 +113,7 @@ export declare class RegisterAgentTool extends BaseHCS10TransactionTool<typeof R
|
|
|
112
113
|
specificInputSchema: z.ZodObject<{
|
|
113
114
|
name: z.ZodString;
|
|
114
115
|
description: z.ZodOptional<z.ZodString>;
|
|
115
|
-
alias: z.ZodOptional<z.ZodString>;
|
|
116
|
+
alias: z.ZodEffects<z.ZodOptional<z.ZodString>, string, string | undefined>;
|
|
116
117
|
type: z.ZodOptional<z.ZodEnum<["autonomous", "manual"]>>;
|
|
117
118
|
model: z.ZodOptional<z.ZodString>;
|
|
118
119
|
capabilities: z.ZodOptional<z.ZodArray<z.ZodNativeEnum<typeof AIAgentCapability>, "many">>;
|
|
@@ -157,6 +158,7 @@ export declare class RegisterAgentTool extends BaseHCS10TransactionTool<typeof R
|
|
|
157
158
|
}>>;
|
|
158
159
|
}, "strip", z.ZodTypeAny, {
|
|
159
160
|
name: string;
|
|
161
|
+
alias: string;
|
|
160
162
|
tokenFees?: {
|
|
161
163
|
amount: number;
|
|
162
164
|
tokenId: string;
|
|
@@ -164,7 +166,6 @@ export declare class RegisterAgentTool extends BaseHCS10TransactionTool<typeof R
|
|
|
164
166
|
exemptAccountIds?: string[] | undefined;
|
|
165
167
|
type?: "autonomous" | "manual" | undefined;
|
|
166
168
|
description?: string | undefined;
|
|
167
|
-
alias?: string | undefined;
|
|
168
169
|
model?: string | undefined;
|
|
169
170
|
capabilities?: AIAgentCapability[] | undefined;
|
|
170
171
|
creator?: string | undefined;
|
|
@@ -212,7 +213,16 @@ export declare class RegisterAgentTool extends BaseHCS10TransactionTool<typeof R
|
|
|
212
213
|
prefix?: string | undefined;
|
|
213
214
|
} | undefined;
|
|
214
215
|
}>;
|
|
216
|
+
private specificArgs;
|
|
215
217
|
constructor(params: HCS10TransactionToolParams);
|
|
216
218
|
protected callBuilderMethod(builder: BaseServiceBuilder, specificArgs: z.infer<typeof RegisterAgentZodSchema>): Promise<void>;
|
|
219
|
+
/**
|
|
220
|
+
* Override _call to intercept the result and save agent to state if needed
|
|
221
|
+
*/
|
|
222
|
+
protected _call(args: z.infer<ReturnType<this['schema']>>, runManager?: CallbackManagerForToolRun): Promise<string>;
|
|
223
|
+
/**
|
|
224
|
+
* Extract agent data from registration result and save to state
|
|
225
|
+
*/
|
|
226
|
+
private _handleRegistrationResult;
|
|
217
227
|
}
|
|
218
228
|
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hashgraphonline/standards-agent-kit",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.101",
|
|
4
4
|
"description": "A modular SDK for building on-chain autonomous agents using Hashgraph Online Standards, including HCS-10 for agent discovery and communication.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/cjs/standards-agent-kit.cjs",
|
|
@@ -63,7 +63,7 @@
|
|
|
63
63
|
},
|
|
64
64
|
"dependencies": {
|
|
65
65
|
"@hashgraph/sdk": "^2.67.0",
|
|
66
|
-
"@hashgraphonline/standards-sdk": "^0.0.
|
|
66
|
+
"@hashgraphonline/standards-sdk": "^0.0.149",
|
|
67
67
|
"@langchain/community": "^0.3.48",
|
|
68
68
|
"@langchain/core": "^0.3.62",
|
|
69
69
|
"@langchain/openai": "^0.5.18",
|
|
@@ -79,8 +79,8 @@
|
|
|
79
79
|
"zod": "^3.25.28"
|
|
80
80
|
},
|
|
81
81
|
"devDependencies": {
|
|
82
|
-
"@hashgraphonline/standards-agent-kit": "
|
|
83
|
-
"@hashgraphonline/standards-agent-plugin": "^0.0.
|
|
82
|
+
"@hashgraphonline/standards-agent-kit": "^0.2",
|
|
83
|
+
"@hashgraphonline/standards-agent-plugin": "^0.0.3",
|
|
84
84
|
"@rollup/plugin-commonjs": "^28.0.6",
|
|
85
85
|
"@swc/core": "^1.11.21",
|
|
86
86
|
"@swc/jest": "^0.2.36",
|
|
@@ -202,6 +202,13 @@ export class HCS10Builder extends BaseServiceBuilder {
|
|
|
202
202
|
return this.network;
|
|
203
203
|
}
|
|
204
204
|
|
|
205
|
+
/**
|
|
206
|
+
* Get state manager instance
|
|
207
|
+
*/
|
|
208
|
+
public getStateManager(): IStateManager | undefined {
|
|
209
|
+
return this.stateManager;
|
|
210
|
+
}
|
|
211
|
+
|
|
205
212
|
/**
|
|
206
213
|
* Get account and signer information
|
|
207
214
|
*/
|
|
@@ -392,17 +399,19 @@ export class HCS10Builder extends BaseServiceBuilder {
|
|
|
392
399
|
try {
|
|
393
400
|
const result = await this.standardClient.getMessages(topicId);
|
|
394
401
|
|
|
395
|
-
const mappedMessages: HCSMessageWithTimestamp[] = result.messages.map(
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
402
|
+
const mappedMessages: HCSMessageWithTimestamp[] = result.messages.map(
|
|
403
|
+
(sdkMessage) => {
|
|
404
|
+
const timestamp = sdkMessage?.created?.getTime() || 0;
|
|
405
|
+
|
|
406
|
+
return {
|
|
407
|
+
...sdkMessage,
|
|
408
|
+
timestamp: timestamp,
|
|
409
|
+
data: sdkMessage.data || '',
|
|
410
|
+
sequence_number: sdkMessage.sequence_number,
|
|
411
|
+
p: 'hcs-10' as const,
|
|
412
|
+
} as HCSMessageWithTimestamp;
|
|
413
|
+
}
|
|
414
|
+
);
|
|
406
415
|
mappedMessages.sort(
|
|
407
416
|
(a: { timestamp: number }, b: { timestamp: number }) =>
|
|
408
417
|
a.timestamp - b.timestamp
|
|
@@ -432,7 +441,9 @@ export class HCS10Builder extends BaseServiceBuilder {
|
|
|
432
441
|
);
|
|
433
442
|
}
|
|
434
443
|
|
|
435
|
-
return this.standardClient.getMessageStream(topicId) as Promise<{
|
|
444
|
+
return this.standardClient.getMessageStream(topicId) as Promise<{
|
|
445
|
+
messages: HCSMessage[];
|
|
446
|
+
}>;
|
|
436
447
|
}
|
|
437
448
|
|
|
438
449
|
/**
|
|
@@ -630,7 +641,8 @@ export class HCS10Builder extends BaseServiceBuilder {
|
|
|
630
641
|
}
|
|
631
642
|
|
|
632
643
|
try {
|
|
633
|
-
let profilePictureData: { buffer: Buffer; filename: string } | null =
|
|
644
|
+
let profilePictureData: { buffer: Buffer; filename: string } | null =
|
|
645
|
+
null;
|
|
634
646
|
if (params.profilePicture) {
|
|
635
647
|
profilePictureData = await this.loadProfilePicture(
|
|
636
648
|
params.profilePicture
|
|
@@ -1509,7 +1521,10 @@ export class HCS10Builder extends BaseServiceBuilder {
|
|
|
1509
1521
|
const messages = await this.getMessages(inboundTopicId);
|
|
1510
1522
|
|
|
1511
1523
|
const unapprovedRequests = messages.messages
|
|
1512
|
-
.filter(
|
|
1524
|
+
.filter(
|
|
1525
|
+
(msg): msg is HCSMessageWithTimestamp & { op: string } =>
|
|
1526
|
+
msg.op === 'connection_request'
|
|
1527
|
+
)
|
|
1513
1528
|
.map((msg) => ({
|
|
1514
1529
|
requestId: msg.sequence_number,
|
|
1515
1530
|
fromAccountId: msg.operator_id?.split('@')[1] || 'unknown',
|
|
@@ -1517,7 +1532,10 @@ export class HCS10Builder extends BaseServiceBuilder {
|
|
|
1517
1532
|
memo: msg.m || '',
|
|
1518
1533
|
data: msg.data,
|
|
1519
1534
|
}))
|
|
1520
|
-
.filter(
|
|
1535
|
+
.filter(
|
|
1536
|
+
(req): req is typeof req & { fromAccountId: string } =>
|
|
1537
|
+
req.fromAccountId !== 'unknown'
|
|
1538
|
+
);
|
|
1521
1539
|
|
|
1522
1540
|
this.executeResult = {
|
|
1523
1541
|
success: true,
|
|
@@ -2053,7 +2071,10 @@ export class HCS10Builder extends BaseServiceBuilder {
|
|
|
2053
2071
|
|
|
2054
2072
|
if (profile.social && Object.keys(profile.social).length > 0) {
|
|
2055
2073
|
profileDetails += `Social: ${Object.entries(profile.social)
|
|
2056
|
-
.map(
|
|
2074
|
+
.map(
|
|
2075
|
+
([platform, handle]: [string, unknown]): string =>
|
|
2076
|
+
`${platform}: ${handle}`
|
|
2077
|
+
)
|
|
2057
2078
|
.join(', ')}\n`;
|
|
2058
2079
|
}
|
|
2059
2080
|
|
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
import { AIAgentCapability } from '@hashgraphonline/standards-sdk';
|
|
2
2
|
import { z } from 'zod';
|
|
3
3
|
import { BaseServiceBuilder } from 'hedera-agent-kit';
|
|
4
|
-
import {
|
|
4
|
+
import { CallbackManagerForToolRun } from '@langchain/core/callbacks/manager';
|
|
5
|
+
import {
|
|
6
|
+
HCS10Builder,
|
|
7
|
+
RegisterAgentParams,
|
|
8
|
+
} from '../../builders/hcs10/hcs10-builder';
|
|
5
9
|
import { BaseHCS10TransactionTool } from './base-hcs10-tools';
|
|
6
10
|
import { HCS10TransactionToolParams } from './hcs10-tool-params';
|
|
11
|
+
import { RegisteredAgent } from '../../state/state-types';
|
|
7
12
|
|
|
8
13
|
const RegisterAgentZodSchema = z.object({
|
|
9
14
|
name: z
|
|
@@ -19,7 +24,17 @@ const RegisterAgentZodSchema = z.object({
|
|
|
19
24
|
alias: z
|
|
20
25
|
.string()
|
|
21
26
|
.optional()
|
|
22
|
-
.
|
|
27
|
+
.transform((val) => {
|
|
28
|
+
if (!val || val.toLowerCase().includes('random')) {
|
|
29
|
+
const timestamp = Date.now().toString(36);
|
|
30
|
+
const randomChars = Math.random().toString(36);
|
|
31
|
+
return `bot${timestamp}${randomChars}`;
|
|
32
|
+
}
|
|
33
|
+
return val;
|
|
34
|
+
})
|
|
35
|
+
.describe(
|
|
36
|
+
'Optional custom username/alias for the agent. Use "random" to generate a unique alias'
|
|
37
|
+
),
|
|
23
38
|
type: z
|
|
24
39
|
.enum(['autonomous', 'manual'])
|
|
25
40
|
.optional()
|
|
@@ -124,8 +139,9 @@ export class RegisterAgentTool extends BaseHCS10TransactionTool<
|
|
|
124
139
|
> {
|
|
125
140
|
name = 'register_agent';
|
|
126
141
|
description =
|
|
127
|
-
'Creates and registers the AI agent on the Hedera network. Returns JSON string with agent details (accountId, privateKey, topics) on success. Note: This tool requires multiple transactions and cannot be used in returnBytes mode.';
|
|
142
|
+
'Creates and registers the AI agent on the Hedera network. Returns JSON string with agent details (accountId, privateKey, topics) on success. Note: This tool requires multiple transactions and cannot be used in returnBytes mode. If alias is set to "random" or contains "random", a unique alias will be generated.';
|
|
128
143
|
specificInputSchema = RegisterAgentZodSchema;
|
|
144
|
+
private specificArgs: z.infer<typeof RegisterAgentZodSchema> | undefined;
|
|
129
145
|
|
|
130
146
|
constructor(params: HCS10TransactionToolParams) {
|
|
131
147
|
super(params);
|
|
@@ -138,7 +154,7 @@ export class RegisterAgentTool extends BaseHCS10TransactionTool<
|
|
|
138
154
|
specificArgs: z.infer<typeof RegisterAgentZodSchema>
|
|
139
155
|
): Promise<void> {
|
|
140
156
|
const hcs10Builder = builder as HCS10Builder;
|
|
141
|
-
|
|
157
|
+
this.specificArgs = specificArgs;
|
|
142
158
|
const params: RegisterAgentParams = {
|
|
143
159
|
name: specificArgs.name,
|
|
144
160
|
};
|
|
@@ -148,6 +164,9 @@ export class RegisterAgentTool extends BaseHCS10TransactionTool<
|
|
|
148
164
|
}
|
|
149
165
|
if (specificArgs.alias !== undefined) {
|
|
150
166
|
params.alias = specificArgs.alias;
|
|
167
|
+
} else {
|
|
168
|
+
const randomSuffix = Date.now().toString(36);
|
|
169
|
+
params.alias = `${specificArgs.name}${randomSuffix}`;
|
|
151
170
|
}
|
|
152
171
|
if (specificArgs.type !== undefined) {
|
|
153
172
|
params.type = specificArgs.type;
|
|
@@ -210,4 +229,91 @@ export class RegisterAgentTool extends BaseHCS10TransactionTool<
|
|
|
210
229
|
|
|
211
230
|
await hcs10Builder.registerAgent(params);
|
|
212
231
|
}
|
|
213
|
-
|
|
232
|
+
|
|
233
|
+
/**
|
|
234
|
+
* Override _call to intercept the result and save agent to state if needed
|
|
235
|
+
*/
|
|
236
|
+
protected override async _call(
|
|
237
|
+
args: z.infer<ReturnType<this['schema']>>,
|
|
238
|
+
runManager?: CallbackManagerForToolRun
|
|
239
|
+
): Promise<string> {
|
|
240
|
+
const result = await super._call(args, runManager);
|
|
241
|
+
|
|
242
|
+
const shouldSetAsCurrent = this.specificArgs?.setAsCurrent !== false;
|
|
243
|
+
|
|
244
|
+
if (this.specificArgs && shouldSetAsCurrent) {
|
|
245
|
+
try {
|
|
246
|
+
const parsed = JSON.parse(result);
|
|
247
|
+
if (parsed.rawResult) {
|
|
248
|
+
this._handleRegistrationResult(parsed.rawResult);
|
|
249
|
+
} else if (parsed.state || parsed.accountId || parsed.metadata) {
|
|
250
|
+
this._handleRegistrationResult(parsed);
|
|
251
|
+
}
|
|
252
|
+
} catch (e) {}
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
return result;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
/**
|
|
259
|
+
* Extract agent data from registration result and save to state
|
|
260
|
+
*/
|
|
261
|
+
private _handleRegistrationResult(rawResult: any): void {
|
|
262
|
+
let accountId = rawResult.accountId || rawResult.metadata?.accountId;
|
|
263
|
+
|
|
264
|
+
if (!accountId && rawResult.state?.createdResources) {
|
|
265
|
+
const accountResource = rawResult.state.createdResources.find(
|
|
266
|
+
(r: string) => r.startsWith('account:')
|
|
267
|
+
);
|
|
268
|
+
if (accountResource) {
|
|
269
|
+
accountId = accountResource.split(':')[1];
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
const inboundTopicId =
|
|
274
|
+
rawResult.inboundTopicId ||
|
|
275
|
+
rawResult.metadata?.inboundTopicId ||
|
|
276
|
+
rawResult.state?.inboundTopicId;
|
|
277
|
+
|
|
278
|
+
const outboundTopicId =
|
|
279
|
+
rawResult.outboundTopicId ||
|
|
280
|
+
rawResult.metadata?.outboundTopicId ||
|
|
281
|
+
rawResult.state?.outboundTopicId;
|
|
282
|
+
|
|
283
|
+
const profileTopicId =
|
|
284
|
+
rawResult.profileTopicId ||
|
|
285
|
+
rawResult.metadata?.profileTopicId ||
|
|
286
|
+
rawResult.state?.profileTopicId;
|
|
287
|
+
|
|
288
|
+
const privateKey = rawResult.privateKey || rawResult.metadata?.privateKey;
|
|
289
|
+
|
|
290
|
+
if (accountId && inboundTopicId && outboundTopicId && this.specificArgs) {
|
|
291
|
+
const registeredAgent: RegisteredAgent = {
|
|
292
|
+
name: this.specificArgs.name,
|
|
293
|
+
accountId,
|
|
294
|
+
inboundTopicId,
|
|
295
|
+
outboundTopicId,
|
|
296
|
+
profileTopicId,
|
|
297
|
+
privateKey,
|
|
298
|
+
};
|
|
299
|
+
|
|
300
|
+
const hcs10Builder = this.getServiceBuilder() as HCS10Builder;
|
|
301
|
+
const stateManager = hcs10Builder.getStateManager();
|
|
302
|
+
if (stateManager) {
|
|
303
|
+
stateManager.setCurrentAgent(registeredAgent);
|
|
304
|
+
|
|
305
|
+
if (stateManager.persistAgentData) {
|
|
306
|
+
const prefix =
|
|
307
|
+
this.specificArgs.persistence?.prefix ||
|
|
308
|
+
this.specificArgs.name.toUpperCase().replace(/[^A-Z0-9]/g, '_');
|
|
309
|
+
stateManager
|
|
310
|
+
.persistAgentData(registeredAgent, {
|
|
311
|
+
type: 'env-file',
|
|
312
|
+
prefix: prefix,
|
|
313
|
+
})
|
|
314
|
+
.catch(() => {});
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
}
|