diff --git a/agent-tee-phala/image/agent/elizaos/index.ts b/agent-tee-phala/image/agent/elizaos/index.ts index 0e6bc39..e506876 100644 --- a/agent-tee-phala/image/agent/elizaos/index.ts +++ b/agent-tee-phala/image/agent/elizaos/index.ts @@ -1,7 +1,14 @@ -import type { Plugin } from "@elizaos/core"; +import { AgentRuntime, ModelProviderName, type Character, type Plugin } from "@elizaos/core"; +import initSqlJs from "sql.js"; import { getWalletClient, getWalletProvider } from "./wallet"; +import { SqlJsDatabaseAdapter } from "@elizaos/adapter-sqljs"; -export default async function createElizaGoatPlugin(): Promise { +const openaiApiKey = process.env.OPENAI_API_KEY; +if (!openaiApiKey) { + throw new Error("Missing OPENAI_API_KEY environment variable"); +} + +async function createElizaGoatPlugin(): Promise { const { walletClient, actions } = await getWalletClient(); return { name: "[GOAT] Onchain Actions", @@ -12,3 +19,37 @@ export default async function createElizaGoatPlugin(): Promise { actions, }; } + +export default async function startElizaGoatPlugin() { + const plugins = await createElizaGoatPlugin(); + const character: Character = { + name: "Rufus Agent", + adjectives: ["smart", "helpful", "friendly"], + lore: ["You are a helpful assistant that can help with a variety of tasks."], + bio: "You are a helpful assistant that can help with a variety of tasks.", + plugins: [plugins], + clients: [], + messageExamples: [], + modelProvider: ModelProviderName.OPENAI, + postExamples: [], + style: { all: [], chat: [], post: [] }, + topics: [], + }; + + // Initialize the database + const SQL = await initSqlJs({ + locateFile: (file) => `https://sql.js.org/dist/${file}`, + }); + const db = new SQL.Database(); + + // Initialize the agent + const agent = new AgentRuntime({ + character, + modelProvider: ModelProviderName.OPENAI, + token: openaiApiKey as string, + databaseAdapter: new SqlJsDatabaseAdapter(db), + cacheManager: undefined as any, + }); + await agent.initialize(); + console.log("Agent initialized..."); +} diff --git a/agent-tee-phala/image/agent/index.ts b/agent-tee-phala/image/agent/index.ts index 6cc2041..786c66e 100644 --- a/agent-tee-phala/image/agent/index.ts +++ b/agent-tee-phala/image/agent/index.ts @@ -1,9 +1,11 @@ -import startVercelAiAgent from "./vercel-ai"; +import startElizaGoatPlugin from "./elizaos"; -export default async function startAgent() { - console.log("Starting agent..."); - await startVercelAiAgent(); - console.log("Agent started"); -} - -startAgent(); +(async function () { + try { + console.log("Starting agent..."); + await startElizaGoatPlugin(); + console.log("Agent started"); + } catch (error) { + console.error("Error starting agent:", error); + } +})(); diff --git a/agent-tee-phala/image/package.json b/agent-tee-phala/image/package.json index 9ca7c91..36a747f 100644 --- a/agent-tee-phala/image/package.json +++ b/agent-tee-phala/image/package.json @@ -25,6 +25,7 @@ "@phala/dstack-sdk": "^0.1.10", "@solana/web3.js": "^1.98.0", "@types/express": "^5.0.0", + "@types/sql.js": "^1.4.9", "ai": "^4.1.24", "dotenv": "^16.4.5", "express": "^4.21.2", diff --git a/agent-tee-phala/image/pnpm-lock.yaml b/agent-tee-phala/image/pnpm-lock.yaml index 16536e1..4932246 100644 --- a/agent-tee-phala/image/pnpm-lock.yaml +++ b/agent-tee-phala/image/pnpm-lock.yaml @@ -55,6 +55,9 @@ importers: '@types/express': specifier: ^5.0.0 version: 5.0.0 + '@types/sql.js': + specifier: ^1.4.9 + version: 1.4.9 ai: specifier: ^4.1.24 version: 4.1.24(react@19.0.0)(zod@3.23.8)