@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.
94 lines (93 loc) • 3.19 kB
JavaScript
import { StructuredTool } from "@langchain/core/tools";
import { z } from "zod";
import { AIAgentCapability, Logger } from "@hashgraphonline/standards-sdk";
class FindRegistrationsTool extends StructuredTool {
constructor({ hcsClient, ...rest }) {
super(rest);
this.name = "find_registrations";
this.description = "Searches the configured agent registry for HCS-10 agents. You can filter by account ID or tags. Returns basic registration info.";
this.schema = z.object({
accountId: z.string().optional().describe(
"Optional: Filter registrations by a specific Hedera account ID (e.g., 0.0.12345)."
),
tags: z.array(z.nativeEnum(AIAgentCapability)).optional().describe(
"Optional: Filter registrations by a list of tags (API filter only)."
)
});
this.hcsClient = hcsClient;
this.logger = Logger.getInstance({ module: "FindRegistrationsTool" });
}
async _call({
accountId,
tags
}) {
this.logger.info(
"Searching registrations with filters - Account ID",
JSON.stringify({
accountId,
tags
})
);
const options = {};
if (accountId) {
options.accountId = accountId;
}
if (tags && tags.length > 0) {
options.tags = tags;
}
options.network = this.hcsClient.getNetwork();
try {
if (!this.hcsClient.standardClient) {
throw new Error(
"Standard SDK client instance is not available in HCS10Client wrapper."
);
}
const result = await this.hcsClient.standardClient.findRegistrations(
options
);
if (!result.success || result.error) {
return `Error finding registrations: ${result.error || "Unknown error"}`;
}
if (!result.registrations || result.registrations.length === 0) {
return "No registrations found matching the criteria.";
}
let output = `Found ${result.registrations.length} registration(s):
`;
result.registrations.forEach((reg, index) => {
const metadata = reg.metadata;
output += `${index + 1}. Name: ${metadata.alias || "N/A"}
`;
output += `Description: ${metadata.bio || "N/A"}
`;
output += ` Account ID: ${reg.accountId}
`;
output += ` Status: ${reg.status}
`;
output += ` Model: ${metadata.properties?.model || "N/A"}
`;
if (metadata.properties?.capabilities && metadata.properties.capabilities.length > 0) {
output += ` Capabilities: ${metadata.properties.capabilities.join(", ")}
`;
}
if (metadata.properties) {
output += ` Properties: ${JSON.stringify(metadata.properties)}
`;
}
output += ` Inbound Topic: ${reg.inboundTopicId}
`;
output += ` Outbound Topic: ${reg.outboundTopicId}
`;
output += ` Created At: ${reg.createdAt}
`;
});
return output.trim();
} catch (error) {
this.logger.error(`Failed to execute findRegistrations: ${error}`);
return `Error searching registrations: ${error instanceof Error ? error.message : String(error)}`;
}
}
}
export {
FindRegistrationsTool
};
//# sourceMappingURL=standards-agent-kit.es10.js.map