-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Expand file tree
/
Copy pathscenario-thread-id.mjs
More file actions
67 lines (60 loc) · 1.73 KB
/
scenario-thread-id.mjs
File metadata and controls
67 lines (60 loc) · 1.73 KB
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
65
66
67
import { END, MessagesAnnotation, START, StateGraph } from '@langchain/langgraph';
import * as Sentry from '@sentry/node';
async function run() {
await Sentry.startSpan({ op: 'function', name: 'langgraph-thread-id-test' }, async () => {
// Define a simple mock LLM function
const mockLlm = () => {
return {
messages: [
{
role: 'assistant',
content: 'Mock LLM response',
response_metadata: {
model_name: 'mock-model',
finish_reason: 'stop',
tokenUsage: {
promptTokens: 20,
completionTokens: 10,
totalTokens: 30,
},
},
},
],
};
};
// Create and compile the graph
const graph = new StateGraph(MessagesAnnotation)
.addNode('agent', mockLlm)
.addEdge(START, 'agent')
.addEdge('agent', END)
.compile({ name: 'thread_test_agent' });
// Test 1: Invoke with thread_id in config
await graph.invoke(
{
messages: [{ role: 'user', content: 'Hello with thread ID' }],
},
{
configurable: {
thread_id: 'thread_abc123_session_1',
},
},
);
// Test 2: Invoke with different thread_id (simulating different conversation)
await graph.invoke(
{
messages: [{ role: 'user', content: 'Different conversation' }],
},
{
configurable: {
thread_id: 'thread_xyz789_session_2',
},
},
);
// Test 3: Invoke without thread_id (should not have gen_ai.conversation.id)
await graph.invoke({
messages: [{ role: 'user', content: 'No thread ID here' }],
});
});
await Sentry.flush(2000);
}
run();