illuma-agents 1.0.36 → 1.0.38

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (128) hide show
  1. package/dist/cjs/agents/AgentContext.cjs +69 -14
  2. package/dist/cjs/agents/AgentContext.cjs.map +1 -1
  3. package/dist/cjs/common/enum.cjs +3 -1
  4. package/dist/cjs/common/enum.cjs.map +1 -1
  5. package/dist/cjs/graphs/Graph.cjs +50 -8
  6. package/dist/cjs/graphs/Graph.cjs.map +1 -1
  7. package/dist/cjs/graphs/MultiAgentGraph.cjs +277 -11
  8. package/dist/cjs/graphs/MultiAgentGraph.cjs.map +1 -1
  9. package/dist/cjs/llm/bedrock/index.cjs +128 -61
  10. package/dist/cjs/llm/bedrock/index.cjs.map +1 -1
  11. package/dist/cjs/main.cjs +16 -7
  12. package/dist/cjs/main.cjs.map +1 -1
  13. package/dist/cjs/messages/cache.cjs +1 -0
  14. package/dist/cjs/messages/cache.cjs.map +1 -1
  15. package/dist/cjs/messages/core.cjs +1 -1
  16. package/dist/cjs/messages/core.cjs.map +1 -1
  17. package/dist/cjs/messages/tools.cjs +2 -2
  18. package/dist/cjs/messages/tools.cjs.map +1 -1
  19. package/dist/cjs/stream.cjs +4 -2
  20. package/dist/cjs/stream.cjs.map +1 -1
  21. package/dist/cjs/tools/BrowserTools.cjs +27 -3
  22. package/dist/cjs/tools/BrowserTools.cjs.map +1 -1
  23. package/dist/cjs/tools/CodeExecutor.cjs +22 -21
  24. package/dist/cjs/tools/CodeExecutor.cjs.map +1 -1
  25. package/dist/cjs/tools/ProgrammaticToolCalling.cjs +14 -11
  26. package/dist/cjs/tools/ProgrammaticToolCalling.cjs.map +1 -1
  27. package/dist/cjs/tools/ToolNode.cjs +101 -2
  28. package/dist/cjs/tools/ToolNode.cjs.map +1 -1
  29. package/dist/cjs/tools/ToolSearch.cjs +862 -0
  30. package/dist/cjs/tools/ToolSearch.cjs.map +1 -0
  31. package/dist/esm/agents/AgentContext.mjs +69 -14
  32. package/dist/esm/agents/AgentContext.mjs.map +1 -1
  33. package/dist/esm/common/enum.mjs +3 -1
  34. package/dist/esm/common/enum.mjs.map +1 -1
  35. package/dist/esm/graphs/Graph.mjs +51 -9
  36. package/dist/esm/graphs/Graph.mjs.map +1 -1
  37. package/dist/esm/graphs/MultiAgentGraph.mjs +278 -12
  38. package/dist/esm/graphs/MultiAgentGraph.mjs.map +1 -1
  39. package/dist/esm/llm/bedrock/index.mjs +127 -60
  40. package/dist/esm/llm/bedrock/index.mjs.map +1 -1
  41. package/dist/esm/main.mjs +1 -1
  42. package/dist/esm/messages/cache.mjs +1 -0
  43. package/dist/esm/messages/cache.mjs.map +1 -1
  44. package/dist/esm/messages/core.mjs +1 -1
  45. package/dist/esm/messages/core.mjs.map +1 -1
  46. package/dist/esm/messages/tools.mjs +2 -2
  47. package/dist/esm/messages/tools.mjs.map +1 -1
  48. package/dist/esm/stream.mjs +4 -2
  49. package/dist/esm/stream.mjs.map +1 -1
  50. package/dist/esm/tools/BrowserTools.mjs +27 -3
  51. package/dist/esm/tools/BrowserTools.mjs.map +1 -1
  52. package/dist/esm/tools/CodeExecutor.mjs +22 -21
  53. package/dist/esm/tools/CodeExecutor.mjs.map +1 -1
  54. package/dist/esm/tools/ProgrammaticToolCalling.mjs +14 -11
  55. package/dist/esm/tools/ProgrammaticToolCalling.mjs.map +1 -1
  56. package/dist/esm/tools/ToolNode.mjs +102 -3
  57. package/dist/esm/tools/ToolNode.mjs.map +1 -1
  58. package/dist/esm/tools/ToolSearch.mjs +827 -0
  59. package/dist/esm/tools/ToolSearch.mjs.map +1 -0
  60. package/dist/types/agents/AgentContext.d.ts +33 -1
  61. package/dist/types/common/enum.d.ts +4 -2
  62. package/dist/types/graphs/Graph.d.ts +6 -0
  63. package/dist/types/graphs/MultiAgentGraph.d.ts +16 -0
  64. package/dist/types/index.d.ts +1 -1
  65. package/dist/types/llm/bedrock/index.d.ts +89 -11
  66. package/dist/types/llm/bedrock/types.d.ts +27 -0
  67. package/dist/types/llm/bedrock/utils/index.d.ts +5 -0
  68. package/dist/types/llm/bedrock/utils/message_inputs.d.ts +31 -0
  69. package/dist/types/llm/bedrock/utils/message_outputs.d.ts +33 -0
  70. package/dist/types/tools/BrowserTools.d.ts +2 -0
  71. package/dist/types/tools/CodeExecutor.d.ts +0 -3
  72. package/dist/types/tools/ProgrammaticToolCalling.d.ts +0 -3
  73. package/dist/types/tools/ToolNode.d.ts +3 -1
  74. package/dist/types/tools/ToolSearch.d.ts +148 -0
  75. package/dist/types/types/graph.d.ts +2 -0
  76. package/dist/types/types/llm.d.ts +3 -1
  77. package/dist/types/types/tools.d.ts +42 -2
  78. package/package.json +12 -5
  79. package/src/agents/AgentContext.ts +88 -16
  80. package/src/common/enum.ts +3 -1
  81. package/src/graphs/Graph.ts +64 -13
  82. package/src/graphs/MultiAgentGraph.ts +350 -13
  83. package/src/index.ts +1 -1
  84. package/src/llm/bedrock/index.ts +221 -99
  85. package/src/llm/bedrock/llm.spec.ts +616 -0
  86. package/src/llm/bedrock/types.ts +51 -0
  87. package/src/llm/bedrock/utils/index.ts +18 -0
  88. package/src/llm/bedrock/utils/message_inputs.ts +563 -0
  89. package/src/llm/bedrock/utils/message_outputs.ts +310 -0
  90. package/src/messages/__tests__/tools.test.ts +21 -21
  91. package/src/messages/cache.test.ts +259 -0
  92. package/src/messages/cache.ts +104 -1
  93. package/src/messages/core.ts +1 -1
  94. package/src/messages/tools.ts +2 -2
  95. package/src/scripts/caching.ts +27 -19
  96. package/src/scripts/code_exec_files.ts +58 -15
  97. package/src/scripts/code_exec_multi_session.ts +241 -0
  98. package/src/scripts/code_exec_session.ts +282 -0
  99. package/src/scripts/multi-agent-conditional.ts +1 -0
  100. package/src/scripts/multi-agent-supervisor.ts +1 -0
  101. package/src/scripts/programmatic_exec_agent.ts +4 -4
  102. package/src/scripts/test-handoff-preamble.ts +277 -0
  103. package/src/scripts/test-parallel-handoffs.ts +291 -0
  104. package/src/scripts/test-tools-before-handoff.ts +8 -4
  105. package/src/scripts/test_code_api.ts +361 -0
  106. package/src/scripts/thinking-bedrock.ts +159 -0
  107. package/src/scripts/thinking.ts +39 -18
  108. package/src/scripts/{tool_search_regex.ts → tool_search.ts} +5 -5
  109. package/src/scripts/tools.ts +7 -3
  110. package/src/stream.ts +4 -2
  111. package/src/tools/BrowserTools.ts +68 -14
  112. package/src/tools/CodeExecutor.ts +26 -23
  113. package/src/tools/ProgrammaticToolCalling.ts +18 -14
  114. package/src/tools/ToolNode.ts +114 -1
  115. package/src/tools/ToolSearch.ts +1041 -0
  116. package/src/tools/__tests__/ProgrammaticToolCalling.test.ts +0 -2
  117. package/src/tools/__tests__/{ToolSearchRegex.integration.test.ts → ToolSearch.integration.test.ts} +6 -6
  118. package/src/tools/__tests__/ToolSearch.test.ts +1003 -0
  119. package/src/types/graph.ts +2 -0
  120. package/src/types/llm.ts +3 -1
  121. package/src/types/tools.ts +51 -2
  122. package/dist/cjs/tools/ToolSearchRegex.cjs +0 -455
  123. package/dist/cjs/tools/ToolSearchRegex.cjs.map +0 -1
  124. package/dist/esm/tools/ToolSearchRegex.mjs +0 -448
  125. package/dist/esm/tools/ToolSearchRegex.mjs.map +0 -1
  126. package/dist/types/tools/ToolSearchRegex.d.ts +0 -80
  127. package/src/tools/ToolSearchRegex.ts +0 -535
  128. package/src/tools/__tests__/ToolSearchRegex.test.ts +0 -232
