diff --git a/.env.example b/.env.example index 444bf1a79a..081f92f279 100644 --- a/.env.example +++ b/.env.example @@ -5,6 +5,7 @@ OPENAI_API_KEY=sk-* # OpenAI API key, starting with sk- REDPILL_API_KEY= # REDPILL API Key GROQ_API_KEY=gsk_* OPENROUTER_API_KEY= +GOOGLE_GENERATIVE_AI_API_KEY= # Gemini API key ELEVENLABS_XI_API_KEY= # API key from elevenlabs diff --git a/README.md b/README.md index 3786057ef1..c8c2b32637 100644 --- a/README.md +++ b/README.md @@ -83,6 +83,7 @@ DISCORD_APPLICATION_ID= DISCORD_API_TOKEN= # Bot token OPENAI_API_KEY=sk-* # OpenAI API key, starting with sk- ELEVENLABS_XI_API_KEY= # API key from elevenlabs +GOOGLE_GENERATIVE_AI_API_KEY= # Gemini API key # ELEVENLABS SETTINGS ELEVENLABS_MODEL_ID=eleven_multilingual_v2 diff --git a/packages/adapter-postgres/src/index.ts b/packages/adapter-postgres/src/index.ts index b081e50aea..00d61867da 100644 --- a/packages/adapter-postgres/src/index.ts +++ b/packages/adapter-postgres/src/index.ts @@ -26,7 +26,6 @@ export class PostgresDatabaseAdapter extends DatabaseAdapter { connectionTimeoutMillis: 2000, }); - // Register error handler for pool this.pool.on("error", (err) => { console.error("Unexpected error on idle client", err); }); @@ -37,22 +36,15 @@ export class PostgresDatabaseAdapter extends DatabaseAdapter { async testConnection(): Promise { let client; try { - // Attempt to get a client from the pool client = await this.pool.connect(); - - // Test the connection with a simple query const result = await client.query("SELECT NOW()"); console.log("Database connection test successful:", result.rows[0]); - return true; } catch (error) { console.error("Database connection test failed:", error); throw new Error(`Failed to connect to database: ${error.message}`); } finally { - // Make sure to release the client back to the pool - if (client) { - client.release(); - } + if (client) client.release(); } } @@ -73,9 +65,9 @@ export class PostgresDatabaseAdapter extends DatabaseAdapter { const client = await this.pool.connect(); try { const { rows } = await client.query( - `SELECT id, "userId", "roomId", last_message_read - FROM participants - WHERE "userId" = $1`, + `SELECT id, "userId", "roomId", "last_message_read" + FROM participants + WHERE "userId" = $1`, [userId] ); return rows as Participant[]; @@ -91,7 +83,7 @@ export class PostgresDatabaseAdapter extends DatabaseAdapter { const client = await this.pool.connect(); try { const { rows } = await client.query( - `SELECT userState FROM participants WHERE "roomId" = $1 AND userId = $2`, + `SELECT "userState" FROM participants WHERE "roomId" = $1 AND "userId" = $2`, [roomId, userId] ); return rows.length > 0 ? rows[0].userState : null; @@ -116,14 +108,14 @@ export class PostgresDatabaseAdapter extends DatabaseAdapter { let queryParams = [params.tableName, ...params.roomIds]; if (params.agentId) { - query += ` AND "userId" = $${params.roomIds.length + 2}`; + query += ` AND "agentId" = $${params.roomIds.length + 2}`; queryParams = [...queryParams, params.agentId]; } const { rows } = await client.query(query, queryParams); return rows.map((row) => ({ ...row, - content: JSON.parse(row.content), + content: typeof row.content === "string" ? JSON.parse(row.content) : row.content, })); } finally { client.release(); @@ -169,14 +161,12 @@ export class PostgresDatabaseAdapter extends DatabaseAdapter { if (rows.length === 0) return null; const account = rows[0]; - console.log("account", account); return { ...account, - details: - typeof account.details === "string" - ? JSON.parse(account.details) - : account.details, + details: typeof account.details === "string" + ? JSON.parse(account.details) + : account.details, }; } finally { client.release(); @@ -188,7 +178,7 @@ export class PostgresDatabaseAdapter extends DatabaseAdapter { try { await client.query( `INSERT INTO accounts (id, name, username, email, "avatarUrl", details) - VALUES ($1, $2, $3, $4, $5, $6)`, + VALUES ($1, $2, $3, $4, $5, $6)`, [ account.id ?? v4(), account.name, @@ -212,17 +202,16 @@ export class PostgresDatabaseAdapter extends DatabaseAdapter { try { const { rows } = await client.query( `SELECT a.id, a.name, a.username, a.details - FROM participants p - LEFT JOIN accounts a ON p."userId" = a.id - WHERE p."roomId" = $1`, + FROM participants p + LEFT JOIN accounts a ON p."userId" = a.id + WHERE p."roomId" = $1`, [params.roomId] ); return rows.map((row) => ({ ...row, - details: - typeof row.details === "string" - ? JSON.parse(row.details) - : row.details, + details: typeof row.details === "string" + ? JSON.parse(row.details) + : row.details, })); } finally { client.release(); @@ -240,10 +229,9 @@ export class PostgresDatabaseAdapter extends DatabaseAdapter { return { ...rows[0], - content: - typeof rows[0].content === "string" - ? JSON.parse(rows[0].content) - : rows[0].content, + content: typeof rows[0].content === "string" + ? JSON.parse(rows[0].content) + : rows[0].content, }; } finally { client.release(); @@ -269,13 +257,13 @@ export class PostgresDatabaseAdapter extends DatabaseAdapter { await client.query( `INSERT INTO memories ( - id, type, content, embedding, "userId", "roomId", "agentId", "unique", "createdAt" - ) VALUES ($1, $2, $3, $4::vector, $5::uuid, $6::uuid, $7::uuid, $8, to_timestamp($9/1000.0))`, + id, type, content, embedding, "userId", "roomId", "agentId", "unique", "createdAt" + ) VALUES ($1, $2, $3, $4, $5::uuid, $6::uuid, $7::uuid, $8, to_timestamp($9/1000.0))`, [ memory.id ?? v4(), tableName, JSON.stringify(memory.content), - `[${memory.embedding.join(",")}]`, + memory.embedding ? `[${memory.embedding.join(",")}]` : null, memory.userId, memory.roomId, memory.agentId, @@ -299,19 +287,19 @@ export class PostgresDatabaseAdapter extends DatabaseAdapter { const client = await this.pool.connect(); try { let sql = ` - SELECT *, - 1 - (embedding <-> $3) as similarity - FROM memories - WHERE type = $1 AND "roomId" = $2 - `; + SELECT *, + 1 - (embedding <-> $3) as similarity + FROM memories + WHERE type = $1 AND "roomId" = $2 + `; if (params.unique) { sql += ` AND "unique" = true`; } sql += ` AND 1 - (embedding <-> $3) >= $4 - ORDER BY embedding <-> $3 - LIMIT $5`; + ORDER BY embedding <-> $3 + LIMIT $5`; const { rows } = await client.query(sql, [ params.tableName, @@ -323,7 +311,7 @@ export class PostgresDatabaseAdapter extends DatabaseAdapter { return rows.map((row) => ({ ...row, - content: JSON.parse(row.content), + content: typeof row.content === "string" ? JSON.parse(row.content) : row.content, similarity: row.similarity, })); } finally { @@ -366,7 +354,8 @@ export class PostgresDatabaseAdapter extends DatabaseAdapter { } if (params.agentId) { - sql += " AND agentId = $3"; + paramCount++; + sql += ` AND "agentId" = $${paramCount}`; values.push(params.agentId); } @@ -383,10 +372,9 @@ export class PostgresDatabaseAdapter extends DatabaseAdapter { const { rows } = await client.query(sql, values); return rows.map((row) => ({ ...row, - content: - typeof row.content === "string" - ? JSON.parse(row.content) - : row.content, + content: typeof row.content === "string" + ? JSON.parse(row.content) + : row.content, })); } finally { client.release(); @@ -424,10 +412,9 @@ export class PostgresDatabaseAdapter extends DatabaseAdapter { const { rows } = await client.query(sql, values); return rows.map((row) => ({ ...row, - objectives: - typeof row.objectives === "string" - ? JSON.parse(row.objectives) - : row.objectives, + objectives: typeof row.objectives === "string" + ? JSON.parse(row.objectives) + : row.objectives, })); } finally { client.release(); @@ -438,13 +425,8 @@ export class PostgresDatabaseAdapter extends DatabaseAdapter { const client = await this.pool.connect(); try { await client.query( - "UPDATE goals SET name = $1, status = $2, objectives = $3 WHERE id = $4", - [ - goal.name, - goal.status, - JSON.stringify(goal.objectives), - goal.id, - ] + `UPDATE goals SET name = $1, status = $2, objectives = $3 WHERE id = $4`, + [goal.name, goal.status, JSON.stringify(goal.objectives), goal.id] ); } finally { client.release(); @@ -456,7 +438,7 @@ export class PostgresDatabaseAdapter extends DatabaseAdapter { try { await client.query( `INSERT INTO goals (id, "roomId", "userId", name, status, objectives) - VALUES ($1, $2, $3, $4, $5, $6)`, + VALUES ($1, $2, $3, $4, $5, $6)`, [ goal.id ?? v4(), goal.roomId, @@ -484,9 +466,7 @@ export class PostgresDatabaseAdapter extends DatabaseAdapter { const client = await this.pool.connect(); try { const newRoomId = roomId || v4(); - await client.query("INSERT INTO rooms (id) VALUES ($1)", [ - newRoomId, - ]); + await client.query("INSERT INTO rooms (id) VALUES ($1)", [newRoomId]); return newRoomId as UUID; } finally { client.release(); @@ -514,7 +494,7 @@ export class PostgresDatabaseAdapter extends DatabaseAdapter { try { await client.query( `INSERT INTO relationships (id, "userA", "userB", "userId") - VALUES ($1, $2, $3, $4)`, + VALUES ($1, $2, $3, $4)`, [v4(), params.userA, params.userB, params.userA] ); return true; @@ -534,7 +514,7 @@ export class PostgresDatabaseAdapter extends DatabaseAdapter { try { const { rows } = await client.query( `SELECT * FROM relationships - WHERE ("userA" = $1 AND "userB" = $2) OR ("userA" = $2 AND "userB" = $1)`, + WHERE ("userA" = $1 AND "userB" = $2) OR ("userA" = $2 AND "userB" = $1)`, [params.userA, params.userB] ); return rows.length > 0 ? rows[0] : null; @@ -566,15 +546,30 @@ export class PostgresDatabaseAdapter extends DatabaseAdapter { }): Promise<{ embedding: number[]; levenshtein_score: number }[]> { const client = await this.pool.connect(); try { + // Get the JSON field content as text first const sql = ` - SELECT embedding, - levenshtein($1, content->$2->$3) as levenshtein_score - FROM memories - WHERE type = $4 - ORDER BY levenshtein_score - LIMIT $5 - `; - + WITH content_text AS ( + SELECT + embedding, + COALESCE( + content->$2->>$3, + '' + ) as content_text + FROM memories + WHERE type = $4 + AND content->$2->>$3 IS NOT NULL + ) + SELECT + embedding, + levenshtein( + $1, + content_text + ) as levenshtein_score + FROM content_text + ORDER BY levenshtein_score + LIMIT $5 + `; + const { rows } = await client.query(sql, [ opts.query_input, opts.query_field_name, @@ -582,11 +577,14 @@ export class PostgresDatabaseAdapter extends DatabaseAdapter { opts.query_table_name, opts.query_match_count, ]); - + return rows.map((row) => ({ embedding: row.embedding, levenshtein_score: row.levenshtein_score, })); + } catch (error) { + console.error('Error in getCachedEmbeddings:', error); + throw error; } finally { client.release(); } @@ -601,7 +599,8 @@ export class PostgresDatabaseAdapter extends DatabaseAdapter { const client = await this.pool.connect(); try { await client.query( - 'INSERT INTO logs (body, "userId", "roomId", type) VALUES ($1, $2, $3, $4)', + `INSERT INTO logs (body, "userId", "roomId", type) + VALUES ($1, $2, $3, $4)`, [params.body, params.userId, params.roomId, params.type] ); } finally { @@ -622,15 +621,14 @@ export class PostgresDatabaseAdapter extends DatabaseAdapter { ): Promise { const client = await this.pool.connect(); try { - // Format the embedding array as a proper vector string const vectorStr = `[${embedding.join(",")}]`; let sql = ` - SELECT *, - 1 - (embedding <-> $1::vector) as similarity - FROM memories - WHERE type = $2 - `; + SELECT *, + 1 - (embedding <-> $1::vector) as similarity + FROM memories + WHERE type = $2 + `; const values: any[] = [vectorStr, params.tableName]; let paramCount = 2; @@ -640,7 +638,8 @@ export class PostgresDatabaseAdapter extends DatabaseAdapter { } if (params.agentId) { - sql += " AND agentId = $3"; + paramCount++; + sql += ` AND "agentId" = $${paramCount}`; values.push(params.agentId); } @@ -667,10 +666,9 @@ export class PostgresDatabaseAdapter extends DatabaseAdapter { const { rows } = await client.query(sql, values); return rows.map((row) => ({ ...row, - content: - typeof row.content === "string" - ? JSON.parse(row.content) - : row.content, + content: typeof row.content === "string" + ? JSON.parse(row.content) + : row.content, similarity: row.similarity, })); } finally { @@ -682,7 +680,8 @@ export class PostgresDatabaseAdapter extends DatabaseAdapter { const client = await this.pool.connect(); try { await client.query( - 'INSERT INTO participants (id, "userId", "roomId") VALUES ($1, $2, $3)', + `INSERT INTO participants (id, "userId", "roomId") + VALUES ($1, $2, $3)`, [v4(), userId, roomId] ); return true; @@ -698,7 +697,7 @@ export class PostgresDatabaseAdapter extends DatabaseAdapter { const client = await this.pool.connect(); try { await client.query( - 'DELETE FROM participants WHERE "userId" = $1 AND "roomId" = $2', + `DELETE FROM participants WHERE "userId" = $1 AND "roomId" = $2`, [userId, roomId] ); return true; @@ -716,10 +715,10 @@ export class PostgresDatabaseAdapter extends DatabaseAdapter { }): Promise { const client = await this.pool.connect(); try { - await client.query("UPDATE goals SET status = $1 WHERE id = $2", [ - params.status, - params.goalId, - ]); + await client.query( + "UPDATE goals SET status = $1 WHERE id = $2", + [params.status, params.goalId] + ); } finally { client.release(); } @@ -741,7 +740,7 @@ export class PostgresDatabaseAdapter extends DatabaseAdapter { const client = await this.pool.connect(); try { await client.query( - "DELETE FROM memories WHERE type = $1 AND roomId = $2", + `DELETE FROM memories WHERE type = $1 AND "roomId" = $2`, [tableName, roomId] ); } finally { @@ -773,9 +772,10 @@ export class PostgresDatabaseAdapter extends DatabaseAdapter { async removeAllGoals(roomId: UUID): Promise { const client = await this.pool.connect(); try { - await client.query(`DELETE FROM goals WHERE "roomId" = $1`, [ - roomId, - ]); + await client.query( + `DELETE FROM goals WHERE "roomId" = $1`, + [roomId] + ); } finally { client.release(); } @@ -807,21 +807,21 @@ export class PostgresDatabaseAdapter extends DatabaseAdapter { client.release(); } } + async getActorDetails(params: { roomId: string }): Promise { const sql = ` - SELECT - a.id, - a.name, - a.username, - COALESCE(a.details::jsonb, '{}'::jsonb) as details - FROM participants p - LEFT JOIN accounts a ON p.userId = a.id - WHERE p.roomId = $1 - `; + SELECT + a.id, + a.name, + a.username, + COALESCE(a.details::jsonb, '{}'::jsonb) as details + FROM participants p + LEFT JOIN accounts a ON p."userId" = a.id + WHERE p."roomId" = $1 + `; try { const result = await this.pool.query(sql, [params.roomId]); - return result.rows.map((row) => ({ ...row, details: row.details, // PostgreSQL automatically handles JSON parsing @@ -832,4 +832,5 @@ export class PostgresDatabaseAdapter extends DatabaseAdapter { } } } -export default PostgresDatabaseAdapter; + +export default PostgresDatabaseAdapter; \ No newline at end of file diff --git a/packages/agent/package.json b/packages/agent/package.json index 152d6c39ca..518844a64a 100644 --- a/packages/agent/package.json +++ b/packages/agent/package.json @@ -16,6 +16,7 @@ "@ai16z/adapter-postgres": "workspace:*", "@ai16z/adapter-sqlite": "workspace:*", "@ai16z/client-direct": "workspace:*", + "@ai16z/client-auto": "workspace:*", "@ai16z/client-discord": "workspace:*", "@ai16z/client-telegram": "workspace:*", "@ai16z/client-twitter": "workspace:*", diff --git a/packages/agent/src/index.ts b/packages/agent/src/index.ts index 0c2a8e36bc..24bffaf62f 100644 --- a/packages/agent/src/index.ts +++ b/packages/agent/src/index.ts @@ -2,6 +2,7 @@ import { PostgresDatabaseAdapter } from "@ai16z/adapter-postgres/src/index.ts"; import { SqliteDatabaseAdapter } from "@ai16z/adapter-sqlite/src/index.ts"; import { DirectClientInterface } from "@ai16z/client-direct/src/index.ts"; import { DiscordClientInterface } from "@ai16z/client-discord/src/index.ts"; +import { AutoClientInterface } from "@ai16z/client-auto/src/index.ts"; import { TelegramClientInterface } from "@ai16z/client-telegram/src/index.ts"; import { TwitterClientInterface } from "@ai16z/client-twitter/src/index.ts"; import { defaultCharacter } from "@ai16z/eliza/src/defaultCharacter.ts"; @@ -174,6 +175,11 @@ export async function initializeClients( const clientTypes = character.clients?.map((str) => str.toLowerCase()) || []; + if (clientTypes.includes("auto")) { + const autoClient = await AutoClientInterface.start(runtime); + if (autoClient) clients.push(autoClient); + } + if (clientTypes.includes("discord")) { clients.push(await DiscordClientInterface.start(runtime)); } diff --git a/packages/client-auto/package.json b/packages/client-auto/package.json new file mode 100644 index 0000000000..c90c356d0b --- /dev/null +++ b/packages/client-auto/package.json @@ -0,0 +1,27 @@ +{ + "name": "@ai16z/client-auto", + "version": "0.0.1", + "main": "dist/index.js", + "type": "module", + "types": "dist/index.d.ts", + "dependencies": { + "@ai16z/eliza": "workspace:*", + "@ai16z/plugin-image-generation": "workspace:*", + "@types/body-parser": "1.19.5", + "@types/cors": "2.8.17", + "@types/express": "5.0.0", + "body-parser": "1.20.3", + "cors": "2.8.5", + "multer": "1.4.5-lts.1" + }, + "devDependencies": { + "tsup": "^8.3.5" + }, + "scripts": { + "build": "tsup --format esm --dts", + "dev": "tsup --watch" + }, + "peerDependencies": { + "whatwg-url": "7.1.0" + } +} diff --git a/packages/client-auto/src/index.ts b/packages/client-auto/src/index.ts new file mode 100644 index 0000000000..2c2d56da8f --- /dev/null +++ b/packages/client-auto/src/index.ts @@ -0,0 +1,54 @@ +import { + Client, + IAgentRuntime +} from "@ai16z/eliza/src/types.ts"; + + +export class AutoClient { + interval: NodeJS.Timeout; + runtime: IAgentRuntime; + + constructor(runtime: IAgentRuntime) { + this.runtime = runtime; + // start a loop that runs every x seconds + this.interval = setInterval(() => { + this.makeTrades(); + }, 60 * 60 * 1000); // 1 hour in milliseconds + + } + + makeTrades() { + console.log("Running auto loop"); + + // malibu todos + // get high trust recommendations + + // get information for all tokens which were recommended + // get any additional information we might need + // make sure we're looking at the right tokens and data + + // shaw -- TODOs + // compose thesis context + // write a thesis which trades and why + + // compose trade context + // geratate trades with LLM + // parse trades from LLM + // post thesis to twitter + + // malibu todos + // execute trades + } +} + +export const AutoClientInterface: Client = { + start: async (runtime: IAgentRuntime) => { + const client = new AutoClient(runtime); + return client; + }, + stop: async (runtime: IAgentRuntime) => { + console.warn("Direct client does not support stopping yet"); + }, +}; + +export default AutoClientInterface; diff --git a/packages/client-auto/tsconfig.json b/packages/client-auto/tsconfig.json new file mode 100644 index 0000000000..eaa78145aa --- /dev/null +++ b/packages/client-auto/tsconfig.json @@ -0,0 +1,8 @@ +{ + "extends": "../../tsconfig.json", + "compilerOptions": { + "outDir": "dist", + "rootDir": "./src" + }, + "include": ["src"] +} diff --git a/packages/client-auto/tsup.config.ts b/packages/client-auto/tsup.config.ts new file mode 100644 index 0000000000..e42bf4efea --- /dev/null +++ b/packages/client-auto/tsup.config.ts @@ -0,0 +1,20 @@ +import { defineConfig } from "tsup"; + +export default defineConfig({ + entry: ["src/index.ts"], + outDir: "dist", + sourcemap: true, + clean: true, + format: ["esm"], // Ensure you're targeting CommonJS + external: [ + "dotenv", // Externalize dotenv to prevent bundling + "fs", // Externalize fs to use Node.js built-in module + "path", // Externalize other built-ins if necessary + "@reflink/reflink", + "@node-llama-cpp", + "https", + "http", + "agentkeepalive", + // Add other modules you want to externalize + ], +}); diff --git a/packages/core/src/generation.ts b/packages/core/src/generation.ts index f6cdbf7227..43cd2e240a 100644 --- a/packages/core/src/generation.ts +++ b/packages/core/src/generation.ts @@ -11,6 +11,7 @@ import { default as tiktoken, TiktokenModel } from "tiktoken"; import Together from "together-ai"; import { elizaLogger } from "./index.ts"; import models from "./models.ts"; +import { createGoogleGenerativeAI } from "@ai-sdk/google"; import { parseBooleanFromText, parseJsonArrayFromText, @@ -104,6 +105,25 @@ export async function generateText({ break; } + case ModelProviderName.GOOGLE: + const google = createGoogleGenerativeAI(); + + const { text: anthropicResponse } = await aiGenerateText({ + model: google(model), + prompt: context, + system: + runtime.character.system ?? + settings.SYSTEM_PROMPT ?? + undefined, + temperature: temperature, + maxTokens: max_response_length, + frequencyPenalty: frequency_penalty, + presencePenalty: presence_penalty, + }); + + response = anthropicResponse; + break; + case ModelProviderName.ANTHROPIC: { elizaLogger.log("Initializing Anthropic model."); @@ -214,7 +234,6 @@ export async function generateText({ break; } - case ModelProviderName.OPENROUTER: { elizaLogger.log("Initializing OpenRouter model."); const serverUrl = models[provider].endpoint; @@ -238,7 +257,6 @@ export async function generateText({ break; } - case ModelProviderName.OLLAMA: { console.log("Initializing Ollama model."); @@ -425,10 +443,13 @@ export async function generateTrueOrFalse({ modelClass: string; }): Promise { let retryDelay = 1000; - console.log("modelClass", modelClass) + console.log("modelClass", modelClass); const stop = Array.from( - new Set([...(models[runtime.modelProvider].settings.stop || []), ["\n"]]) + new Set([ + ...(models[runtime.modelProvider].settings.stop || []), + ["\n"], + ]) ) as string[]; while (true) { diff --git a/packages/core/src/models.ts b/packages/core/src/models.ts index 2e4ca2ad3f..0d230e75be 100644 --- a/packages/core/src/models.ts +++ b/packages/core/src/models.ts @@ -137,9 +137,9 @@ const models: Models = { temperature: 0.3, }, model: { - [ModelClass.SMALL]: "gemini-1.5-flash", - [ModelClass.MEDIUM]: "gemini-1.5-flash", - [ModelClass.LARGE]: "gemini-1.5-pro", + [ModelClass.SMALL]: "gemini-1.5-flash-latest", + [ModelClass.MEDIUM]: "gemini-1.5-flash-latest", + [ModelClass.LARGE]: "gemini-1.5-pro-latest", [ModelClass.EMBEDDING]: "text-embedding-004", }, }, @@ -187,8 +187,7 @@ const models: Models = { settings.LARGE_OPENROUTER_MODEL || settings.OPENROUTER_MODEL || "nousresearch/hermes-3-llama-3.1-405b", - [ModelClass.EMBEDDING]: - "text-embedding-3-small", + [ModelClass.EMBEDDING]: "text-embedding-3-small", }, }, [ModelProviderName.OLLAMA]: { diff --git a/packages/core/src/parsing.ts b/packages/core/src/parsing.ts index 1cf110868d..4041419983 100644 --- a/packages/core/src/parsing.ts +++ b/packages/core/src/parsing.ts @@ -14,6 +14,7 @@ export const parseShouldRespondFromText = ( text: string ): "RESPOND" | "IGNORE" | "STOP" | null => { const match = text + .split('\n')[0] .trim() .replace("[", "") .toUpperCase() @@ -21,7 +22,7 @@ export const parseShouldRespondFromText = ( .match(/^(RESPOND|IGNORE|STOP)$/i); return match ? (match[0].toUpperCase() as "RESPOND" | "IGNORE" | "STOP") - : null; + : text.includes("RESPOND") ? "RESPOND" : text.includes("IGNORE") ? "IGNORE" : text.includes("STOP") ? "STOP" : null; }; export const booleanFooter = `Respond with a YES or a NO.`; diff --git a/packages/core/src/runtime.ts b/packages/core/src/runtime.ts index 2731ed0ec4..6ec9494704 100644 --- a/packages/core/src/runtime.ts +++ b/packages/core/src/runtime.ts @@ -498,14 +498,14 @@ export class AgentRuntime implements IAgentRuntime { * @returns The results of the evaluation. */ async evaluate(message: Memory, state?: State, didRespond?: boolean) { - console.log("Evaluate: ", didRespond) + console.log("Evaluate: ", didRespond); const evaluatorPromises = this.evaluators.map( async (evaluator: Evaluator) => { - console.log("Evaluating", evaluator.name) + console.log("Evaluating", evaluator.name); if (!evaluator.handler) { return null; } - if(!didRespond && !evaluator.alwaysRun) { + if (!didRespond && !evaluator.alwaysRun) { return null; } const result = await evaluator.validate(this, message, state); diff --git a/packages/core/src/types.ts b/packages/core/src/types.ts index 4fa54fcb90..7d61a241f5 100644 --- a/packages/core/src/types.ts +++ b/packages/core/src/types.ts @@ -550,7 +550,11 @@ export interface IAgentRuntime { state?: State, callback?: HandlerCallback ): Promise; - evaluate(message: Memory, state?: State, didRespond?: boolean): Promise; + evaluate( + message: Memory, + state?: State, + didRespond?: boolean + ): Promise; ensureParticipantExists(userId: UUID, roomId: UUID): Promise; ensureUserExists( userId: UUID, diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 8ac65575ff..fdc56e0ea5 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -182,6 +182,9 @@ importers: '@ai16z/adapter-sqlite': specifier: workspace:* version: link:../adapter-sqlite + '@ai16z/client-auto': + specifier: workspace:* + version: link:../client-auto '@ai16z/client-direct': specifier: workspace:* version: link:../client-direct @@ -223,6 +226,40 @@ importers: specifier: ^8.3.5 version: 8.3.5(jiti@1.21.6)(postcss@8.4.47)(tsx@4.19.2)(typescript@5.6.3)(yaml@2.6.0) + packages/client-auto: + dependencies: + '@ai16z/eliza': + specifier: workspace:* + version: link:../core + '@ai16z/plugin-image-generation': + specifier: workspace:* + version: link:../plugin-image-generation + '@types/body-parser': + specifier: 1.19.5 + version: 1.19.5 + '@types/cors': + specifier: 2.8.17 + version: 2.8.17 + '@types/express': + specifier: 5.0.0 + version: 5.0.0 + body-parser: + specifier: 1.20.3 + version: 1.20.3 + cors: + specifier: 2.8.5 + version: 2.8.5 + multer: + specifier: 1.4.5-lts.1 + version: 1.4.5-lts.1 + whatwg-url: + specifier: 7.1.0 + version: 7.1.0 + devDependencies: + tsup: + specifier: ^8.3.5 + version: 8.3.5(jiti@1.21.6)(postcss@8.4.47)(tsx@4.19.2)(typescript@5.6.3)(yaml@2.6.0) + packages/client-direct: dependencies: '@ai16z/eliza': @@ -472,7 +509,7 @@ importers: version: 2.79.2 ts-jest: specifier: 29.2.5 - version: 29.2.5(@babel/core@7.26.0)(@jest/transform@29.7.0)(@jest/types@29.6.3)(babel-jest@29.7.0(@babel/core@7.26.0))(esbuild@0.24.0)(jest@29.7.0(@types/node@22.8.4)(ts-node@10.9.2(@types/node@22.8.4)(typescript@5.6.3)))(typescript@5.6.3) + version: 29.2.5(@babel/core@7.26.0)(@jest/transform@29.7.0)(@jest/types@29.6.3)(babel-jest@29.7.0(@babel/core@7.26.0))(jest@29.7.0(@types/node@22.8.4)(ts-node@10.9.2(@types/node@22.8.4)(typescript@5.6.3)))(typescript@5.6.3) ts-node: specifier: 10.9.2 version: 10.9.2(@types/node@22.8.4)(typescript@5.6.3) @@ -709,33 +746,6 @@ importers: specifier: 7.1.0 version: 7.1.0 - packages/test: - dependencies: - '@ai16z/adapter-sqlite': - specifier: workspace:* - version: link:../adapter-sqlite - '@ai16z/adapter-sqljs': - specifier: workspace:* - version: link:../adapter-sqljs - '@ai16z/adapter-supabase': - specifier: workspace:* - version: link:../adapter-supabase - '@ai16z/eliza': - specifier: workspace:* - version: link:../core - '@ai16z/plugin-bootstrap': - specifier: workspace:* - version: link:../plugin-bootstrap - '@ai16z/plugin-node': - specifier: workspace:* - version: link:../plugin-node - tsup: - specifier: ^8.3.5 - version: 8.3.5(jiti@1.21.6)(postcss@8.4.47)(tsx@4.19.2)(typescript@5.6.3)(yaml@2.6.0) - whatwg-url: - specifier: 7.1.0 - version: 7.1.0 - packages: '@ai-sdk/anthropic@0.0.53': @@ -24831,7 +24841,7 @@ snapshots: ts-interface-checker@0.1.13: {} - ts-jest@29.2.5(@babel/core@7.26.0)(@jest/transform@29.7.0)(@jest/types@29.6.3)(babel-jest@29.7.0(@babel/core@7.26.0))(esbuild@0.24.0)(jest@29.7.0(@types/node@22.8.4)(ts-node@10.9.2(@types/node@22.8.4)(typescript@5.6.3)))(typescript@5.6.3): + ts-jest@29.2.5(@babel/core@7.26.0)(@jest/transform@29.7.0)(@jest/types@29.6.3)(babel-jest@29.7.0(@babel/core@7.26.0))(jest@29.7.0(@types/node@22.8.4)(ts-node@10.9.2(@types/node@22.8.4)(typescript@5.6.3)))(typescript@5.6.3): dependencies: bs-logger: 0.2.6 ejs: 3.1.10 @@ -24849,7 +24859,6 @@ snapshots: '@jest/transform': 29.7.0 '@jest/types': 29.6.3 babel-jest: 29.7.0(@babel/core@7.26.0) - esbuild: 0.24.0 ts-mixer@6.0.4: {}