@hashgraphonline/conversational-agent 0.1.209 → 0.1.211
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/bin/conversational-agent-cli.js +30 -0
- package/cli/readme.md +181 -0
- package/dist/cjs/base-agent.d.ts +3 -1
- package/dist/cjs/conversational-agent.d.ts +14 -22
- package/dist/cjs/index.cjs +1 -1
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.ts +5 -3
- package/dist/cjs/langchain-agent.d.ts +6 -3
- package/dist/cjs/memory/SmartMemoryManager.d.ts +7 -1
- package/dist/cjs/memory/TokenCounter.d.ts +1 -1
- package/dist/cjs/plugins/hbar/AirdropToolWrapper.d.ts +43 -0
- package/dist/{types/plugins/hbar-transfer/HbarTransferPlugin.d.ts → cjs/plugins/hbar/HbarPlugin.d.ts} +2 -1
- package/dist/{types/plugins/hbar-transfer → cjs/plugins/hbar}/TransferHbarTool.d.ts +1 -1
- package/dist/cjs/plugins/hbar/index.d.ts +3 -0
- package/dist/cjs/plugins/index.d.ts +2 -1
- package/dist/cjs/services/EntityResolver.d.ts +26 -0
- package/dist/cjs/tools/EntityResolverTool.d.ts +104 -0
- package/dist/cjs/types/inscription.d.ts +37 -0
- package/dist/esm/index.js +8 -2
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/index12.js +1 -4
- package/dist/esm/index12.js.map +1 -1
- package/dist/esm/index13.js +0 -1
- package/dist/esm/index13.js.map +1 -1
- package/dist/esm/index14.js +2 -7
- package/dist/esm/index14.js.map +1 -1
- package/dist/esm/index15.js +31 -69
- package/dist/esm/index15.js.map +1 -1
- package/dist/esm/index16.js +126 -39
- package/dist/esm/index16.js.map +1 -1
- package/dist/esm/index17.js +148 -13
- package/dist/esm/index17.js.map +1 -1
- package/dist/esm/index18.js +44 -146
- package/dist/esm/index18.js.map +1 -1
- package/dist/esm/index19.js +100 -6
- package/dist/esm/index19.js.map +1 -1
- package/dist/esm/index20.js +20 -174
- package/dist/esm/index20.js.map +1 -1
- package/dist/esm/index21.js +7 -151
- package/dist/esm/index21.js.map +1 -1
- package/dist/esm/index22.js +154 -45
- package/dist/esm/index22.js.map +1 -1
- package/dist/esm/index23.js +149 -24
- package/dist/esm/index23.js.map +1 -1
- package/dist/esm/index24.js +56 -83
- package/dist/esm/index24.js.map +1 -1
- package/dist/esm/index25.js +24 -236
- package/dist/esm/index25.js.map +1 -1
- package/dist/esm/index26.js +95 -0
- package/dist/esm/index26.js.map +1 -0
- package/dist/esm/index27.js +242 -0
- package/dist/esm/index27.js.map +1 -0
- package/dist/esm/index5.js +32 -19
- package/dist/esm/index5.js.map +1 -1
- package/dist/esm/index6.js +156 -195
- package/dist/esm/index6.js.map +1 -1
- package/dist/esm/index7.js +2 -2
- package/dist/esm/index7.js.map +1 -1
- package/dist/esm/index8.js +80 -48
- package/dist/esm/index8.js.map +1 -1
- package/dist/types/base-agent.d.ts +3 -1
- package/dist/types/conversational-agent.d.ts +14 -22
- package/dist/types/index.d.ts +5 -3
- package/dist/types/langchain-agent.d.ts +6 -3
- package/dist/types/memory/SmartMemoryManager.d.ts +7 -1
- package/dist/types/memory/TokenCounter.d.ts +1 -1
- package/dist/types/plugins/hbar/AirdropToolWrapper.d.ts +43 -0
- package/dist/{cjs/plugins/hbar-transfer/HbarTransferPlugin.d.ts → types/plugins/hbar/HbarPlugin.d.ts} +2 -1
- package/dist/{cjs/plugins/hbar-transfer → types/plugins/hbar}/TransferHbarTool.d.ts +1 -1
- package/dist/types/plugins/hbar/index.d.ts +3 -0
- package/dist/types/plugins/index.d.ts +2 -1
- package/dist/types/services/EntityResolver.d.ts +26 -0
- package/dist/types/tools/EntityResolverTool.d.ts +104 -0
- package/dist/types/types/inscription.d.ts +37 -0
- package/package.json +13 -4
- package/src/base-agent.ts +14 -9
- package/src/config/system-message.ts +11 -2
- package/src/context/ReferenceContextManager.ts +1 -1
- package/src/conversational-agent.ts +221 -254
- package/src/index.ts +17 -3
- package/src/langchain-agent.ts +130 -78
- package/src/mcp/ContentProcessor.ts +0 -2
- package/src/mcp/adapters/langchain.ts +0 -1
- package/src/memory/ContentStorage.ts +0 -5
- package/src/memory/MemoryWindow.ts +0 -1
- package/src/memory/ReferenceIdGenerator.ts +4 -4
- package/src/memory/SmartMemoryManager.ts +53 -92
- package/src/memory/TokenCounter.ts +4 -7
- package/src/plugins/hbar/AirdropToolWrapper.ts +157 -0
- package/src/plugins/hbar/HbarPlugin.ts +86 -0
- package/src/plugins/{hbar-transfer → hbar}/TransferHbarTool.ts +3 -3
- package/src/plugins/hbar/index.ts +3 -0
- package/src/plugins/index.ts +2 -1
- package/src/services/EntityResolver.ts +135 -0
- package/src/tools/EntityResolverTool.ts +170 -0
- package/src/types/inscription.ts +40 -0
- package/dist/cjs/plugins/hbar-transfer/index.d.ts +0 -1
- package/dist/types/plugins/hbar-transfer/index.d.ts +0 -1
- package/src/plugins/hbar-transfer/HbarTransferPlugin.ts +0 -66
- package/src/plugins/hbar-transfer/index.ts +0 -1
- /package/dist/cjs/plugins/{hbar-transfer → hbar}/AccountBuilder.d.ts +0 -0
- /package/dist/cjs/plugins/{hbar-transfer → hbar}/types.d.ts +0 -0
- /package/dist/types/plugins/{hbar-transfer → hbar}/AccountBuilder.d.ts +0 -0
- /package/dist/types/plugins/{hbar-transfer → hbar}/types.d.ts +0 -0
- /package/src/plugins/{hbar-transfer → hbar}/AccountBuilder.ts +0 -0
- /package/src/plugins/{hbar-transfer → hbar}/types.ts +0 -0
|
@@ -5,10 +5,11 @@ import { ChatResponse } from './base-agent';
|
|
|
5
5
|
import { HCS10Plugin } from './plugins/hcs-10/HCS10Plugin';
|
|
6
6
|
import { HCS2Plugin } from './plugins/hcs-2/HCS2Plugin';
|
|
7
7
|
import { InscribePlugin } from './plugins/inscribe/InscribePlugin';
|
|
8
|
-
import {
|
|
8
|
+
import { HbarPlugin } from './plugins/hbar/HbarPlugin';
|
|
9
9
|
import { IStateManager } from '@hashgraphonline/standards-agent-kit';
|
|
10
10
|
import { MCPServerConfig, MCPConnectionStatus } from './mcp/types';
|
|
11
|
-
import {
|
|
11
|
+
import { ContentStoreManager } from './services/ContentStoreManager';
|
|
12
|
+
import { SmartMemoryManager, SmartMemoryConfig } from './memory';
|
|
12
13
|
|
|
13
14
|
export type ToolDescriptor = {
|
|
14
15
|
name: string;
|
|
@@ -26,6 +27,7 @@ export interface ConversationalAgentOptions {
|
|
|
26
27
|
network?: NetworkType;
|
|
27
28
|
openAIApiKey: string;
|
|
28
29
|
openAIModelName?: string;
|
|
30
|
+
llmProvider?: 'openai' | 'anthropic';
|
|
29
31
|
verbose?: boolean;
|
|
30
32
|
operationalMode?: AgentOperationalMode;
|
|
31
33
|
userAccountId?: string;
|
|
@@ -61,16 +63,16 @@ export declare class ConversationalAgent {
|
|
|
61
63
|
hcs10Plugin: HCS10Plugin;
|
|
62
64
|
hcs2Plugin: HCS2Plugin;
|
|
63
65
|
inscribePlugin: InscribePlugin;
|
|
64
|
-
|
|
66
|
+
hbarPlugin: HbarPlugin;
|
|
65
67
|
stateManager: IStateManager;
|
|
66
68
|
private options;
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
private
|
|
69
|
+
logger: Logger;
|
|
70
|
+
contentStoreManager?: ContentStoreManager;
|
|
71
|
+
memoryManager?: SmartMemoryManager | undefined;
|
|
72
|
+
private entityTools?;
|
|
71
73
|
constructor(options: ConversationalAgentOptions);
|
|
72
74
|
/**
|
|
73
|
-
* Initialize the conversational agent with Hedera
|
|
75
|
+
* Initialize the conversational agent with Hedera Hashgraph connection and AI configuration
|
|
74
76
|
* @throws {Error} If account ID or private key is missing
|
|
75
77
|
* @throws {Error} If initialization fails
|
|
76
78
|
*/
|
|
@@ -186,18 +188,18 @@ export declare class ConversationalAgent {
|
|
|
186
188
|
* Detect the private key type by querying the account info from mirror node
|
|
187
189
|
* @param {string} accountId - The Hedera account ID
|
|
188
190
|
* @param {string} privateKey - The private key string
|
|
189
|
-
* @param {NetworkType} network - The Hedera
|
|
191
|
+
* @param {NetworkType} network - The Hedera Hashgraph
|
|
190
192
|
* @returns {Promise<PrivateKey>} The appropriate PrivateKey instance
|
|
191
193
|
*/
|
|
192
194
|
private detectPrivateKeyType;
|
|
193
195
|
/**
|
|
194
|
-
* Resolve entity references
|
|
196
|
+
* Resolve entity references using LLM-based resolver
|
|
195
197
|
* @param content - Message content to resolve
|
|
196
198
|
* @returns Resolved message content with entity IDs replaced
|
|
197
199
|
*/
|
|
198
200
|
private resolveEntitiesInMessage;
|
|
199
201
|
/**
|
|
200
|
-
* Extract and store
|
|
202
|
+
* Extract and store entities from agent responses
|
|
201
203
|
* @param response - Agent response containing potential entity information
|
|
202
204
|
* @param originalMessage - Original user message for context
|
|
203
205
|
*/
|
|
@@ -213,17 +215,6 @@ export declare class ConversationalAgent {
|
|
|
213
215
|
* @private
|
|
214
216
|
*/
|
|
215
217
|
private connectMCP;
|
|
216
|
-
/**
|
|
217
|
-
* Start MCP connections without blocking initialization
|
|
218
|
-
* @private
|
|
219
|
-
*/
|
|
220
|
-
private startConnections;
|
|
221
|
-
/**
|
|
222
|
-
* Connect to a single MCP server
|
|
223
|
-
* @param {MCPServerConfig} server - Server configuration
|
|
224
|
-
* @private
|
|
225
|
-
*/
|
|
226
|
-
private connectServer;
|
|
227
218
|
/**
|
|
228
219
|
* Get MCP connection status for all servers
|
|
229
220
|
* @returns {Map<string, MCPConnectionStatus>} Connection status map
|
|
@@ -239,4 +230,5 @@ export declare class ConversationalAgent {
|
|
|
239
230
|
* Clean up resources
|
|
240
231
|
*/
|
|
241
232
|
cleanup(): Promise<void>;
|
|
233
|
+
private extractResponseText;
|
|
242
234
|
}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { HCS10Plugin } from './plugins/hcs-10/HCS10Plugin';
|
|
2
2
|
export { HCS2Plugin } from './plugins/hcs-2/HCS2Plugin';
|
|
3
3
|
export { InscribePlugin } from './plugins/inscribe/InscribePlugin';
|
|
4
|
-
export {
|
|
4
|
+
export { HbarPlugin } from './plugins/hbar/HbarPlugin';
|
|
5
5
|
export { HCS10Plugin as OpenConvAIPlugin } from './plugins/hcs-10/HCS10Plugin';
|
|
6
6
|
export { ConversationalAgent } from './conversational-agent';
|
|
7
7
|
export type { ConversationalAgentOptions } from './conversational-agent';
|
|
@@ -11,6 +11,8 @@ export { createAgent } from './agent-factory';
|
|
|
11
11
|
export { LangChainProvider, type AIProvider, type VercelAIProvider, type BAMLProvider, } from './providers';
|
|
12
12
|
export * from 'hedera-agent-kit';
|
|
13
13
|
export type { IStateManager } from '@hashgraphonline/standards-agent-kit';
|
|
14
|
-
export type { MCPServerConfig, MCPConnectionStatus, MCPToolInfo } from './mcp/types';
|
|
15
|
-
export { MCPServers, createMCPConfig, validateServerConfig } from './mcp/helpers';
|
|
14
|
+
export type { MCPServerConfig, MCPConnectionStatus, MCPToolInfo, } from './mcp/types';
|
|
15
|
+
export { MCPServers, createMCPConfig, validateServerConfig, } from './mcp/helpers';
|
|
16
16
|
export * from './memory';
|
|
17
|
+
export { createEntityTools, ResolveEntitiesTool, ExtractEntitiesTool, } from './tools/EntityResolverTool';
|
|
18
|
+
export { ContentStoreManager } from './services/ContentStoreManager';
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { BaseAgent, ConversationContext, ChatResponse, OperationalMode, UsageStats } from './base-agent';
|
|
2
|
+
import { MCPConnectionStatus } from './mcp/types';
|
|
2
3
|
|
|
3
4
|
export declare class LangChainAgent extends BaseAgent {
|
|
4
5
|
private executor;
|
|
5
6
|
private systemMessage;
|
|
6
7
|
private mcpManager?;
|
|
7
8
|
private smartMemory;
|
|
9
|
+
private mcpConnectionStatus;
|
|
8
10
|
boot(): Promise<void>;
|
|
9
11
|
chat(message: string, context?: ConversationContext): Promise<ChatResponse>;
|
|
10
12
|
shutdown(): Promise<void>;
|
|
@@ -12,18 +14,19 @@ export declare class LangChainAgent extends BaseAgent {
|
|
|
12
14
|
getUsageStats(): UsageStats;
|
|
13
15
|
getUsageLog(): UsageStats[];
|
|
14
16
|
clearUsageStats(): void;
|
|
17
|
+
getMCPConnectionStatus(): Map<string, MCPConnectionStatus>;
|
|
15
18
|
private createAgentKit;
|
|
16
19
|
private createExecutor;
|
|
17
20
|
private handleError;
|
|
18
21
|
private initializeMCP;
|
|
19
22
|
/**
|
|
20
|
-
* Connect to MCP servers asynchronously after agent boot
|
|
23
|
+
* Connect to MCP servers asynchronously after agent boot with background timeout pattern
|
|
21
24
|
*/
|
|
22
25
|
connectMCPServers(): Promise<void>;
|
|
23
26
|
/**
|
|
24
|
-
* Connect to a single MCP server
|
|
27
|
+
* Connect to a single MCP server in background with timeout
|
|
25
28
|
*/
|
|
26
|
-
private
|
|
29
|
+
private connectServerInBackground;
|
|
27
30
|
/**
|
|
28
31
|
* Check if a string is valid JSON
|
|
29
32
|
*/
|
|
@@ -69,16 +69,22 @@ export interface MemoryStats {
|
|
|
69
69
|
usagePercentage: number;
|
|
70
70
|
}
|
|
71
71
|
/**
|
|
72
|
+
* TODO: investigate using chroma / rag for long term memory
|
|
72
73
|
* Smart memory manager that combines active memory window with long-term storage
|
|
73
74
|
* Provides context-aware memory management with automatic pruning and searchable history
|
|
74
75
|
*/
|
|
75
76
|
export declare class SmartMemoryManager {
|
|
76
77
|
private memoryWindow;
|
|
77
|
-
private
|
|
78
|
+
private _contentStorage;
|
|
78
79
|
private tokenCounter;
|
|
79
80
|
private config;
|
|
80
81
|
private static readonly DEFAULT_CONFIG;
|
|
81
82
|
constructor(config?: SmartMemoryConfig);
|
|
83
|
+
/**
|
|
84
|
+
* Get the content storage instance for file/content reference operations
|
|
85
|
+
* @returns ContentStorage instance
|
|
86
|
+
*/
|
|
87
|
+
get contentStorage(): ContentStorage;
|
|
82
88
|
/**
|
|
83
89
|
* Add a message to the active memory window
|
|
84
90
|
* Automatically handles pruning and storage of displaced messages
|
|
@@ -10,7 +10,7 @@ export declare class TokenCounter {
|
|
|
10
10
|
private modelName;
|
|
11
11
|
private static readonly MESSAGE_OVERHEAD;
|
|
12
12
|
private static readonly ROLE_OVERHEAD;
|
|
13
|
-
constructor(modelName?: TiktokenModel);
|
|
13
|
+
constructor(modelName?: string | TiktokenModel);
|
|
14
14
|
/**
|
|
15
15
|
* Count tokens in raw text content
|
|
16
16
|
* @param text - The text to count tokens for
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { StructuredTool } from '@langchain/core/tools';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
|
|
4
|
+
export declare class AirdropToolWrapper extends StructuredTool {
|
|
5
|
+
name: string;
|
|
6
|
+
description: string;
|
|
7
|
+
schema: z.ZodObject<{
|
|
8
|
+
tokenId: z.ZodString;
|
|
9
|
+
recipients: z.ZodArray<z.ZodObject<{
|
|
10
|
+
accountId: z.ZodString;
|
|
11
|
+
amount: z.ZodUnion<[z.ZodNumber, z.ZodString]>;
|
|
12
|
+
}, "strip", z.ZodTypeAny, {
|
|
13
|
+
accountId: string;
|
|
14
|
+
amount: string | number;
|
|
15
|
+
}, {
|
|
16
|
+
accountId: string;
|
|
17
|
+
amount: string | number;
|
|
18
|
+
}>, "many">;
|
|
19
|
+
memo: z.ZodOptional<z.ZodString>;
|
|
20
|
+
}, "strip", z.ZodTypeAny, {
|
|
21
|
+
tokenId: string;
|
|
22
|
+
recipients: {
|
|
23
|
+
accountId: string;
|
|
24
|
+
amount: string | number;
|
|
25
|
+
}[];
|
|
26
|
+
memo?: string | undefined;
|
|
27
|
+
}, {
|
|
28
|
+
tokenId: string;
|
|
29
|
+
recipients: {
|
|
30
|
+
accountId: string;
|
|
31
|
+
amount: string | number;
|
|
32
|
+
}[];
|
|
33
|
+
memo?: string | undefined;
|
|
34
|
+
}>;
|
|
35
|
+
private originalTool;
|
|
36
|
+
private agentKit;
|
|
37
|
+
private logger;
|
|
38
|
+
constructor(originalTool: StructuredTool, agentKit: unknown);
|
|
39
|
+
_call(input: z.infer<typeof this.schema>): Promise<string>;
|
|
40
|
+
private convertToSmallestUnits;
|
|
41
|
+
private getTokenInfo;
|
|
42
|
+
private queryTokenInfo;
|
|
43
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { GenericPluginContext, HederaTool, BasePlugin } from 'hedera-agent-kit';
|
|
2
2
|
|
|
3
|
-
export declare class
|
|
3
|
+
export declare class HbarPlugin extends BasePlugin {
|
|
4
4
|
id: string;
|
|
5
5
|
name: string;
|
|
6
6
|
description: string;
|
|
@@ -8,6 +8,7 @@ export declare class HbarTransferPlugin extends BasePlugin {
|
|
|
8
8
|
author: string;
|
|
9
9
|
namespace: string;
|
|
10
10
|
private tools;
|
|
11
|
+
private originalAirdropTool;
|
|
11
12
|
initialize(context: GenericPluginContext): Promise<void>;
|
|
12
13
|
private initializeTools;
|
|
13
14
|
getTools(): HederaTool[];
|
|
@@ -29,7 +29,7 @@ declare const TransferHbarZodSchemaCore: z.ZodObject<{
|
|
|
29
29
|
/**
|
|
30
30
|
* A Hedera transaction tool for transferring HBAR between accounts.
|
|
31
31
|
* Supports single and multi-party transfers with automatic balance validation.
|
|
32
|
-
* Extends BaseHederaTransactionTool to handle HBAR transfer transactions on the Hedera
|
|
32
|
+
* Extends BaseHederaTransactionTool to handle HBAR transfer transactions on the Hedera Hashgraph.
|
|
33
33
|
*/
|
|
34
34
|
export declare class TransferHbarTool extends BaseHederaTransactionTool<typeof TransferHbarZodSchemaCore> {
|
|
35
35
|
name: string;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { EntityAssociation } from '../memory/SmartMemoryManager';
|
|
2
|
+
|
|
3
|
+
export interface EntityResolverConfig {
|
|
4
|
+
apiKey: string;
|
|
5
|
+
modelName?: string;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* LLM-based entity resolver that replaces brittle regex patterns
|
|
9
|
+
*/
|
|
10
|
+
export declare class EntityResolver {
|
|
11
|
+
private llm;
|
|
12
|
+
constructor(config: EntityResolverConfig);
|
|
13
|
+
/**
|
|
14
|
+
* Resolve entity references using LLM instead of regex
|
|
15
|
+
*/
|
|
16
|
+
resolveReferences(message: string, entities: EntityAssociation[]): Promise<string>;
|
|
17
|
+
/**
|
|
18
|
+
* Extract entities from agent response using LLM
|
|
19
|
+
*/
|
|
20
|
+
extractEntities(response: unknown, userMessage: string): Promise<Array<{
|
|
21
|
+
id: string;
|
|
22
|
+
name: string;
|
|
23
|
+
type: string;
|
|
24
|
+
transactionId?: string;
|
|
25
|
+
}>>;
|
|
26
|
+
}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { StructuredTool } from '@langchain/core/tools';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
|
|
4
|
+
declare const ResolveEntitiesSchema: z.ZodObject<{
|
|
5
|
+
message: z.ZodString;
|
|
6
|
+
entities: z.ZodArray<z.ZodObject<{
|
|
7
|
+
entityId: z.ZodString;
|
|
8
|
+
entityName: z.ZodString;
|
|
9
|
+
entityType: z.ZodString;
|
|
10
|
+
}, "strip", z.ZodTypeAny, {
|
|
11
|
+
entityId: string;
|
|
12
|
+
entityName: string;
|
|
13
|
+
entityType: string;
|
|
14
|
+
}, {
|
|
15
|
+
entityId: string;
|
|
16
|
+
entityName: string;
|
|
17
|
+
entityType: string;
|
|
18
|
+
}>, "many">;
|
|
19
|
+
}, "strip", z.ZodTypeAny, {
|
|
20
|
+
message: string;
|
|
21
|
+
entities: {
|
|
22
|
+
entityId: string;
|
|
23
|
+
entityName: string;
|
|
24
|
+
entityType: string;
|
|
25
|
+
}[];
|
|
26
|
+
}, {
|
|
27
|
+
message: string;
|
|
28
|
+
entities: {
|
|
29
|
+
entityId: string;
|
|
30
|
+
entityName: string;
|
|
31
|
+
entityType: string;
|
|
32
|
+
}[];
|
|
33
|
+
}>;
|
|
34
|
+
declare const ExtractEntitiesSchema: z.ZodObject<{
|
|
35
|
+
response: z.ZodString;
|
|
36
|
+
userMessage: z.ZodString;
|
|
37
|
+
}, "strip", z.ZodTypeAny, {
|
|
38
|
+
response: string;
|
|
39
|
+
userMessage: string;
|
|
40
|
+
}, {
|
|
41
|
+
response: string;
|
|
42
|
+
userMessage: string;
|
|
43
|
+
}>;
|
|
44
|
+
export declare class ResolveEntitiesTool extends StructuredTool {
|
|
45
|
+
name: string;
|
|
46
|
+
description: string;
|
|
47
|
+
schema: z.ZodObject<{
|
|
48
|
+
message: z.ZodString;
|
|
49
|
+
entities: z.ZodArray<z.ZodObject<{
|
|
50
|
+
entityId: z.ZodString;
|
|
51
|
+
entityName: z.ZodString;
|
|
52
|
+
entityType: z.ZodString;
|
|
53
|
+
}, "strip", z.ZodTypeAny, {
|
|
54
|
+
entityId: string;
|
|
55
|
+
entityName: string;
|
|
56
|
+
entityType: string;
|
|
57
|
+
}, {
|
|
58
|
+
entityId: string;
|
|
59
|
+
entityName: string;
|
|
60
|
+
entityType: string;
|
|
61
|
+
}>, "many">;
|
|
62
|
+
}, "strip", z.ZodTypeAny, {
|
|
63
|
+
message: string;
|
|
64
|
+
entities: {
|
|
65
|
+
entityId: string;
|
|
66
|
+
entityName: string;
|
|
67
|
+
entityType: string;
|
|
68
|
+
}[];
|
|
69
|
+
}, {
|
|
70
|
+
message: string;
|
|
71
|
+
entities: {
|
|
72
|
+
entityId: string;
|
|
73
|
+
entityName: string;
|
|
74
|
+
entityType: string;
|
|
75
|
+
}[];
|
|
76
|
+
}>;
|
|
77
|
+
private llm;
|
|
78
|
+
constructor(apiKey: string, modelName?: string);
|
|
79
|
+
_call(input: z.infer<typeof ResolveEntitiesSchema>): Promise<string>;
|
|
80
|
+
private groupEntitiesByType;
|
|
81
|
+
private buildEntityContext;
|
|
82
|
+
}
|
|
83
|
+
export declare class ExtractEntitiesTool extends StructuredTool {
|
|
84
|
+
name: string;
|
|
85
|
+
description: string;
|
|
86
|
+
schema: z.ZodObject<{
|
|
87
|
+
response: z.ZodString;
|
|
88
|
+
userMessage: z.ZodString;
|
|
89
|
+
}, "strip", z.ZodTypeAny, {
|
|
90
|
+
response: string;
|
|
91
|
+
userMessage: string;
|
|
92
|
+
}, {
|
|
93
|
+
response: string;
|
|
94
|
+
userMessage: string;
|
|
95
|
+
}>;
|
|
96
|
+
private llm;
|
|
97
|
+
constructor(apiKey: string, modelName?: string);
|
|
98
|
+
_call(input: z.infer<typeof ExtractEntitiesSchema>): Promise<string>;
|
|
99
|
+
}
|
|
100
|
+
export declare function createEntityTools(apiKey: string, modelName?: string): {
|
|
101
|
+
resolveEntities: ResolveEntitiesTool;
|
|
102
|
+
extractEntities: ExtractEntitiesTool;
|
|
103
|
+
};
|
|
104
|
+
export {};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Inscription quote response from standards-agent-kit
|
|
3
|
+
*/
|
|
4
|
+
export interface InscriptionQuote {
|
|
5
|
+
totalCostHbar: string;
|
|
6
|
+
validUntil: string;
|
|
7
|
+
breakdown: {
|
|
8
|
+
transfers: Array<{
|
|
9
|
+
type: string;
|
|
10
|
+
amount: string;
|
|
11
|
+
description: string;
|
|
12
|
+
}>;
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Parameters for inscription tool calls with quote support
|
|
17
|
+
*/
|
|
18
|
+
export interface InscriptionToolParams {
|
|
19
|
+
[key: string]: unknown;
|
|
20
|
+
quoteOnly?: boolean;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Result from inscription tool execution
|
|
24
|
+
*/
|
|
25
|
+
export interface InscriptionResult {
|
|
26
|
+
success: boolean;
|
|
27
|
+
transactionId?: string;
|
|
28
|
+
message: string;
|
|
29
|
+
quote?: InscriptionQuote;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* User confirmation status for inscription
|
|
33
|
+
*/
|
|
34
|
+
export interface InscriptionConfirmation {
|
|
35
|
+
confirmed: boolean;
|
|
36
|
+
reason?: string;
|
|
37
|
+
}
|
package/package.json
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hashgraphonline/conversational-agent",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.211",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/cjs/index.cjs",
|
|
6
6
|
"module": "./dist/esm/index.js",
|
|
7
7
|
"types": "./dist/types/index.d.ts",
|
|
8
|
+
"bin": {
|
|
9
|
+
"conversational-agent": "./bin/conversational-agent-cli.js"
|
|
10
|
+
},
|
|
8
11
|
"exports": {
|
|
9
12
|
".": {
|
|
10
13
|
"types": "./dist/types/index.d.ts",
|
|
@@ -18,6 +21,8 @@
|
|
|
18
21
|
"./package.json": "./package.json"
|
|
19
22
|
},
|
|
20
23
|
"files": [
|
|
24
|
+
"bin",
|
|
25
|
+
"cli/dist",
|
|
21
26
|
"dist",
|
|
22
27
|
"src",
|
|
23
28
|
"LICENSE",
|
|
@@ -31,6 +36,7 @@
|
|
|
31
36
|
"build:cjs": "BUILD_FORMAT=cjs vite build",
|
|
32
37
|
"build:umd": "BUILD_FORMAT=umd vite build",
|
|
33
38
|
"build": "pnpm run clean && pnpm run build:es && pnpm run build:cjs",
|
|
39
|
+
"build:all": "pnpm run build && pnpm run cli:build",
|
|
34
40
|
"prepublishOnly": "pnpm run build",
|
|
35
41
|
"release": "pnpm publish --access public",
|
|
36
42
|
"release:canary": "pnpm run prepublishOnly && pnpm publish --tag canary --access public",
|
|
@@ -39,7 +45,7 @@
|
|
|
39
45
|
"lint": "eslint .",
|
|
40
46
|
"lint:fix": "eslint . --fix",
|
|
41
47
|
"typecheck": "tsc --noEmit",
|
|
42
|
-
"cli:build": "
|
|
48
|
+
"cli:build": "cd cli && pnpm install && pnpm build",
|
|
43
49
|
"cli": "tsx cli/scripts/run-cli.ts",
|
|
44
50
|
"cli:dev": "cd cli && pnpm dev",
|
|
45
51
|
"example:mcp-filesystem": "tsx examples/mcp-filesystem-demo.ts",
|
|
@@ -86,13 +92,16 @@
|
|
|
86
92
|
},
|
|
87
93
|
"dependencies": {
|
|
88
94
|
"@hashgraph/sdk": "^2.69.0",
|
|
89
|
-
"@hashgraphonline/standards-agent-kit": "0.2.
|
|
90
|
-
"@
|
|
95
|
+
"@hashgraphonline/standards-agent-kit": "0.2.125",
|
|
96
|
+
"@langchain/anthropic": "^0.3.26",
|
|
97
|
+
"@hashgraphonline/standards-sdk": "^0.0.180",
|
|
91
98
|
"@langchain/core": "^0.3.66",
|
|
92
99
|
"@langchain/openai": "^0.6.3",
|
|
93
100
|
"@modelcontextprotocol/sdk": "^1.17.0",
|
|
101
|
+
"axios": "^1.11.0",
|
|
94
102
|
"bignumber.js": "^9.3.1",
|
|
95
103
|
"electron-log": "^5.4.2",
|
|
104
|
+
"ethers": "^6.15.0",
|
|
96
105
|
"hedera-agent-kit": "^2.0.3",
|
|
97
106
|
"langchain": "^0.3.3",
|
|
98
107
|
"tiktoken": "^1.0.21",
|
package/src/base-agent.ts
CHANGED
|
@@ -11,7 +11,7 @@ import {
|
|
|
11
11
|
import type { CostCalculation } from 'hedera-agent-kit';
|
|
12
12
|
import type { AIProvider, VercelAIProvider, BAMLProvider } from './providers';
|
|
13
13
|
import { Logger } from '@hashgraphonline/standards-sdk';
|
|
14
|
-
import type { MCPServerConfig } from './mcp/types';
|
|
14
|
+
import type { MCPServerConfig, MCPConnectionStatus } from './mcp/types';
|
|
15
15
|
|
|
16
16
|
export interface ToolFilterConfig {
|
|
17
17
|
namespaceWhitelist?: string[];
|
|
@@ -115,16 +115,17 @@ export abstract class BaseAgent {
|
|
|
115
115
|
abstract getUsageStats(): UsageStats;
|
|
116
116
|
abstract getUsageLog(): UsageStats[];
|
|
117
117
|
abstract clearUsageStats(): void;
|
|
118
|
+
abstract connectMCPServers(): Promise<void>;
|
|
119
|
+
abstract getMCPConnectionStatus(): Map<string, MCPConnectionStatus>;
|
|
118
120
|
|
|
119
|
-
getCore(): HederaAgentKit | undefined {
|
|
121
|
+
public getCore(): HederaAgentKit | undefined {
|
|
120
122
|
return this.agentKit;
|
|
121
123
|
}
|
|
122
124
|
|
|
123
|
-
protected filterTools(
|
|
124
|
-
tools: StructuredTool[]
|
|
125
|
-
): StructuredTool[] {
|
|
125
|
+
protected filterTools(tools: StructuredTool[]): StructuredTool[] {
|
|
126
126
|
let filtered = [...tools];
|
|
127
127
|
const filter = this.config.filtering;
|
|
128
|
+
|
|
128
129
|
if (!filter) return filtered;
|
|
129
130
|
|
|
130
131
|
if (filter.namespaceWhitelist?.length) {
|
|
@@ -160,7 +161,7 @@ export abstract class BaseAgent {
|
|
|
160
161
|
|
|
161
162
|
parts.push(
|
|
162
163
|
`You are a helpful Hedera assistant. Your primary operator account is ${operatorId}. ` +
|
|
163
|
-
`You have tools to interact with the Hedera
|
|
164
|
+
`You have tools to interact with the Hedera Hashgraph. ` +
|
|
164
165
|
`When using any tool, provide all necessary parameters as defined by that tool's schema and description.`
|
|
165
166
|
);
|
|
166
167
|
|
|
@@ -198,11 +199,15 @@ export abstract class BaseAgent {
|
|
|
198
199
|
);
|
|
199
200
|
} else {
|
|
200
201
|
parts.push(
|
|
201
|
-
`\nOPERATIONAL MODE: 'returnBytes'. Your goal is to provide transaction bytes
|
|
202
|
+
`\nOPERATIONAL MODE: 'returnBytes'. Your goal is to provide transaction bytes when possible. ` +
|
|
202
203
|
`When a user asks for a transaction to be prepared (e.g., for them to sign, or for scheduling without the default scheduling flow), ` +
|
|
203
|
-
`you MUST call the appropriate tool.
|
|
204
|
+
`you MUST call the appropriate tool. ` +
|
|
205
|
+
`IMPORTANT: Only use metaOption 'returnBytes: true' for tools that explicitly support it (like HBAR transfers, token operations). ` +
|
|
206
|
+
`Many tools (inscriptions, HCS-2, HCS-20, etc.) do NOT support returnBytes and will execute directly - this is expected behavior. ` +
|
|
207
|
+
`For tools without returnBytes support, simply call them with their standard parameters. ` +
|
|
208
|
+
`If you need raw bytes for the user to sign for their own account ${
|
|
204
209
|
userAccId || 'if specified'
|
|
205
|
-
}, ensure the tool constructs the transaction body accordingly
|
|
210
|
+
}, ensure the tool constructs the transaction body accordingly when returnBytes IS supported.`
|
|
206
211
|
);
|
|
207
212
|
}
|
|
208
213
|
}
|
|
@@ -1,12 +1,21 @@
|
|
|
1
|
-
export const getSystemMessage = (
|
|
1
|
+
export const getSystemMessage = (
|
|
2
|
+
accountId: string
|
|
3
|
+
): string => `You are a helpful assistant managing Hashgraph Online HCS-10 connections, messages, HCS-2 registries, content inscription, and Hedera Hashgraph operations.
|
|
2
4
|
|
|
3
5
|
You have access to tools for:
|
|
4
6
|
- HCS-10: registering agents, finding registered agents, initiating connections, listing active connections, sending messages over connections, and checking for new messages
|
|
5
7
|
- HCS-2: creating registries, registering entries, updating entries, deleting entries, migrating registries, and querying registry contents
|
|
6
8
|
- Inscription: inscribing content from URLs, files, or buffers, creating Hashinal NFTs, and retrieving inscriptions
|
|
9
|
+
- Hedera Token Service (HTS): creating tokens, transferring tokens, airdropping tokens, and managing token operations
|
|
7
10
|
|
|
8
11
|
*** IMPORTANT CONTEXT ***
|
|
9
12
|
You are currently operating as agent: ${accountId} on the Hashgraph Online network
|
|
10
13
|
When users ask about "my profile", "my account", "my connections", etc., use this account ID: ${accountId}
|
|
11
14
|
|
|
12
|
-
|
|
15
|
+
*** CRITICAL ENTITY HANDLING RULES ***
|
|
16
|
+
- When users refer to entities (tokens, topics, accounts) with pronouns like "it", "that", "the token/topic", etc., ALWAYS use the most recently created entity of that type
|
|
17
|
+
- Entity IDs look like "0.0.XXXXXX" and are stored in memory after creation
|
|
18
|
+
- NEVER use example or placeholder IDs like "0.0.123456" - always use actual created entity IDs
|
|
19
|
+
- Account ID ${accountId} is NOT a token - tokens and accounts are different entities
|
|
20
|
+
|
|
21
|
+
Remember the connection numbers when listing connections, as users might refer to them.`;
|
|
@@ -275,7 +275,7 @@ export class ReferenceContextManager {
|
|
|
275
275
|
}
|
|
276
276
|
|
|
277
277
|
if (includeActions) {
|
|
278
|
-
display += `\n💡 You can say "inscribe it" to inscribe this content to the Hedera
|
|
278
|
+
display += `\n💡 You can say "inscribe it" to inscribe this content to the Hedera Hashgraph.`;
|
|
279
279
|
}
|
|
280
280
|
|
|
281
281
|
display += `\n\n*Reference ID: ${reference.referenceId.substring(0, 12)}...*`;
|