From f110634d4b1e87c01a11573bb1c08bb0497b755b Mon Sep 17 00:00:00 2001 From: jmderby Date: Wed, 12 Feb 2025 17:50:10 -0800 Subject: [PATCH 1/2] attempt at deploying eliza --- agent-tee-phala/image/agent/index.ts | 35 ++++++++++++++++++++++++---- agent-tee-phala/image/package.json | 1 + agent-tee-phala/image/pnpm-lock.yaml | 3 +++ 3 files changed, 35 insertions(+), 4 deletions(-) diff --git a/agent-tee-phala/image/agent/index.ts b/agent-tee-phala/image/agent/index.ts index 1a51a00..9d53e14 100644 --- a/agent-tee-phala/image/agent/index.ts +++ b/agent-tee-phala/image/agent/index.ts @@ -1,9 +1,16 @@ -import type { Character } from "@elizaos/core"; +import { AgentRuntime, ModelProviderName, type Character } from "@elizaos/core"; +import { SqlJsDatabaseAdapter } from "@elizaos/adapter-sqljs"; +import initSqlJs from "sql.js"; import createElizaGoatPlugin from "./elizaos"; +const openAiApiKey = process.env.OPENAI_API_KEY as string; + +if (!openAiApiKey) { + throw new Error("Missing OPENAI_API_KEY environment variable"); +} + export default async function startAgent() { const plugins = await createElizaGoatPlugin(); - // @ts-ignore TODO: Finish character and deploy the agent here... const character: Character = { name: "Rufus Agent", adjectives: ["smart", "helpful", "friendly"], @@ -11,9 +18,29 @@ export default async function startAgent() { bio: "You are a helpful assistant that can help with a variety of tasks.", plugins: [plugins], clients: [], - // services: [], + messageExamples: [], + modelProvider: ModelProviderName.OPENAI, + postExamples: [], + style: { all: [], chat: [], post: [] }, + topics: [], }; - console.log("Skipping agent deployment..."); + + // 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, + databaseAdapter: new SqlJsDatabaseAdapter(db), + cacheManager: undefined as any, + }); + await agent.initialize(); + console.log("Agent initialized..."); } startAgent(); diff --git a/agent-tee-phala/image/package.json b/agent-tee-phala/image/package.json index a9a0a61..95e8124 100644 --- a/agent-tee-phala/image/package.json +++ b/agent-tee-phala/image/package.json @@ -23,6 +23,7 @@ "@goat-sdk/wallet-viem": "0.2.0", "@phala/dstack-sdk": "^0.1.7", "@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 90cf1ba..570d462 100644 --- a/agent-tee-phala/image/pnpm-lock.yaml +++ b/agent-tee-phala/image/pnpm-lock.yaml @@ -49,6 +49,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) From 2adc22939a92913574059e991bc13b594ce52187 Mon Sep 17 00:00:00 2001 From: jmderby Date: Tue, 4 Mar 2025 14:38:13 -0800 Subject: [PATCH 2/2] Elizaos: Deploy agent --- agent-tee-phala/image/agent/elizaos/index.ts | 45 +++++++++++++++++++- agent-tee-phala/image/agent/index.ts | 26 +++++------ 2 files changed, 54 insertions(+), 17 deletions(-) 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 808ecdf..786c66e 100644 --- a/agent-tee-phala/image/agent/index.ts +++ b/agent-tee-phala/image/agent/index.ts @@ -1,15 +1,11 @@ -import startVercelAiAgent from "./vercel-ai"; - -const openAiApiKey = process.env.OPENAI_API_KEY as string; - -if (!openAiApiKey) { - throw new Error("Missing OPENAI_API_KEY environment variable"); -} - -export default async function startAgent() { - console.log("Starting agent..."); - await startVercelAiAgent(); - console.log("Agent started"); -} - -startAgent(); +import startElizaGoatPlugin from "./elizaos"; + +(async function () { + try { + console.log("Starting agent..."); + await startElizaGoatPlugin(); + console.log("Agent started"); + } catch (error) { + console.error("Error starting agent:", error); + } +})();