-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
293 additions
and
130 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,100 @@ | ||
describe("Wait", () => { | ||
// 1. prepare test before all and after all | ||
// 2. Load 3 conversations, 2 where the agent should continue, and 1 where the agent should not continue | ||
// 3. Run tests | ||
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 { getRelationship } from "../../relationships"; | ||
import { type BgentRuntime } from "../../runtime"; | ||
import { type Message } from "../../types"; | ||
import action from "../wait"; // Import the wait action | ||
|
||
dotenv.config(); | ||
|
||
const zeroUuid = "00000000-0000-0000-0000-000000000000"; | ||
|
||
describe("Wait Action Behavior", () => { | ||
let user: User | null; | ||
let runtime: BgentRuntime; | ||
let room_id: UUID | null; | ||
|
||
afterAll(async () => { | ||
await cleanup(); | ||
}); | ||
|
||
beforeAll(async () => { | ||
const setup = await createRuntime(process.env as Record<string, string>); | ||
user = setup.user; | ||
runtime = setup.runtime; | ||
|
||
const data = await getRelationship({ | ||
supabase: runtime.supabase, | ||
userA: user?.id as UUID, | ||
userB: zeroUuid, | ||
}); | ||
|
||
room_id = data?.room_id; | ||
|
||
await cleanup(); | ||
}); | ||
|
||
async function cleanup() { | ||
await runtime.reflectionManager.removeAllMemoriesByUserIds([ | ||
user?.id as UUID, | ||
zeroUuid, | ||
]); | ||
await runtime.messageManager.removeAllMemoriesByUserIds([ | ||
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 wait action behavior", async () => { | ||
const message: Message = { | ||
senderId: zeroUuid as UUID, | ||
agentId: zeroUuid, | ||
userIds: [user?.id as UUID, zeroUuid], | ||
content: { | ||
content: "Please wait a moment, I need to think about this...", | ||
action: "wait", | ||
}, | ||
room_id: room_id as UUID, | ||
}; | ||
|
||
const handler = action.handler!; | ||
|
||
await populateMemories([GetTellMeAboutYourselfConversation1]); | ||
|
||
const result = (await handler(runtime, message)) as string[]; | ||
// Expectation depends on the implementation of the wait action. | ||
// For instance, it might be that there's no immediate output, | ||
// or the output indicates waiting, so adjust the expectation accordingly. | ||
expect(result).toEqual(expect.anything()); // Update this line based on the expected behavior of the wait action | ||
}, 60000); | ||
}); |
Oops, something went wrong.