generated from langchain-ai/memory-template-js
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathagent.int.test.ts
64 lines (60 loc) · 2.29 KB
/
agent.int.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import { describe, it, expect } from "@jest/globals";
import { MemorySaver, InMemoryStore } from "@langchain/langgraph";
import { builder } from "../src/memory_agent/graph.js";
describe("Memory Graph", () => {
const conversations = [
["My name is Alice and I love pizza. Remember this."],
[
"Hi, I'm Bob and I enjoy playing tennis. Remember this.",
"Yes, I also have a pet dog named Max.",
"Max is a golden retriever and he's 5 years old. Please remember this too.",
],
[
"Hello, I'm Charlie. I work as a software engineer and I'm passionate about AI. Remember this.",
"I specialize in machine learning algorithms and I'm currently working on a project involving natural language processing.",
"My main goal is to improve sentiment analysis accuracy in multi-lingual texts. It's challenging but exciting.",
"We've made some progress using transformer models, but we're still working on handling context and idioms across languages.",
"Chinese and English have been the most challenging pair so far due to their vast differences in structure and cultural contexts.",
],
];
it.each(
conversations.map((conversation, index) => [
["short", "medium", "long"][index],
conversation,
]),
)(
"should store memories for %s conversation",
async (_, conversation) => {
const memStore = new InMemoryStore();
const graph = builder.compile({
store: memStore,
checkpointer: new MemorySaver(),
});
const userId = "test-user";
for (const content of conversation) {
await graph.invoke(
{
messages: [
{ role: "user", content: [{ type: "text", text: content }] },
],
},
{
configurable: {
userId,
thread_id: "thread",
model: "gpt-4o-mini",
systemPrompt: "You are a helpful assistant.",
},
},
);
}
const namespace = ["memories", userId];
const memories = await memStore.search(namespace);
expect(memories.length).toBeGreaterThan(0);
const badNamespace = ["memories", "wrong-user"];
const badMemories = await memStore.search(badNamespace);
expect(badMemories.length).toBe(0);
},
30000,
);
});