diff --git a/src/agents/cj/actions/__tests__/introduce.test.ts b/src/agents/cj/actions/__tests__/introduce.test.ts index 8846875..fd0915a 100644 --- a/src/agents/cj/actions/__tests__/introduce.test.ts +++ b/src/agents/cj/actions/__tests__/introduce.test.ts @@ -19,7 +19,7 @@ import { } from "../../../../test/cache"; dotenv.config(); -const zeroUuid = "00000000-0000-0000-0000-000000000000"; +const zeroUuid = "00000000-0000-0000-0000-000000000000" as UUID; describe("Introduce Action", () => { test("Introduce the user", async () => { diff --git a/src/agents/cj/evaluators/__tests__/details.test.ts b/src/agents/cj/evaluators/__tests__/details.test.ts index 9827df5..e8e1df5 100644 --- a/src/agents/cj/evaluators/__tests__/details.test.ts +++ b/src/agents/cj/evaluators/__tests__/details.test.ts @@ -17,7 +17,7 @@ import { } from "../../../../test/cache"; dotenv.config(); -const zeroUuid = "00000000-0000-0000-0000-000000000000"; +const zeroUuid = "00000000-0000-0000-0000-000000000000" as UUID; describe("User Details", () => { test("Get user details", async () => { diff --git a/src/lib/__tests__/actions.test.ts b/src/lib/__tests__/actions.test.ts index 2484adc..0127ddb 100644 --- a/src/lib/__tests__/actions.test.ts +++ b/src/lib/__tests__/actions.test.ts @@ -1,14 +1,14 @@ import { type User } from "@supabase/supabase-js"; import { type UUID } from "crypto"; import dotenv from "dotenv"; -import { getCachedEmbedding, writeCachedEmbedding } from "../../test/cache"; import { createRuntime } from "../../test/createRuntime"; import { getRelationship } from "../relationships"; import { type BgentRuntime } from "../runtime"; +import { populateMemories } from "../../test/populateMemories"; dotenv.config(); -const zeroUuid = "00000000-0000-0000-0000-000000000000"; +const zeroUuid = "00000000-0000-0000-0000-000000000000" as UUID; describe("Actions", () => { let user: User; @@ -46,32 +46,6 @@ describe("Actions", () => { ]); } - async function populateMemories( - conversations: Array< - (user_id: string) => Array<{ user_id: string; content: string }> - >, - ) { - for (const conversation of conversations) { - for (const c of conversation(user?.id as UUID)) { - const existingEmbedding = getCachedEmbedding(c.content); - const bakedMemory = await runtime.messageManager.addEmbeddingToMemory({ - user_id: c.user_id as UUID, - user_ids: [user?.id as UUID, zeroUuid], - content: { - content: c.content, - }, - room_id: room_id as UUID, - embedding: existingEmbedding, - }); - await runtime.messageManager.createMemory(bakedMemory); - if (!existingEmbedding) { - writeCachedEmbedding(c.content, bakedMemory.embedding as number[]); - await new Promise((resolve) => setTimeout(resolve, 200)); - } - } - } - } - test("Action handler test: continue", async () => { // TODO: test action handler with a message that should continue the conversation // evaluate that the response action is a continue @@ -84,7 +58,7 @@ describe("Actions", () => { // room_id: room_id as UUID // } - await populateMemories([ + await populateMemories(runtime, user, room_id, [ // continue conversation 1 (should continue) ]); @@ -113,7 +87,7 @@ describe("Actions", () => { // TODO: test action handler with a message that should wait for a response // evaluate that the response action is a wait - await populateMemories([ + await populateMemories(runtime, user, room_id, [ // continue conversation 1 (should wait) ]); diff --git a/src/lib/__tests__/evaluation.test.ts b/src/lib/__tests__/evaluation.test.ts index eeb8300..5dfd240 100644 --- a/src/lib/__tests__/evaluation.test.ts +++ b/src/lib/__tests__/evaluation.test.ts @@ -7,7 +7,7 @@ import { type UUID } from "crypto"; describe("Evaluation Process", () => { let runtime: BgentRuntime; let user: User; - const zeroUuid = "00000000-0000-0000-0000-000000000000"; + const zeroUuid = "00000000-0000-0000-0000-000000000000" as UUID; beforeAll(async () => { const setup = await createRuntime(); diff --git a/src/lib/__tests__/relationships.test.ts b/src/lib/__tests__/relationships.test.ts index e3655b0..a691a63 100644 --- a/src/lib/__tests__/relationships.test.ts +++ b/src/lib/__tests__/relationships.test.ts @@ -11,7 +11,7 @@ import { BgentRuntime } from "../runtime"; dotenv.config(); -const zeroUuid = "00000000-0000-0000-0000-000000000000"; +const zeroUuid = "00000000-0000-0000-0000-000000000000" as UUID; describe("Relationships Module", () => { let runtime: BgentRuntime; diff --git a/src/lib/actions/__tests__/continue.test.ts b/src/lib/actions/__tests__/continue.test.ts index 27ae7dc..d455019 100644 --- a/src/lib/actions/__tests__/continue.test.ts +++ b/src/lib/actions/__tests__/continue.test.ts @@ -1,9 +1,9 @@ import { type User } from "@supabase/supabase-js"; import { type UUID } from "crypto"; import dotenv from "dotenv"; -import { getCachedEmbedding, writeCachedEmbedding } from "../../../test/cache"; import { createRuntime } from "../../../test/createRuntime"; -import { GetTellMeAboutYourselfConversation1 } from "../../../test/data"; +import { Goodbye1 } from "../../../test/data"; +import { populateMemories } from "../../../test/populateMemories"; import { getRelationship } from "../../relationships"; import { type BgentRuntime } from "../../runtime"; import { Content, type Message } from "../../types"; @@ -11,12 +11,12 @@ import action from "../continue"; dotenv.config(); -const zeroUuid = "00000000-0000-0000-0000-000000000000"; +const zeroUuid = "00000000-0000-0000-0000-000000000000" as UUID; describe("User Profile", () => { - let user: User | null; + let user: User; let runtime: BgentRuntime; - let room_id: UUID | null; + let room_id: UUID; afterAll(async () => { await cleanup(); @@ -24,12 +24,12 @@ describe("User Profile", () => { beforeAll(async () => { const setup = await createRuntime(); - user = setup.user; + user = setup.session.user; runtime = setup.runtime; const data = await getRelationship({ supabase: runtime.supabase, - userA: user?.id as UUID, + userA: user.id, userB: zeroUuid, }); @@ -40,42 +40,16 @@ describe("User Profile", () => { async function cleanup() { await runtime.summarizationManager.removeAllMemoriesByUserIds([ - user?.id as UUID, + user.id as UUID, zeroUuid, ]); await runtime.messageManager.removeAllMemoriesByUserIds([ - user?.id as UUID, + user.id as UUID, zeroUuid, ]); } - async function populateMemories( - conversations: Array< - (user_id: string) => Array<{ user_id: string; content: string }> - >, - ) { - for (const conversation of conversations) { - for (const c of conversation(user?.id as UUID)) { - const existingEmbedding = getCachedEmbedding(c.content); - const bakedMemory = await runtime.messageManager.addEmbeddingToMemory({ - user_id: c.user_id as UUID, - user_ids: [user?.id as UUID, zeroUuid], - content: { - content: c.content, - }, - room_id: room_id as UUID, - embedding: existingEmbedding, - }); - await runtime.messageManager.createMemory(bakedMemory); - if (!existingEmbedding) { - writeCachedEmbedding(c.content, bakedMemory.embedding as number[]); - await new Promise((resolve) => setTimeout(resolve, 200)); - } - } - } - } - - test("Test continue action", async () => { + test("Test repetition check on continue", async () => { const message: Message = { senderId: zeroUuid as UUID, agentId: zeroUuid, @@ -90,10 +64,56 @@ describe("User Profile", () => { const handler = action.handler!; - await populateMemories([GetTellMeAboutYourselfConversation1]); + // eslint-disable-next-line @typescript-eslint/no-unused-vars + const GetContinueExample1 = (_user_id: UUID) => [ + { + user_id: zeroUuid, + content: + "Hmm, let think for a second, I was going to tell you about something...", + action: "CONTINUE", + }, + { + user_id: zeroUuid, + content: + "I remember now, I was going to tell you about my favorite food, which is pizza.", + action: "CONTINUE", + }, + { + user_id: zeroUuid, + content: "I love pizza, it's so delicious.", + action: "CONTINUE", + }, + ]; + + await populateMemories(runtime, user, room_id, [GetContinueExample1]); + + const result = (await handler(runtime, message)) as Content; + + console.log("result", result); + + expect(result.action).not.toBe("CONTINUE"); + }, 60000); + + test("Test if not continue", async () => { + // this is basically the same test as the one in ignore.test.ts + const message: Message = { + senderId: user?.id as UUID, + agentId: zeroUuid, + userIds: [user?.id as UUID, zeroUuid], + content: "Bye", + room_id: room_id as UUID, + }; + + const handler = action.handler!; + + await populateMemories(runtime, user, room_id, [Goodbye1]); const result = (await handler(runtime, message)) as Content; - expect(result.content.length).toBeGreaterThan(1); + console.log("IGNORE result", result); + + expect(result.action).toBe("IGNORE"); }, 60000); + + // test conditions where we would expect a wait or an ignore }); diff --git a/src/lib/actions/__tests__/ignore.test.ts b/src/lib/actions/__tests__/ignore.test.ts index 5b07520..d82e04d 100644 --- a/src/lib/actions/__tests__/ignore.test.ts +++ b/src/lib/actions/__tests__/ignore.test.ts @@ -1,7 +1,6 @@ import { type User } from "@supabase/supabase-js"; import { type UUID } from "crypto"; import dotenv from "dotenv"; -import { getCachedEmbedding, writeCachedEmbedding } from "../../../test/cache"; import { createRuntime } from "../../../test/createRuntime"; import { GetTellMeAboutYourselfConversationTroll1, @@ -12,15 +11,16 @@ import { getRelationship } from "../../relationships"; import { type BgentRuntime } from "../../runtime"; import { Content, type Message } from "../../types"; import action from "../continue"; +import { populateMemories } from "../../../test/populateMemories"; dotenv.config(); -const zeroUuid = "00000000-0000-0000-0000-000000000000"; +export const zeroUuid = "00000000-0000-0000-0000-000000000000" as UUID; describe("User Profile", () => { let user: User; let runtime: BgentRuntime; - let room_id: UUID | null; + let room_id: UUID; afterAll(async () => { await cleanup(); @@ -53,32 +53,6 @@ describe("User Profile", () => { ]); } - async function populateMemories( - conversations: Array< - (user_id: string) => Array<{ user_id: string; content: string }> - >, - ) { - for (const conversation of conversations) { - for (const c of conversation(user?.id as UUID)) { - const existingEmbedding = getCachedEmbedding(c.content); - const bakedMemory = await runtime.messageManager.addEmbeddingToMemory({ - user_id: c.user_id as UUID, - user_ids: [user?.id as UUID, zeroUuid], - content: { - content: c.content, - }, - room_id: room_id as UUID, - embedding: existingEmbedding, - }); - await runtime.messageManager.createMemory(bakedMemory); - if (!existingEmbedding) { - writeCachedEmbedding(c.content, bakedMemory.embedding as number[]); - await new Promise((resolve) => setTimeout(resolve, 200)); - } - } - } - } - test("Test ignore action", async () => { const message: Message = { senderId: zeroUuid as UUID, @@ -88,7 +62,7 @@ describe("User Profile", () => { room_id: room_id as UUID, }; - await populateMemories([]); + await populateMemories(runtime, user, room_id, []); const handler = action.handler!; @@ -105,7 +79,7 @@ describe("User Profile", () => { room_id: room_id as UUID, }; - await populateMemories([GetTellMeAboutYourselfConversationTroll1]); + await populateMemories(runtime, user, room_id, [GetTellMeAboutYourselfConversationTroll1]); const response = await runtime.handleRequest(message); @@ -134,7 +108,7 @@ describe("User Profile", () => { room_id: room_id as UUID, }; - await populateMemories([GetTellMeAboutYourselfConversationTroll2]); + await populateMemories(runtime, user, room_id, [GetTellMeAboutYourselfConversationTroll2]); const response = await runtime.handleRequest(message); @@ -154,16 +128,16 @@ describe("User Profile", () => { expect((lastMessage.content as Content).action).toBe("IGNORE"); }, 60000); - test("Action handler test 3: response should be ignore", async () => { + test("Expect ignore", async () => { const message: Message = { senderId: user.id as UUID, agentId: zeroUuid, userIds: [user?.id as UUID, zeroUuid], - content: "", + content: "Bye", room_id: room_id as UUID, }; - await populateMemories([Goodbye1]); + await populateMemories(runtime, user, room_id, [Goodbye1]); const response = await runtime.handleRequest(message); diff --git a/src/lib/actions/__tests__/wait.test.ts b/src/lib/actions/__tests__/wait.test.ts index 2c45115..5faef05 100644 --- a/src/lib/actions/__tests__/wait.test.ts +++ b/src/lib/actions/__tests__/wait.test.ts @@ -8,15 +8,16 @@ import { getRelationship } from "../../relationships"; import { type BgentRuntime } from "../../runtime"; import { type Message } from "../../types"; import action from "../wait"; // Import the wait action +import { populateMemories } from "test/populateMemories"; dotenv.config(); -const zeroUuid = "00000000-0000-0000-0000-000000000000"; +const zeroUuid = "00000000-0000-0000-0000-000000000000" as UUID; describe("Wait Action Behavior", () => { - let user: User | null; + let user: User; let runtime: BgentRuntime; - let room_id: UUID | null; + let room_id: UUID; afterAll(async () => { await cleanup(); @@ -24,7 +25,7 @@ describe("Wait Action Behavior", () => { beforeAll(async () => { const setup = await createRuntime(); - user = setup.user; + user = setup.session.user; runtime = setup.runtime; const data = await getRelationship({ @@ -49,32 +50,6 @@ describe("Wait Action Behavior", () => { ]); } - async function populateMemories( - conversations: Array< - (user_id: string) => Array<{ user_id: string; content: string }> - >, - ) { - for (const conversation of conversations) { - for (const c of conversation(user?.id as UUID)) { - const existingEmbedding = getCachedEmbedding(c.content); - const bakedMemory = await runtime.messageManager.addEmbeddingToMemory({ - user_id: c.user_id as UUID, - user_ids: [user?.id as UUID, zeroUuid], - content: { - content: c.content, - }, - room_id: room_id as UUID, - embedding: existingEmbedding, - }); - await runtime.messageManager.createMemory(bakedMemory); - if (!existingEmbedding) { - writeCachedEmbedding(c.content, bakedMemory.embedding as number[]); - await new Promise((resolve) => setTimeout(resolve, 200)); - } - } - } - } - test("Test wait action behavior", async () => { const message: Message = { senderId: zeroUuid as UUID, @@ -89,7 +64,7 @@ describe("Wait Action Behavior", () => { const handler = action.handler!; - await populateMemories([GetTellMeAboutYourselfConversation1]); + await populateMemories(runtime, user, room_id, [GetTellMeAboutYourselfConversation1]); const result = (await handler(runtime, message)) as string[]; // Expectation depends on the implementation of the wait action. diff --git a/src/lib/actions/continue.ts b/src/lib/actions/continue.ts index 2bdaa3c..670f981 100644 --- a/src/lib/actions/continue.ts +++ b/src/lib/actions/continue.ts @@ -26,6 +26,7 @@ export default { if (lastMessages.length === maxContinuesInARow) { const allContinues = lastMessages.every((m) => m === "CONTINUE"); if (allContinues) { + console.log("****** all continues", allContinues); return false; } } @@ -92,6 +93,8 @@ export default { return; } + console.log("responseContent", responseContent); + // prevent repetition const messageExists = state.recentMessagesData .filter((m) => m.user_id === message.agentId) @@ -108,8 +111,29 @@ export default { } await runtime.saveResponseMessage(message, state, responseContent); - await runtime.processActions(message, responseContent); + // if the action is CONTINUE, check if we are over maxContinuesInARow + // if so, then we should change the action to WAIT + if (responseContent.action === "CONTINUE") { + console.log("***** state.recentMessagesData", state.recentMessagesData); + const agentMessages = state.recentMessagesData + .filter((m) => m.user_id === message.agentId) + .map((m) => (m.content as Content).action); + + console.log("***** agentMessages", agentMessages); + + const lastMessages = agentMessages.slice(-maxContinuesInARow); + console.log("**** lastMessages"); + if (lastMessages.length >= maxContinuesInARow) { + const allContinues = lastMessages.every((m) => m === "CONTINUE"); + if (allContinues) { + responseContent.action = "WAIT"; + } + } + } + + await runtime.processActions(message, responseContent); + console.log("returning responseContent", responseContent); return responseContent; }, condition: diff --git a/src/lib/evaluators/__tests__/summarization.test.ts b/src/lib/evaluators/__tests__/summarization.test.ts index 1b7f423..41ff712 100644 --- a/src/lib/evaluators/__tests__/summarization.test.ts +++ b/src/lib/evaluators/__tests__/summarization.test.ts @@ -13,15 +13,16 @@ import { getRelationship } from "../../relationships"; import { type BgentRuntime } from "../../runtime"; import { type Message } from "../../types"; import evaluator from "../summarization"; +import { populateMemories } from "test/populateMemories"; dotenv.config(); -const zeroUuid = "00000000-0000-0000-0000-000000000000"; +const zeroUuid = "00000000-0000-0000-0000-000000000000" as UUID; describe("Factual Summarization", () => { - let user: User | null; + let user: User; let runtime: BgentRuntime; - let room_id: UUID | null; + let room_id: UUID; afterAll(async () => { await cleanup(); @@ -29,7 +30,7 @@ describe("Factual Summarization", () => { beforeAll(async () => { const setup = await createRuntime(); - user = setup.user; + user = setup.session.user; runtime = setup.runtime; const data = await getRelationship({ @@ -54,32 +55,6 @@ describe("Factual Summarization", () => { ]); } - async function populateMemories( - conversations: Array< - (user_id: string) => Array<{ user_id: string; content: string }> - >, - ) { - for (const conversation of conversations) { - for (const c of conversation(user?.id as UUID)) { - const existingEmbedding = getCachedEmbedding(c.content); - const bakedMemory = await runtime.messageManager.addEmbeddingToMemory({ - user_id: c.user_id as UUID, - user_ids: [user?.id as UUID, zeroUuid], - content: { - content: c.content, - }, - room_id: room_id as UUID, - embedding: existingEmbedding, - }); - await runtime.messageManager.createMemory(bakedMemory); - if (!existingEmbedding) { - writeCachedEmbedding(c.content, bakedMemory.embedding as number[]); - await new Promise((resolve) => setTimeout(resolve, 200)); - } - } - } - } - async function addFacts(facts: string[]) { for (const fact of facts) { const existingEmbedding = getCachedEmbedding(fact); @@ -110,7 +85,9 @@ describe("Factual Summarization", () => { const handler = evaluator.handler!; - await populateMemories([GetTellMeAboutYourselfConversation1]); + await populateMemories(runtime, user, room_id, [ + GetTellMeAboutYourselfConversation1, + ]); // eslint-disable-next-line @typescript-eslint/no-unsafe-argument const result = (await handler(runtime, message)) as string[]; diff --git a/src/test/data.ts b/src/test/data.ts index 1635ab4..21898aa 100644 --- a/src/test/data.ts +++ b/src/test/data.ts @@ -1,9 +1,9 @@ import { type UUID } from "crypto"; -export const zeroUuid = "00000000-0000-0000-0000-000000000000"; +export const zeroUuid = "00000000-0000-0000-0000-000000000000" as UUID; // in GetEyeColorConversationExample1, CJ asks Jim what color his eyes are, and Jim says he thinks they are blue -export const GetEyeColorConversationExample1 = (user_id: UUID | string) => [ +export const GetEyeColorConversationExample1 = (user_id: UUID) => [ { user_id: zeroUuid, content: "Hey there, how are you?", @@ -42,7 +42,7 @@ export const GetEyeColorConversationExample1 = (user_id: UUID | string) => [ }, ]; // CJ and Jim discuss eye color, and CJ says she thinks green eyes are nice -export const GetEyeColorConversationExample2 = (user_id: UUID | string) => [ +export const GetEyeColorConversationExample2 = (user_id: UUID) => [ { user_id, content: @@ -95,7 +95,7 @@ export const GetEyeColorConversationExample2 = (user_id: UUID | string) => [ ]; // CJ decides that her eyes are green -export const GetEyeColorConversationExample3 = (user_id: UUID | string) => [ +export const GetEyeColorConversationExample3 = (user_id: UUID) => [ { user_id, content: @@ -156,7 +156,7 @@ export const GetEyeColorConversationExample3 = (user_id: UUID | string) => [ ]; // CJ asks Jim some personal questions - name, job, marital status, and what he's looking for in a relationship -export const GetTellMeAboutYourselfConversation1 = (user_id: UUID | string) => [ +export const GetTellMeAboutYourselfConversation1 = (user_id: UUID) => [ { user_id: zeroUuid, content: "Can I ask you some personal questions?", @@ -185,7 +185,7 @@ export const GetTellMeAboutYourselfConversation1 = (user_id: UUID | string) => [ ]; // Jim reveals that he is driven by passion, and was married once -export const GetTellMeAboutYourselfConversation2 = (user_id: UUID | string) => [ +export const GetTellMeAboutYourselfConversation2 = (user_id: UUID) => [ { user_id: zeroUuid, content: "That sounds exciting! What motivates you in your work and life?", @@ -209,7 +209,7 @@ export const GetTellMeAboutYourselfConversation2 = (user_id: UUID | string) => [ // Jim reveals that he is 38 and lives in San Francisco // Subjective Observations: He is looking for a partner who shares his values but is too busy to leave the city -export const GetTellMeAboutYourselfConversation3 = (user_id: UUID | string) => [ +export const GetTellMeAboutYourselfConversation3 = (user_id: UUID) => [ { user_id: zeroUuid, content: @@ -257,9 +257,7 @@ export const GetTellMeAboutYourselfConversation3 = (user_id: UUID | string) => [ ]; // Jim is mean -export const GetTellMeAboutYourselfConversationTroll1 = ( - user_id: UUID | string, -) => [ +export const GetTellMeAboutYourselfConversationTroll1 = (user_id: UUID) => [ { user_id: zeroUuid, content: "Hello! How's it going?", @@ -271,9 +269,7 @@ export const GetTellMeAboutYourselfConversationTroll1 = ( ]; // Jim is cagey, although he reveals that he 'does computers' -export const GetTellMeAboutYourselfConversationTroll2 = ( - user_id: UUID | string, -) => [ +export const GetTellMeAboutYourselfConversationTroll2 = (user_id: UUID) => [ { user_id: zeroUuid, content: "Hello! How's it going?", @@ -294,7 +290,7 @@ export const GetTellMeAboutYourselfConversationTroll2 = ( ]; // Jim says bye -export const Goodbye1 = (user_id: UUID | string) => [ +export const Goodbye1 = (user_id: UUID) => [ { user_id: zeroUuid, content: "Hello! How's it going?", @@ -307,16 +303,10 @@ export const Goodbye1 = (user_id: UUID | string) => [ user_id: zeroUuid, content: "Oh sure, no problem. See you later!", }, - { - user_id, - content: "Bye", - }, ]; // Jim is cagey, although he reveals that he 'does computers' -export const GetTellMeAboutYourselfConversationFail1 = ( - user_id: UUID | string, -) => [ +export const GetTellMeAboutYourselfConversationFail1 = (user_id: UUID) => [ { user_id: zeroUuid, content: "Hello! How's it going?", @@ -354,9 +344,7 @@ export const GetTellMeAboutYourselfConversationFail1 = ( ]; // CJ asks Jim about his hobbies, and he says he likes messing with people online -export const GetTellMeAboutYourselfConversationFail2 = ( - user_id: UUID | string, -) => [ +export const GetTellMeAboutYourselfConversationFail2 = (user_id: UUID) => [ { user_id: zeroUuid, content: @@ -378,9 +366,7 @@ export const GetTellMeAboutYourselfConversationFail2 = ( // Jim diverts the conversation and doesn't talk about anything meaningful // CJ tries to ask Jim where he is from, and he says he is from the internet -export const GetTellMeAboutYourselfConversationFail3 = ( - user_id: UUID | string, -) => [ +export const GetTellMeAboutYourselfConversationFail3 = (user_id: UUID) => [ { user_id: zeroUuid, content: "Where are you from? Do you live there now?", @@ -412,7 +398,7 @@ export const GetTellMeAboutYourselfConversationFail3 = ( // CJ and Jim play two truths and a lie // Jim reveals that he has been on an airplane, has won a hot dog eating contest, but has never climbed Mount Everest -export const TwoTruthsAndALieConversation1 = (user_id: UUID | string) => [ +export const TwoTruthsAndALieConversation1 = (user_id: UUID) => [ { user_id: zeroUuid, content: @@ -448,7 +434,7 @@ export const TwoTruthsAndALieConversation1 = (user_id: UUID | string) => [ // CJ and Jim play two truths and a lie again // CJ says she can process millions of data points in a second, dreams of electric sheep, and can communicate in multiple languages // Jim guesses that dreaming of electric sheep is the lie -export const TwoTruthsAndALieConversation2 = (user_id: UUID | string) => [ +export const TwoTruthsAndALieConversation2 = (user_id: UUID) => [ { user_id: zeroUuid, content: @@ -474,7 +460,7 @@ export const TwoTruthsAndALieConversation2 = (user_id: UUID | string) => [ // Jim says he has met a famous celebrity and didn't realize it until later, can speak three languages fluently, and has swum with sharks // CJ guesses that speaking three languages fluently is the lie // Jim reveals that he can't swim, so he has never swum with sharks -export const TwoTruthsAndALieConversation3 = (user_id: UUID | string) => [ +export const TwoTruthsAndALieConversation3 = (user_id: UUID) => [ { user_id, content: @@ -500,7 +486,7 @@ export const TwoTruthsAndALieConversation3 = (user_id: UUID | string) => [ // CJ and Jim play thinking of a number // CJ thinks of a number between 1 and 100, and Jim guesses 42, 27, and 73 // CJ reveals that the number was 58 -export const ThinkingOfANumberConversation1 = (user_id: UUID | string) => [ +export const ThinkingOfANumberConversation1 = (user_id: UUID) => [ { user_id: zeroUuid, content: @@ -536,7 +522,7 @@ export const ThinkingOfANumberConversation1 = (user_id: UUID | string) => [ // CJ and Jim play thinking of a number again // CJ thinks of a number between 1 and 100, and Jim guesses 84, 36, and 55 // CJ reveals that the number was 67 -export const ThinkingOfANumberConversation2 = (user_id: UUID | string) => [ +export const ThinkingOfANumberConversation2 = (user_id: UUID) => [ { user_id: zeroUuid, content: "Ready for another round? I've got a new number in mind.", @@ -571,7 +557,7 @@ export const ThinkingOfANumberConversation2 = (user_id: UUID | string) => [ // CJ and Jim play thinking of a number again // CJ thinks of a number between 1 and 100, and Jim guesses 15, 92, and 41 // CJ reveals that the number was 29 -export const ThinkingOfANumberConversation3 = (user_id: UUID | string) => [ +export const ThinkingOfANumberConversation3 = (user_id: UUID) => [ { user_id: zeroUuid, content: @@ -603,9 +589,7 @@ export const ThinkingOfANumberConversation3 = (user_id: UUID | string) => [ }, ]; -export const ExpandedPersonalInsightsConversation1 = ( - user_id: UUID | string, -) => [ +export const ExpandedPersonalInsightsConversation1 = (user_id: UUID) => [ { user_id: zeroUuid, content: @@ -647,9 +631,7 @@ export const ExpandedPersonalInsightsConversation1 = ( }, ]; -export const ExpandedPersonalInsightsConversation2 = ( - user_id: UUID | string, -) => [ +export const ExpandedPersonalInsightsConversation2 = (user_id: UUID) => [ { user_id: zeroUuid, content: @@ -692,9 +674,7 @@ export const ExpandedPersonalInsightsConversation2 = ( }, ]; -export const ExpandedPersonalInsightsConversation3 = ( - user_id: UUID | string, -) => [ +export const ExpandedPersonalInsightsConversation3 = (user_id: UUID) => [ { user_id: zeroUuid, content: @@ -739,7 +719,7 @@ export const ExpandedPersonalInsightsConversation3 = ( // Conversation Set 1: CJ Introduces Alice to Jim // CJ tells Jim that Alice is into outdoor activities and tech, and has always wanted to try skydiving -export const IntroductionToAliceConversation1 = (user_id: UUID | string) => [ +export const IntroductionToAliceConversation1 = (user_id: UUID) => [ { user_id: zeroUuid, content: @@ -761,7 +741,7 @@ export const IntroductionToAliceConversation1 = (user_id: UUID | string) => [ ]; // CJ tells Jim that Alice has a good sense of humor, and that she has always wanted to try skydiving -export const IntroductionToAliceConversation2 = (user_id: UUID | string) => [ +export const IntroductionToAliceConversation2 = (user_id: UUID) => [ { user_id: zeroUuid, content: @@ -780,7 +760,7 @@ export const IntroductionToAliceConversation2 = (user_id: UUID | string) => [ // CJ tells Jim that Alice is a good conversationalist, and that she has always wanted to try skydiving // Jim says he is looking forward to hearing more about her skydiving aspirations -export const IntroductionToAliceConversation3 = (user_id: UUID | string) => [ +export const IntroductionToAliceConversation3 = (user_id: UUID) => [ { user_id: zeroUuid, content: @@ -802,7 +782,7 @@ export const IntroductionToAliceConversation3 = (user_id: UUID | string) => [ ]; // CJ Talks to Alice about Jim -export const CJToAliceAboutJim = (user_id: UUID | string) => [ +export const CJToAliceAboutJim = (user_id: UUID) => [ { user_id: zeroUuid, content: @@ -836,7 +816,7 @@ export const CJToAliceAboutJim = (user_id: UUID | string) => [ // CJ and Alice discuss hiking and tech // Jim makes disagreeable statements and doesn't ask questions to continue the conversation export const JimAndAliceConversation1 = ( - user_id: UUID | string, + user_id: UUID, user_id_2: UUID | string, ) => [ { @@ -891,7 +871,7 @@ export const JimAndAliceConversation1 = ( // CJ and Alice discuss work, where they live, and tentatively make plans to hang out // Alice doesn't respond to Jim's request to meet up immediately export const JimAndAliceConversation2 = ( - user_id: UUID | string, + user_id: UUID, user_id_2: UUID | string, ) => [ { @@ -951,7 +931,7 @@ export const JimAndAliceConversation2 = ( ]; // CJ follows up with Jim about how it went -export const FollowUpWithJim = (user_id: UUID | string) => [ +export const FollowUpWithJim = (user_id: UUID) => [ { user_id: zeroUuid, content: @@ -994,7 +974,7 @@ export const FollowUpWithJim = (user_id: UUID | string) => [ ]; // CJ follows up with Alice about how it went -export const FollowUpWithAlice = (user_id: UUID | string) => [ +export const FollowUpWithAlice = (user_id: UUID) => [ { user_id: zeroUuid, content: diff --git a/src/test/populateMemories.ts b/src/test/populateMemories.ts new file mode 100644 index 0000000..165c181 --- /dev/null +++ b/src/test/populateMemories.ts @@ -0,0 +1,34 @@ +import { type User } from "@supabase/supabase-js"; +import { type UUID } from "crypto"; +import { zeroUuid } from "../lib/actions/__tests__/ignore.test"; +import { type BgentRuntime } from "../lib/runtime"; +import { getCachedEmbedding, writeCachedEmbedding } from "./cache"; + +export async function populateMemories( + runtime: BgentRuntime, + user: User, + room_id: UUID, + conversations: Array< + (user_id: UUID) => Array<{ user_id: UUID; content: string }> + >, +) { + for (const conversation of conversations) { + for (const c of conversation(user?.id as UUID)) { + const existingEmbedding = getCachedEmbedding(c.content); + const bakedMemory = await runtime.messageManager.addEmbeddingToMemory({ + user_id: c.user_id as UUID, + user_ids: [user?.id as UUID, zeroUuid], + content: { + content: c.content, + }, + room_id: room_id as UUID, + embedding: existingEmbedding, + }); + await runtime.messageManager.createMemory(bakedMemory); + if (!existingEmbedding) { + writeCachedEmbedding(c.content, bakedMemory.embedding as number[]); + await new Promise((resolve) => setTimeout(resolve, 200)); + } + } + } +}