@@ -0,0 +1,241 @@
1
+ // src/scripts/code_exec_multi_session.ts
2
+ /**
3
+ * Tests multi-session file tracking for code execution.
4
+ * Verifies that:
5
+ * 1. Files from multiple executions are accumulated
6
+ * 2. Each file tracks its source session_id
7
+ * 3. Edited/recreated files replace older versions (latest preferred)
8
+ *
9
+ * Run with: npm run code_exec_multi_session
10
+ */
11
+ import { config } from 'dotenv';
12
+ config();
13
+ import { HumanMessage, BaseMessage } from '@langchain/core/messages';
14
+ import type { RunnableConfig } from '@langchain/core/runnables';
15
+ import type * as t from '@/types';
16
+ import { ChatModelStreamHandler } from '@/stream';
17
+ import { ToolEndHandler, ModelEndHandler } from '@/events';
18
+ import { getLLMConfig } from '@/utils/llmConfig';
19
+ import { getArgs } from '@/scripts/args';
20
+ import { Constants, GraphEvents } from '@/common';
21
+ import { Run } from '@/run';
22
+ import { createCodeExecutionTool } from '@/tools/CodeExecutor';
23
+
24
+ const conversationHistory: BaseMessage[] = [];
25
+
26
+ /**
27
+ * Prints session context from the graph
28
+ */
29
+ function printSessionContext(run: Run<t.IState>, label: string): void {
30
+ const graph = run.Graph;
31
+ if (!graph) {
32
+ console.log(`\n[${label}] No graph available`);
33
+ return;
34
+ }
35
+
36
+ const session = graph.sessions.get(Constants.EXECUTE_CODE) as
37
+ | t.CodeSessionContext
38
+ | undefined;
39
+
40
+ console.log(`\n========== ${label} ==========`);
41
+ if (!session) {
42
+ console.log(' No session context stored yet');
43
+ return;
44
+ }
45
+
46
+ console.log(` Latest session_id: ${session.session_id}`);
47
+ console.log(` Files tracked: ${session.files.length}`);
48
+ for (const file of session.files) {
49
+ console.log(` - ${file.name} (session: ${file.session_id})`);
50
+ }
51
+ }
52
+
53
+ async function testMultiSessionFiles(): Promise<void> {
54
+ const { provider } = await getArgs();
55
+
56
+ const customHandlers = {
57
+ [GraphEvents.TOOL_END]: new ToolEndHandler(),
58
+ [GraphEvents.CHAT_MODEL_END]: new ModelEndHandler(),
59
+ [GraphEvents.CHAT_MODEL_STREAM]: new ChatModelStreamHandler(),
60
+ };
61
+
62
+ const llmConfig = getLLMConfig(provider);
63
+
64
+ const run = await Run.create<t.IState>({
65
+ runId: 'multi-session-test',
66
+ graphConfig: {
67
+ type: 'standard',
68
+ llmConfig,
69
+ tools: [createCodeExecutionTool()],
70
+ instructions: `You are a coding assistant. Execute code exactly as requested.
71
+ When asked to create files, use Python and save to /mnt/data/.
72
+ When reading files, print their contents.
73
+ Be concise in responses.`,
74
+ },
75
+ returnContent: true,
76
+ customHandlers,
77
+ });
78
+
79
+ const streamConfig: Partial<RunnableConfig> & {
80
+ version: 'v1' | 'v2';
81
+ streamMode: string;
82
+ } = {
83
+ configurable: {
84
+ provider,
85
+ thread_id: 'multi-session-test',
86
+ },
87
+ streamMode: 'values',
88
+ version: 'v2' as const,
89
+ };
90
+
91
+ // ========== TEST 1: Create first file ==========
92
+ console.log('\n\n' + '='.repeat(60));
93
+ console.log('TEST 1: Create first file (file_a.txt)');
94
+ console.log('='.repeat(60));
95
+
96
+ conversationHistory.push(
97
+ new HumanMessage(`
98
+ Create a file called "file_a.txt" with the content:
99
+ "This is file A, version 1"
100
+ Print confirmation when done.
101
+ `)
102
+ );
103
+
104
+ await run.processStream({ messages: conversationHistory }, streamConfig);
105
+ const messages1 = run.getRunMessages();
106
+ if (messages1) conversationHistory.push(...messages1);
107
+
108
+ printSessionContext(run, 'After Test 1');
109
+
110
+ // ========== TEST 2: Create second file (different session) ==========
111
+ console.log('\n\n' + '='.repeat(60));
112
+ console.log('TEST 2: Create second file (file_b.txt)');
113
+ console.log('Expecting: Both file_a.txt and file_b.txt tracked');
114
+ console.log('='.repeat(60));
115
+
116
+ conversationHistory.push(
117
+ new HumanMessage(`
118
+ Create a NEW file called "file_b.txt" with the content:
119
+ "This is file B"
120
+ Print confirmation when done.
121
+ `)
122
+ );
123
+
124
+ await run.processStream({ messages: conversationHistory }, streamConfig);
125
+ const messages2 = run.getRunMessages();
126
+ if (messages2) conversationHistory.push(...messages2);
127
+
128
+ printSessionContext(run, 'After Test 2');
129
+
130
+ // ========== TEST 3: Read BOTH files (verifies accumulation) ==========
131
+ console.log('\n\n' + '='.repeat(60));
132
+ console.log('TEST 3: Read BOTH files from previous executions');
133
+ console.log('This verifies multi-session file accumulation works');
134
+ console.log('='.repeat(60));
135
+
136
+ conversationHistory.push(
137
+ new HumanMessage(`
138
+ Read and print the contents of BOTH files:
139
+ 1. file_a.txt
140
+ 2. file_b.txt
141
+
142
+ Show me what's in each file.
143
+ `)
144
+ );
145
+
146
+ await run.processStream({ messages: conversationHistory }, streamConfig);
147
+ const messages3 = run.getRunMessages();
148
+ if (messages3) conversationHistory.push(...messages3);
149
+
150
+ printSessionContext(run, 'After Test 3');
151
+
152
+ // ========== TEST 4: Edit file_a.txt (verifies latest-wins) ==========
153
+ console.log('\n\n' + '='.repeat(60));
154
+ console.log('TEST 4: Edit file_a.txt (create new version)');
155
+ console.log('Expecting: Old file_a.txt replaced with new version');
156
+ console.log('='.repeat(60));
157
+
158
+ conversationHistory.push(
159
+ new HumanMessage(`
160
+ Create an UPDATED version of "file_a.txt" with the content:
161
+ "This is file A, version 2 - UPDATED"
162
+ Print confirmation when done.
163
+ `)
164
+ );
165
+
166
+ await run.processStream({ messages: conversationHistory }, streamConfig);
167
+ const messages4 = run.getRunMessages();
168
+ if (messages4) conversationHistory.push(...messages4);
169
+
170
+ printSessionContext(run, 'After Test 4');
171
+
172
+ // ========== TEST 5: Read file_a.txt (verifies latest version) ==========
173
+ console.log('\n\n' + '='.repeat(60));
174
+ console.log('TEST 5: Read file_a.txt to verify it has the UPDATED content');
175
+ console.log('Expected: "version 2 - UPDATED" NOT "version 1"');
176
+ console.log('='.repeat(60));
177
+
178
+ conversationHistory.push(
179
+ new HumanMessage(`
180
+ Read and print the contents of file_a.txt.
181
+ Tell me what version it shows.
182
+ `)
183
+ );
184
+
185
+ await run.processStream({ messages: conversationHistory }, streamConfig);
186
+ const messages5 = run.getRunMessages();
187
+ if (messages5) conversationHistory.push(...messages5);
188
+
189
+ printSessionContext(run, 'Final Session State');
190
+
191
+ // ========== SUMMARY ==========
192
+ console.log('\n\n' + '='.repeat(60));
193
+ console.log('TEST SUMMARY');
194
+ console.log('='.repeat(60));
195
+
196
+ const finalSession = run.Graph?.sessions.get(Constants.EXECUTE_CODE) as
197
+ | t.CodeSessionContext
198
+ | undefined;
199
+
200
+ if (finalSession) {
201
+ const uniqueSessionIds = new Set(
202
+ finalSession.files.map((f) => f.session_id)
203
+ );
204
+ console.log(`\nTotal files tracked: ${finalSession.files.length}`);
205
+ console.log(`Unique session_ids: ${uniqueSessionIds.size}`);
206
+ console.log('\nFiles:');
207
+ for (const file of finalSession.files) {
208
+ console.log(
209
+ ` - ${file.name} (session: ${file.session_id?.slice(0, 20)}...)`
210
+ );
211
+ }
212
+
213
+ // Verify expectations
214
+ const fileACount = finalSession.files.filter(
215
+ (f) => f.name === 'file_a.txt'
216
+ ).length;
217
+ const fileBCount = finalSession.files.filter(
218
+ (f) => f.name === 'file_b.txt'
219
+ ).length;
220
+
221
+ console.log('\n✓ Checks:');
222
+ console.log(` file_a.txt count: ${fileACount} (expected: 1, latest wins)`);
223
+ console.log(` file_b.txt count: ${fileBCount} (expected: 1)`);
224
+
225
+ if (fileACount === 1 && fileBCount === 1) {
226
+ console.log('\n✅ All tests passed! Multi-session tracking works.');
227
+ } else {
228
+ console.log('\n❌ Test failed - unexpected file counts');
229
+ }
230
+ }
231
+ }
232
+
233
+ process.on('unhandledRejection', (reason, promise) => {
234
+ console.error('Unhandled Rejection at:', promise, 'reason:', reason);
235
+ process.exit(1);
236
+ });
237
+
238
+ testMultiSessionFiles().catch((err) => {
239
+ console.error('Test failed:', err);
240
+ process.exit(1);
241
+ });
@@ -0,0 +1,282 @@
1
+ // src/scripts/code_exec_session.ts
2
+ /**
3
+ * Test script for automatic session tracking in code execution tools.
4
+ *
5
+ * This tests the automatic session_id injection feature where:
6
+ * 1. First code execution generates files and returns a session_id
7
+ * 2. Session context is stored in Graph.sessions
8
+ * 3. Subsequent code executions automatically have access to previous files
9
+ * without the LLM needing to explicitly pass session_id
10
+ *
11
+ * Run with: npm run code_exec_session
12
+ */
13
+ import { config } from 'dotenv';
14
+ config();
15
+ import { HumanMessage, BaseMessage } from '@langchain/core/messages';
16
+ import type { RunnableConfig } from '@langchain/core/runnables';
17
+ import type * as t from '@/types';
18
+ import { ChatModelStreamHandler, createContentAggregator } from '@/stream';
19
+ import {
20
+ ToolEndHandler,
21
+ ModelEndHandler,
22
+ createMetadataAggregator,
23
+ } from '@/events';
24
+ import { getLLMConfig } from '@/utils/llmConfig';
25
+ import { getArgs } from '@/scripts/args';
26
+ import { Constants, GraphEvents } from '@/common';
27
+ import { Run } from '@/run';
28
+ import { createCodeExecutionTool } from '@/tools/CodeExecutor';
29
+
30
+ const conversationHistory: BaseMessage[] = [];
31
+
32
+ /**
33
+ * Prints a formatted section header for test output
34
+ */
35
+ function printSection(title: string): void {
36
+ console.log('\n' + '='.repeat(60));
37
+ console.log(` ${title}`);
38
+ console.log('='.repeat(60) + '\n');
39
+ }
40
+
41
+ /**
42
+ * Prints session context from the graph for debugging
43
+ */
44
+ function printSessionContext(run: Run<t.IState>): void {
45
+ const graph = run.Graph;
46
+ if (!graph) {
47
+ console.log('[Session] No graph available');
48
+ return;
49
+ }
50
+
51
+ const session = graph.sessions.get(Constants.EXECUTE_CODE) as
52
+ | t.CodeSessionContext
53
+ | undefined;
54
+
55
+ if (!session) {
56
+ console.log('[Session] No session context stored yet');
57
+ return;
58
+ }
59
+
60
+ console.log('[Session] Current session context:');
61
+ console.log(` - session_id: ${session.session_id}`);
62
+ console.log(` - files: ${JSON.stringify(session.files, null, 2)}`);
63
+ console.log(
64
+ ` - lastUpdated: ${new Date(session.lastUpdated).toISOString()}`
65
+ );
66
+ }
67
+
68
+ async function testAutomaticSessionTracking(): Promise<void> {
69
+ const { userName, location, provider, currentDate } = await getArgs();
70
+ const { contentParts, aggregateContent } = createContentAggregator();
71
+
72
+ const customHandlers = {
73
+ [GraphEvents.TOOL_END]: new ToolEndHandler(),
74
+ [GraphEvents.CHAT_MODEL_END]: new ModelEndHandler(),
75
+ [GraphEvents.CHAT_MODEL_STREAM]: new ChatModelStreamHandler(),
76
+ [GraphEvents.ON_RUN_STEP_COMPLETED]: {
77
+ handle: (
78
+ event: GraphEvents.ON_RUN_STEP_COMPLETED,
79
+ data: t.StreamEventData
80
+ ): void => {
81
+ console.log('====== ON_RUN_STEP_COMPLETED ======');
82
+ console.dir(data, { depth: null });
83
+ aggregateContent({
84
+ event,
85
+ data: data as unknown as { result: t.ToolEndEvent },
86
+ });
87
+ },
88
+ },
89
+ [GraphEvents.ON_RUN_STEP]: {
90
+ handle: (
91
+ event: GraphEvents.ON_RUN_STEP,
92
+ data: t.StreamEventData
93
+ ): void => {
94
+ console.log('====== ON_RUN_STEP ======');
95
+ console.dir(data, { depth: null });
96
+ aggregateContent({ event, data: data as t.RunStep });
97
+ },
98
+ },
99
+ [GraphEvents.ON_RUN_STEP_DELTA]: {
100
+ handle: (
101
+ event: GraphEvents.ON_RUN_STEP_DELTA,
102
+ data: t.StreamEventData
103
+ ): void => {
104
+ aggregateContent({ event, data: data as t.RunStepDeltaEvent });
105
+ },
106
+ },
107
+ [GraphEvents.ON_MESSAGE_DELTA]: {
108
+ handle: (
109
+ event: GraphEvents.ON_MESSAGE_DELTA,
110
+ data: t.StreamEventData
111
+ ): void => {
112
+ aggregateContent({ event, data: data as t.MessageDeltaEvent });
113
+ },
114
+ },
115
+ [GraphEvents.TOOL_START]: {
116
+ handle: (
117
+ _event: string,
118
+ data: t.StreamEventData,
119
+ _metadata?: Record<string, unknown>
120
+ ): void => {
121
+ console.log('====== TOOL_START ======');
122
+ console.dir(data, { depth: null });
123
+ },
124
+ },
125
+ };
126
+
127
+ const llmConfig = getLLMConfig(provider);
128
+
129
+ const run = await Run.create<t.IState>({
130
+ runId: 'session-tracking-test-1',
131
+ graphConfig: {
132
+ type: 'standard',
133
+ llmConfig,
134
+ tools: [createCodeExecutionTool()],
135
+ instructions: `You are an AI assistant testing automatic file persistence.
136
+ When writing Python code:
137
+ - Use print() for all outputs
138
+ - Files from previous executions are automatically available in /mnt/data/
139
+ - Files are READ-ONLY; write modifications to NEW filenames
140
+ - IMPORTANT: Do NOT include session_id in your tool calls - it's handled automatically.`,
141
+ additional_instructions: `User: ${userName}, Location: ${location}, Date: ${currentDate}.`,
142
+ },
143
+ returnContent: true,
144
+ customHandlers,
145
+ });
146
+
147
+ const streamConfig: Partial<RunnableConfig> & {
148
+ version: 'v1' | 'v2';
149
+ run_id?: string;
150
+ streamMode: string;
151
+ } = {
152
+ configurable: {
153
+ provider,
154
+ thread_id: 'session-tracking-test',
155
+ },
156
+ streamMode: 'values',
157
+ version: 'v2' as const,
158
+ };
159
+
160
+ // =========================================================================
161
+ // Test 1: Create initial file (establishes session)
162
+ // =========================================================================
163
+ printSection('Test 1: Create Initial File');
164
+ console.log(
165
+ 'This test creates a file, which should establish a session context.\n'
166
+ );
167
+
168
+ const userMessage1 = `
169
+ Create a Python file that writes a simple JSON config file named "app_config.json" with the following content:
170
+ {
171
+ "app_name": "TestApp",
172
+ "version": "1.0.0",
173
+ "debug": true
174
+ }
175
+
176
+ After writing, print the contents to confirm it was created correctly.
177
+ `;
178
+
179
+ conversationHistory.push(new HumanMessage(userMessage1));
180
+ await run.processStream({ messages: conversationHistory }, streamConfig);
181
+
182
+ const finalMessages1 = run.getRunMessages();
183
+ if (finalMessages1) {
184
+ conversationHistory.push(...finalMessages1);
185
+ }
186
+
187
+ printSection('Session Context After Test 1');
188
+ printSessionContext(run);
189
+
190
+ // =========================================================================
191
+ // Test 2: Access previously created file (uses automatic session injection)
192
+ // =========================================================================
193
+ printSection('Test 2: Access Previous File (Automatic Session)');
194
+ console.log('This test reads the file created in Test 1.');
195
+ console.log(
196
+ 'The LLM does NOT need to provide session_id - it should be injected automatically.\n'
197
+ );
198
+
199
+ const userMessage2 = `
200
+ Now read the app_config.json file that was just created and:
201
+ 1. Print its contents
202
+ 2. Confirm the version is "1.0.0"
203
+
204
+ Note: You should be able to access this file from the previous execution automatically.
205
+ `;
206
+
207
+ conversationHistory.push(new HumanMessage(userMessage2));
208
+ await run.processStream({ messages: conversationHistory }, streamConfig);
209
+
210
+ const finalMessages2 = run.getRunMessages();
211
+ if (finalMessages2) {
212
+ conversationHistory.push(...finalMessages2);
213
+ }
214
+
215
+ printSection('Session Context After Test 2');
216
+ printSessionContext(run);
217
+
218
+ // =========================================================================
219
+ // Test 3: Modify file (write to new filename)
220
+ // =========================================================================
221
+ printSection('Test 3: Modify File (Write to New Filename)');
222
+ console.log(
223
+ 'This test modifies the config by reading the old file and writing a new one.\n'
224
+ );
225
+
226
+ const userMessage3 = `
227
+ Read app_config.json, update the version to "2.0.0" and debug to false,
228
+ then save it as "app_config_v2.json". Print both the old and new contents.
229
+ `;
230
+
231
+ conversationHistory.push(new HumanMessage(userMessage3));
232
+ await run.processStream({ messages: conversationHistory }, streamConfig);
233
+
234
+ const finalMessages3 = run.getRunMessages();
235
+ if (finalMessages3) {
236
+ conversationHistory.push(...finalMessages3);
237
+ }
238
+
239
+ printSection('Session Context After Test 3');
240
+ printSessionContext(run);
241
+
242
+ // =========================================================================
243
+ // Summary
244
+ // =========================================================================
245
+ printSection('Test Summary');
246
+ console.log('The automatic session tracking feature should have:');
247
+ console.log('1. Stored the session_id after the first code execution');
248
+ console.log('2. Automatically injected it into subsequent executions');
249
+ console.log('3. Accumulated file references across all executions');
250
+ console.log('\nCheck the session context output above to verify.\n');
251
+
252
+ // Generate title
253
+ const { handleLLMEnd, collected } = createMetadataAggregator();
254
+ const titleResult = await run.generateTitle({
255
+ provider,
256
+ inputText: 'Testing automatic session tracking for code execution',
257
+ contentParts,
258
+ chainOptions: {
259
+ callbacks: [{ handleLLMEnd }],
260
+ },
261
+ });
262
+ console.log('Generated Title:', titleResult);
263
+ console.log('Collected metadata:', collected);
264
+ }
265
+
266
+ process.on('unhandledRejection', (reason, promise) => {
267
+ console.error('Unhandled Rejection at:', promise, 'reason:', reason);
268
+ console.log('Conversation history:');
269
+ console.dir(conversationHistory, { depth: null });
270
+ process.exit(1);
271
+ });
272
+
273
+ process.on('uncaughtException', (err) => {
274
+ console.error('Uncaught Exception:', err);
275
+ });
276
+
277
+ testAutomaticSessionTracking().catch((err) => {
278
+ console.error(err);
279
+ console.log('Conversation history:');
280
+ console.dir(conversationHistory, { depth: null });
281
+ process.exit(1);
282
+ });
@@ -210,6 +210,7 @@ async function testConditionalMultiAgent() {
210
210
  console.log(`\n\nExpert used: ${selectedExpert}`);
211
211
  console.log('Content parts:', contentParts.length);
212
212
  console.log('---');
213
+ console.dir(contentParts, { depth: null });
213
214
  }
