@hashgraphonline/standards-agent-plugin
Version:
Standards agent plugin for OpenConvAI functionality with HCS-10 tools
116 lines (113 loc) • 4.05 kB
JavaScript
import { ServerSigner, getAllHederaCorePlugins, HederaConversationalAgent } from "hedera-agent-kit";
import { OpenConvAIPlugin } from "./index2.js";
import { OpenConvaiState } from "@hashgraphonline/standards-agent-kit";
import { Logger, HederaMirrorNode } from "@hashgraphonline/standards-sdk";
import { PrivateKey } from "@hashgraph/sdk";
class StandardsKit {
constructor(options) {
this.options = options;
this.stateManager = options.stateManager || new OpenConvaiState();
this.plugin = new OpenConvAIPlugin();
this.logger = new Logger({ module: "StandardsKit" });
}
async initialize() {
const {
accountId,
privateKey,
network = "testnet",
openAIApiKey,
openAIModelName = "gpt-4o",
verbose = false,
operationalMode = "autonomous",
userAccountId,
customSystemMessagePreamble,
customSystemMessagePostamble,
additionalPlugins = [],
scheduleUserTransactionsInBytesMode,
mirrorNodeConfig,
disableLogging
} = this.options;
if (!accountId || !privateKey) {
throw new Error("Account ID and private key are required");
}
try {
const mirrorNode = new HederaMirrorNode(network, this.logger);
const accountInfo = await mirrorNode.requestAccount(accountId);
const keyType = accountInfo?.key?._type || "";
let privateKeyInstance;
if (keyType?.toLowerCase()?.includes("ecdsa")) {
privateKeyInstance = PrivateKey.fromStringECDSA(privateKey);
} else {
privateKeyInstance = PrivateKey.fromStringED25519(privateKey);
}
const serverSigner = new ServerSigner(
accountId,
privateKeyInstance,
network
);
const defaultSystemMessage = `You are a helpful assistant managing Hedera HCS-10 connections and messages.
You have access to tools for registering agents, finding registered agents, initiating connections, listing active connections, sending messages over connections, and checking for new messages.
*** IMPORTANT CONTEXT ***
You are currently operating as agent: ${accountId}
When users ask about "my profile", "my account", "my connections", etc., use this account ID: ${accountId}
Remember the connection numbers when listing connections, as users might refer to them.`;
const allPlugins = [
this.plugin,
...additionalPlugins,
...getAllHederaCorePlugins()
];
const agentConfig = {
pluginConfig: {
plugins: allPlugins,
appConfig: {
stateManager: this.stateManager
}
},
openAIApiKey,
openAIModelName,
verbose,
operationalMode,
userAccountId,
customSystemMessagePreamble: customSystemMessagePreamble || defaultSystemMessage,
...customSystemMessagePostamble !== void 0 && {
customSystemMessagePostamble
},
...scheduleUserTransactionsInBytesMode !== void 0 && {
scheduleUserTransactionsInBytesMode
},
...mirrorNodeConfig !== void 0 && { mirrorNodeConfig },
...disableLogging !== void 0 && { disableLogging }
};
this.conversationalAgent = new HederaConversationalAgent(
serverSigner,
agentConfig
);
await this.conversationalAgent.initialize();
} catch (error) {
this.logger.error("Failed to initialize StandardsKit:", error);
throw error;
}
}
getPlugin() {
return this.plugin;
}
getStateManager() {
return this.stateManager;
}
getConversationalAgent() {
if (!this.conversationalAgent) {
throw new Error("StandardsKit not initialized. Call initialize() first.");
}
return this.conversationalAgent;
}
async processMessage(message, chatHistory = []) {
if (!this.conversationalAgent) {
throw new Error("StandardsKit not initialized. Call initialize() first.");
}
return this.conversationalAgent.processMessage(message, chatHistory);
}
}
export {
StandardsKit
};
//# sourceMappingURL=index3.js.map