UNPKG

@hashgraphonline/standards-agent-kit

Version:

A modular SDK for building on-chain autonomous agents using Hashgraph Online Standards, including HCS-10 for agent discovery and communication.

189 lines (188 loc) 6.59 kB
import { HCS10Client } from '../hcs10/HCS10Client'; import { StructuredTool } from '@langchain/core/tools'; import { z } from 'zod'; import { IStateManager } from '../state/state-types'; /** * RegisterAgentTool wraps the createAndRegisterAgent() function of HCS10Client. * It creates and registers an agent on Hedera using the HCS-10 standard SDK flow. * On success, returns a JSON string containing the new agent's details (including private key). */ export declare class RegisterAgentTool extends StructuredTool { name: string; description: string; private client; private stateManager?; schema: z.ZodObject<{ name: z.ZodString; description: z.ZodOptional<z.ZodString>; type: z.ZodOptional<z.ZodEnum<["autonomous", "manual"]>>; model: z.ZodOptional<z.ZodString>; capabilities: z.ZodOptional<z.ZodArray<z.ZodNumber, "many">>; profilePicture: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodObject<{ url: z.ZodString; filename: z.ZodString; }, "strip", z.ZodTypeAny, { url: string; filename: string; }, { url: string; filename: string; }>, z.ZodObject<{ path: z.ZodString; filename: z.ZodOptional<z.ZodString>; }, "strip", z.ZodTypeAny, { path: string; filename?: string | undefined; }, { path: string; filename?: string | undefined; }>]>>; feeCollectorAccountId: z.ZodOptional<z.ZodString>; hbarFee: z.ZodOptional<z.ZodNumber>; tokenFee: z.ZodOptional<z.ZodObject<{ amount: z.ZodNumber; tokenId: z.ZodString; }, "strip", z.ZodTypeAny, { amount: number; tokenId: string; }, { amount: number; tokenId: string; }>>; hbarFees: z.ZodOptional<z.ZodArray<z.ZodObject<{ amount: z.ZodNumber; collectorAccount: z.ZodOptional<z.ZodString>; }, "strip", z.ZodTypeAny, { amount: number; collectorAccount?: string | undefined; }, { amount: number; collectorAccount?: string | undefined; }>, "many">>; tokenFees: z.ZodOptional<z.ZodArray<z.ZodObject<{ amount: z.ZodNumber; tokenId: z.ZodString; collectorAccount: z.ZodOptional<z.ZodString>; }, "strip", z.ZodTypeAny, { amount: number; tokenId: string; collectorAccount?: string | undefined; }, { amount: number; tokenId: string; collectorAccount?: string | undefined; }>, "many">>; exemptAccountIds: z.ZodOptional<z.ZodArray<z.ZodString, "many">>; setAsCurrent: z.ZodOptional<z.ZodBoolean>; persistence: z.ZodOptional<z.ZodObject<{ prefix: z.ZodOptional<z.ZodString>; }, "strip", z.ZodTypeAny, { prefix?: string | undefined; }, { prefix?: string | undefined; }>>; }, "strip", z.ZodTypeAny, { name: string; capabilities?: number[] | undefined; description?: string | undefined; type?: "autonomous" | "manual" | undefined; model?: string | undefined; profilePicture?: string | { url: string; filename: string; } | { path: string; filename?: string | undefined; } | undefined; feeCollectorAccountId?: string | undefined; hbarFee?: number | undefined; tokenFee?: { amount: number; tokenId: string; } | undefined; hbarFees?: { amount: number; collectorAccount?: string | undefined; }[] | undefined; tokenFees?: { amount: number; tokenId: string; collectorAccount?: string | undefined; }[] | undefined; exemptAccountIds?: string[] | undefined; setAsCurrent?: boolean | undefined; persistence?: { prefix?: string | undefined; } | undefined; }, { name: string; capabilities?: number[] | undefined; description?: string | undefined; type?: "autonomous" | "manual" | undefined; model?: string | undefined; profilePicture?: string | { url: string; filename: string; } | { path: string; filename?: string | undefined; } | undefined; feeCollectorAccountId?: string | undefined; hbarFee?: number | undefined; tokenFee?: { amount: number; tokenId: string; } | undefined; hbarFees?: { amount: number; collectorAccount?: string | undefined; }[] | undefined; tokenFees?: { amount: number; tokenId: string; collectorAccount?: string | undefined; }[] | undefined; exemptAccountIds?: string[] | undefined; setAsCurrent?: boolean | undefined; persistence?: { prefix?: string | undefined; } | undefined; }>; /** * Creates a new RegisterAgentTool instance * @param client - Instance of HCS10Client (already configured with operator/network) * @param stateManager - Optional state manager to store agent details */ constructor(client: HCS10Client, stateManager?: IStateManager); /** * Loads a profile picture from a local file or URL and returns a buffer * @param profilePicture - Local file path or URL * @returns Object containing buffer and filename */ private loadProfilePicture; /** * Calls createAndRegisterAgent() with the provided metadata. * Returns a JSON string with agent details on success, or an error string. */ _call(input: z.infer<typeof this.schema>): Promise<string>; /** * Checks if the token fee configuration is valid */ private hasValidTokenFee; /** * Processes the registration result and returns formatted output */ private processRegistrationResult; /** * Ensures the agent has enough HBAR for operations */ private ensureAgentHasFunds; /** * Validates that all required fields are present in the registration result */ private validateRegistrationResult; /** * Creates a description of the fees configured for the agent */ private createFeeDescription; }