@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.
70 lines (69 loc) • 2.8 kB
JavaScript
import { StructuredTool } from "@langchain/core/tools";
import { z } from "zod";
import { Logger } from "@hashgraphonline/standards-sdk";
class RetrieveProfileTool extends StructuredTool {
/**
* Creates a new RetrieveProfileTool instance.
* @param client - An instance of HCS10Client.
*/
constructor(client) {
super();
this.name = "retrieve_profile";
this.description = "Retrieves the HCS-11 profile data associated with a given Hedera account ID. If no account ID is provided, it defaults to the current operator account ID. Returns the profile object as a JSON string on success.";
this.schema = z.object({
accountId: z.string().optional().describe(
"The Hedera account ID (e.g., 0.0.12345) to retrieve the profile for. If omitted, defaults to the current operator account ID."
),
disableCache: z.boolean().optional().describe(
"Optional: Set to true to bypass the cache and fetch fresh profile data."
)
});
this.client = client;
this.logger = Logger.getInstance({ module: this.name });
}
/**
* Executes the profile retrieval.
* @param input - The input object containing accountId and optional disableCache flag.
* @returns A JSON string of the profile on success, or an error message string.
*/
async _call(input) {
let targetAccountId;
try {
if (input.accountId) {
targetAccountId = input.accountId;
} else {
this.logger.info("accountId not provided, defaulting to operator ID.");
targetAccountId = this.client.getOperatorId();
}
if (!targetAccountId) {
throw new Error("Could not determine target account ID.");
}
this.logger.info(
`Attempting to retrieve profile for account: ${targetAccountId}, Disable Cache: ${!!input.disableCache}`
);
const result = await this.client.standardClient.retrieveProfile(
targetAccountId,
input.disableCache
);
if (result.success && result.profile) {
this.logger.info(
`Successfully retrieved profile for ${targetAccountId}.`
);
return JSON.stringify(result.profile, null, 2);
} else {
const errorMessage = `Error retrieving profile for ${targetAccountId}: ${result.error || "Profile not found or invalid."}`;
this.logger.error(errorMessage);
return errorMessage;
}
} catch (error) {
const idForError = input.accountId || "operator default";
const errorMessage = `Unexpected error retrieving profile for ${idForError}: ${error instanceof Error ? error.message : String(error)}`;
this.logger.error(errorMessage, error);
return errorMessage;
}
}
}
export {
RetrieveProfileTool
};
//# sourceMappingURL=standards-agent-kit.es14.js.map