214
215
  } catch (error) {
215
216
  console.error('Error in conditional multi-agent test:', error);
@@ -353,6 +353,7 @@ async function testSupervisorMultiAgent() {
353
353
  );
354
354
  console.log(` transfer_to_legal_advisor`);
355
355
  console.log('─'.repeat(60));
356
+ console.dir(contentParts, { depth: null });
356
357
  }
357
358
  await sleep(3000);
358
359
  } catch (error) {
@@ -23,7 +23,7 @@ import type { RunnableConfig } from '@langchain/core/runnables';
23
23
  import type * as t from '@/types';
24
24
  import { createCodeExecutionTool } from '@/tools/CodeExecutor';
25
25
  import { createProgrammaticToolCallingTool } from '@/tools/ProgrammaticToolCalling';
26
- import { createToolSearchRegexTool } from '@/tools/ToolSearchRegex';
26
+ import { createToolSearch } from '@/tools/ToolSearch';
27
27
  import { getLLMConfig } from '@/utils/llmConfig';
28
28
  import { getArgs } from '@/scripts/args';
29
29
  import { Run } from '@/run';
@@ -40,7 +40,7 @@ import {
40
40
 
41
41
  /**
42
42
  * Tool registry only needs business logic tools that require filtering.
43
- * Special tools (execute_code, run_tools_with_code, tool_search_regex)
43
+ * Special tools (execute_code, run_tools_with_code, tool_search)
44
44
  * are always bound directly to the LLM and don't need registry entries.
45
45
  */
46
46
  function createAgentToolRegistry(): t.LCToolRegistry {
@@ -73,7 +73,7 @@ async function main(): Promise<void> {
73
73
  // Create special tools (PTC, code execution, tool search)
74
74
  const codeExecTool = createCodeExecutionTool();
75
75
  const ptcTool = createProgrammaticToolCallingTool();
76
- const toolSearchTool = createToolSearchRegexTool();
76
+ const toolSearchTool = createToolSearch();
77
77
 
78
78
  // Build complete tool list and map
79
79
  const allTools = [...mockTools, codeExecTool, ptcTool, toolSearchTool];
@@ -199,7 +199,7 @@ Use the run_tools_with_code tool to do this efficiently - don't call each tool s
199
199
  console.log('='.repeat(70));
200
200
  console.log('\nKey observations:');
201
201
  console.log(
202
- '1. LLM only sees tools with allowed_callers including "direct" (get_weather, execute_code, run_tools_with_code, tool_search_regex)'
202
+ '1. LLM only sees tools with allowed_callers including "direct" (get_weather, execute_code, run_tools_with_code, tool_search)'
203
203
  );
204
204
  console.log(
205
205
  '2. When PTC is invoked, ToolNode automatically injects programmatic tools (get_team_members, get_expenses, get_weather)'