// index.js
import { Client, PrivateKey } from '@hiero-ledger/sdk';
import { AgentMode } from '@hashgraph/hedera-agent-kit';
import { allCorePlugins } from '@hashgraph/hedera-agent-kit/plugins';
import { HederaADKToolkit } from '@hashgraph/hedera-agent-kit-adk';
import { LlmAgent, Runner, InMemorySessionService, isFinalResponse } from '@google/adk';
import 'dotenv/config';
const client = Client.forTestnet().setOperator(
process.env.ACCOUNT_ID,
PrivateKey.fromStringECDSA(process.env.PRIVATE_KEY),
// PrivateKey.fromStringED25519(process.env.PRIVATE_KEY), // use this instead for ED25519 keys
);
const toolkit = new HederaADKToolkit({
client,
configuration: {
tools: [],
plugins: allCorePlugins,
context: {
mode: AgentMode.AUTONOMOUS,
accountId: process.env.ACCOUNT_ID,
},
},
});
const agent = new LlmAgent({
name: 'hedera_agent',
description: 'An AI agent that can interact with the Hedera blockchain.',
model: 'gemini-3.1-flash-lite-preview',
instruction: 'You are a helpful assistant with access to Hedera blockchain tools.',
tools: toolkit.getTools(),
});
const APP_NAME = 'hedera_agent_app';
const USER_ID = 'hedera_user';
const SESSION_ID = 'session_1';
const sessionService = new InMemorySessionService();
await sessionService.createSession({ appName: APP_NAME, sessionId: SESSION_ID, userId: USER_ID });
const runner = new Runner({ appName: APP_NAME, agent, sessionService });
const events = runner.runAsync({
userId: USER_ID,
sessionId: SESSION_ID,
newMessage: { role: 'user', parts: [{ text: "what's my balance?" }] },
});
for await (const event of events) {
if (isFinalResponse(event)) {
const text = event.content?.parts?.map((p) => p.text).filter(Boolean).join(' ');
if (text) console.log(text);
}
}