@illuma-ai/agents 1.1.20 → 1.1.22

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 (246) hide show
  1. package/dist/cjs/graphs/Graph.cjs +12 -1
  2. package/dist/cjs/graphs/Graph.cjs.map +1 -1
  3. package/dist/cjs/graphs/MultiAgentGraph.cjs +85 -1
  4. package/dist/cjs/graphs/MultiAgentGraph.cjs.map +1 -1
  5. package/dist/cjs/llm/bedrock/index.cjs +14 -0
  6. package/dist/cjs/llm/bedrock/index.cjs.map +1 -1
  7. package/dist/cjs/run.cjs +20 -9
  8. package/dist/cjs/run.cjs.map +1 -1
  9. package/dist/esm/graphs/Graph.mjs +12 -1
  10. package/dist/esm/graphs/Graph.mjs.map +1 -1
  11. package/dist/esm/graphs/MultiAgentGraph.mjs +85 -1
  12. package/dist/esm/graphs/MultiAgentGraph.mjs.map +1 -1
  13. package/dist/esm/llm/bedrock/index.mjs +14 -0
  14. package/dist/esm/llm/bedrock/index.mjs.map +1 -1
  15. package/dist/esm/run.mjs +20 -9
  16. package/dist/esm/run.mjs.map +1 -1
  17. package/dist/types/graphs/MultiAgentGraph.d.ts +17 -0
  18. package/package.json +1 -1
  19. package/src/graphs/Graph.ts +12 -1
  20. package/src/graphs/MultiAgentGraph.ts +105 -1
  21. package/src/graphs/__tests__/multi-agent-delegate.test.ts +191 -0
  22. package/src/llm/bedrock/index.ts +17 -0
  23. package/src/run.ts +20 -11
  24. package/src/scripts/test-bedrock-handoff-autonomous.ts +231 -0
  25. package/src/agents/AgentContext.js +0 -782
  26. package/src/agents/AgentContext.test.js +0 -421
  27. package/src/agents/__tests__/AgentContext.test.js +0 -678
  28. package/src/agents/__tests__/resolveStructuredOutputMode.test.js +0 -117
  29. package/src/common/enum.js +0 -192
  30. package/src/common/index.js +0 -3
  31. package/src/events.js +0 -166
  32. package/src/graphs/Graph.js +0 -1857
  33. package/src/graphs/MultiAgentGraph.js +0 -1092
  34. package/src/graphs/__tests__/structured-output.integration.test.js +0 -624
  35. package/src/graphs/__tests__/structured-output.test.js +0 -144
  36. package/src/graphs/contextManagement.e2e.test.js +0 -718
  37. package/src/graphs/contextManagement.test.js +0 -485
  38. package/src/graphs/handoffValidation.test.js +0 -276
  39. package/src/graphs/index.js +0 -3
  40. package/src/index.js +0 -28
  41. package/src/instrumentation.js +0 -21
  42. package/src/llm/anthropic/index.js +0 -319
  43. package/src/llm/anthropic/types.js +0 -46
  44. package/src/llm/anthropic/utils/message_inputs.js +0 -627
  45. package/src/llm/anthropic/utils/message_outputs.js +0 -290
  46. package/src/llm/anthropic/utils/output_parsers.js +0 -89
  47. package/src/llm/anthropic/utils/tools.js +0 -25
  48. package/src/llm/bedrock/__tests__/bedrock-caching.test.js +0 -392
  49. package/src/llm/bedrock/index.js +0 -303
  50. package/src/llm/bedrock/types.js +0 -2
  51. package/src/llm/bedrock/utils/index.js +0 -6
  52. package/src/llm/bedrock/utils/message_inputs.js +0 -463
  53. package/src/llm/bedrock/utils/message_outputs.js +0 -269
  54. package/src/llm/fake.js +0 -92
  55. package/src/llm/google/index.js +0 -215
  56. package/src/llm/google/types.js +0 -12
  57. package/src/llm/google/utils/common.js +0 -670
  58. package/src/llm/google/utils/tools.js +0 -111
  59. package/src/llm/google/utils/zod_to_genai_parameters.js +0 -47
  60. package/src/llm/openai/index.js +0 -1033
  61. package/src/llm/openai/types.js +0 -2
  62. package/src/llm/openai/utils/index.js +0 -756
  63. package/src/llm/openai/utils/isReasoningModel.test.js +0 -79
  64. package/src/llm/openrouter/index.js +0 -261
  65. package/src/llm/openrouter/reasoning.test.js +0 -181
  66. package/src/llm/providers.js +0 -36
  67. package/src/llm/text.js +0 -65
  68. package/src/llm/vertexai/index.js +0 -402
  69. package/src/messages/__tests__/tools.test.js +0 -392
  70. package/src/messages/cache.js +0 -404
  71. package/src/messages/cache.test.js +0 -1167
  72. package/src/messages/content.js +0 -48
  73. package/src/messages/content.test.js +0 -314
  74. package/src/messages/core.js +0 -359
  75. package/src/messages/ensureThinkingBlock.test.js +0 -997
  76. package/src/messages/format.js +0 -973
  77. package/src/messages/formatAgentMessages.test.js +0 -2278
  78. package/src/messages/formatAgentMessages.tools.test.js +0 -362
  79. package/src/messages/formatMessage.test.js +0 -608
  80. package/src/messages/ids.js +0 -18
  81. package/src/messages/index.js +0 -9
  82. package/src/messages/labelContentByAgent.test.js +0 -725
  83. package/src/messages/prune.js +0 -438
  84. package/src/messages/reducer.js +0 -60
  85. package/src/messages/shiftIndexTokenCountMap.test.js +0 -63
  86. package/src/messages/summarize.js +0 -146
  87. package/src/messages/summarize.test.js +0 -332
  88. package/src/messages/tools.js +0 -90
  89. package/src/mockStream.js +0 -81
  90. package/src/prompts/collab.js +0 -7
  91. package/src/prompts/index.js +0 -3
  92. package/src/prompts/taskmanager.js +0 -58
  93. package/src/run.js +0 -427
  94. package/src/schemas/index.js +0 -3
  95. package/src/schemas/schema-preparation.test.js +0 -370
  96. package/src/schemas/validate.js +0 -314
  97. package/src/schemas/validate.test.js +0 -264
  98. package/src/scripts/abort.js +0 -127
  99. package/src/scripts/ant_web_search.js +0 -130
  100. package/src/scripts/ant_web_search_edge_case.js +0 -133
  101. package/src/scripts/ant_web_search_error_edge_case.js +0 -119
  102. package/src/scripts/args.js +0 -41
  103. package/src/scripts/bedrock-cache-debug.js +0 -186
  104. package/src/scripts/bedrock-content-aggregation-test.js +0 -195
  105. package/src/scripts/bedrock-merge-test.js +0 -80
  106. package/src/scripts/bedrock-parallel-tools-test.js +0 -150
  107. package/src/scripts/caching.js +0 -106
  108. package/src/scripts/cli.js +0 -152
  109. package/src/scripts/cli2.js +0 -119
  110. package/src/scripts/cli3.js +0 -163
  111. package/src/scripts/cli4.js +0 -165
  112. package/src/scripts/cli5.js +0 -165
  113. package/src/scripts/code_exec.js +0 -171
  114. package/src/scripts/code_exec_files.js +0 -180
  115. package/src/scripts/code_exec_multi_session.js +0 -185
  116. package/src/scripts/code_exec_ptc.js +0 -265
  117. package/src/scripts/code_exec_session.js +0 -217
  118. package/src/scripts/code_exec_simple.js +0 -120
  119. package/src/scripts/content.js +0 -111
  120. package/src/scripts/empty_input.js +0 -125
  121. package/src/scripts/handoff-test.js +0 -96
  122. package/src/scripts/image.js +0 -138
  123. package/src/scripts/memory.js +0 -83
  124. package/src/scripts/multi-agent-chain.js +0 -271
  125. package/src/scripts/multi-agent-conditional.js +0 -185
  126. package/src/scripts/multi-agent-document-review-chain.js +0 -171
  127. package/src/scripts/multi-agent-hybrid-flow.js +0 -264
  128. package/src/scripts/multi-agent-parallel-start.js +0 -214
  129. package/src/scripts/multi-agent-parallel.js +0 -346
  130. package/src/scripts/multi-agent-sequence.js +0 -184
  131. package/src/scripts/multi-agent-supervisor.js +0 -324
  132. package/src/scripts/multi-agent-test.js +0 -147
  133. package/src/scripts/parallel-asymmetric-tools-test.js +0 -202
  134. package/src/scripts/parallel-full-metadata-test.js +0 -176
  135. package/src/scripts/parallel-tools-test.js +0 -256
  136. package/src/scripts/programmatic_exec.js +0 -277
  137. package/src/scripts/programmatic_exec_agent.js +0 -168
  138. package/src/scripts/search.js +0 -118
  139. package/src/scripts/sequential-full-metadata-test.js +0 -143
  140. package/src/scripts/simple.js +0 -174
  141. package/src/scripts/single-agent-metadata-test.js +0 -152
  142. package/src/scripts/stream.js +0 -113
  143. package/src/scripts/test-custom-prompt-key.js +0 -132
  144. package/src/scripts/test-handoff-input.js +0 -143
  145. package/src/scripts/test-handoff-preamble.js +0 -227
  146. package/src/scripts/test-handoff-steering.js +0 -353
  147. package/src/scripts/test-multi-agent-list-handoff.js +0 -318
  148. package/src/scripts/test-parallel-agent-labeling.js +0 -253
  149. package/src/scripts/test-parallel-handoffs.js +0 -229
  150. package/src/scripts/test-thinking-handoff-bedrock.js +0 -132
  151. package/src/scripts/test-thinking-handoff.js +0 -132
  152. package/src/scripts/test-thinking-to-thinking-handoff-bedrock.js +0 -140
  153. package/src/scripts/test-tool-before-handoff-role-order.js +0 -223
  154. package/src/scripts/test-tools-before-handoff.js +0 -187
  155. package/src/scripts/test_code_api.js +0 -263
  156. package/src/scripts/thinking-bedrock.js +0 -128
  157. package/src/scripts/thinking-vertexai.js +0 -130
  158. package/src/scripts/thinking.js +0 -134
  159. package/src/scripts/tool_search.js +0 -114
  160. package/src/scripts/tools.js +0 -125
  161. package/src/specs/agent-handoffs-bedrock.integration.test.js +0 -280
  162. package/src/specs/agent-handoffs.test.js +0 -924
  163. package/src/specs/anthropic.simple.test.js +0 -287
  164. package/src/specs/azure.simple.test.js +0 -381
  165. package/src/specs/cache.simple.test.js +0 -282
  166. package/src/specs/custom-event-await.test.js +0 -148
  167. package/src/specs/deepseek.simple.test.js +0 -189
  168. package/src/specs/emergency-prune.test.js +0 -308
  169. package/src/specs/moonshot.simple.test.js +0 -237
  170. package/src/specs/observability.integration.test.js +0 -1337
  171. package/src/specs/openai.simple.test.js +0 -233
  172. package/src/specs/openrouter.simple.test.js +0 -202
  173. package/src/specs/prune.test.js +0 -733
  174. package/src/specs/reasoning.test.js +0 -144
  175. package/src/specs/spec.utils.js +0 -4
  176. package/src/specs/thinking-handoff.test.js +0 -486
  177. package/src/specs/thinking-prune.test.js +0 -600
  178. package/src/specs/token-distribution-edge-case.test.js +0 -246
  179. package/src/specs/token-memoization.test.js +0 -32
  180. package/src/specs/tokens.test.js +0 -49
  181. package/src/specs/tool-error.test.js +0 -139
  182. package/src/splitStream.js +0 -204
  183. package/src/splitStream.test.js +0 -504
  184. package/src/stream.js +0 -650
  185. package/src/stream.test.js +0 -225
  186. package/src/test/mockTools.js +0 -340
  187. package/src/tools/BrowserTools.js +0 -245
  188. package/src/tools/Calculator.js +0 -38
  189. package/src/tools/Calculator.test.js +0 -225
  190. package/src/tools/CodeExecutor.js +0 -233
  191. package/src/tools/ProgrammaticToolCalling.js +0 -602
  192. package/src/tools/StreamingToolCallBuffer.js +0 -179
  193. package/src/tools/ToolNode.js +0 -930
  194. package/src/tools/ToolSearch.js +0 -904
  195. package/src/tools/__tests__/BrowserTools.test.js +0 -306
  196. package/src/tools/__tests__/ProgrammaticToolCalling.integration.test.js +0 -276
  197. package/src/tools/__tests__/ProgrammaticToolCalling.test.js +0 -807
  198. package/src/tools/__tests__/StreamingToolCallBuffer.test.js +0 -175
  199. package/src/tools/__tests__/ToolApproval.test.js +0 -675
  200. package/src/tools/__tests__/ToolNode.recovery.test.js +0 -200
  201. package/src/tools/__tests__/ToolNode.session.test.js +0 -319
  202. package/src/tools/__tests__/ToolSearch.integration.test.js +0 -125
  203. package/src/tools/__tests__/ToolSearch.test.js +0 -812
  204. package/src/tools/__tests__/handlers.test.js +0 -799
  205. package/src/tools/__tests__/truncation-recovery.integration.test.js +0 -362
  206. package/src/tools/handlers.js +0 -306
  207. package/src/tools/schema.js +0 -25
  208. package/src/tools/search/anthropic.js +0 -34
  209. package/src/tools/search/content.js +0 -116
  210. package/src/tools/search/content.test.js +0 -133
  211. package/src/tools/search/firecrawl.js +0 -173
  212. package/src/tools/search/format.js +0 -198
  213. package/src/tools/search/highlights.js +0 -241
  214. package/src/tools/search/index.js +0 -3
  215. package/src/tools/search/jina-reranker.test.js +0 -106
  216. package/src/tools/search/rerankers.js +0 -165
  217. package/src/tools/search/schema.js +0 -102
  218. package/src/tools/search/search.js +0 -561
  219. package/src/tools/search/serper-scraper.js +0 -126
  220. package/src/tools/search/test.js +0 -129
  221. package/src/tools/search/tool.js +0 -453
  222. package/src/tools/search/types.js +0 -2
  223. package/src/tools/search/utils.js +0 -59
  224. package/src/types/graph.js +0 -24
  225. package/src/types/graph.test.js +0 -192
  226. package/src/types/index.js +0 -7
  227. package/src/types/llm.js +0 -2
  228. package/src/types/messages.js +0 -2
  229. package/src/types/run.js +0 -2
  230. package/src/types/stream.js +0 -2
  231. package/src/types/tools.js +0 -2
  232. package/src/utils/contextAnalytics.js +0 -79
  233. package/src/utils/contextAnalytics.test.js +0 -166
  234. package/src/utils/events.js +0 -26
  235. package/src/utils/graph.js +0 -11
  236. package/src/utils/handlers.js +0 -65
  237. package/src/utils/index.js +0 -10
  238. package/src/utils/llm.js +0 -21
  239. package/src/utils/llmConfig.js +0 -205
  240. package/src/utils/logging.js +0 -37
  241. package/src/utils/misc.js +0 -51
  242. package/src/utils/run.js +0 -69
  243. package/src/utils/schema.js +0 -21
  244. package/src/utils/title.js +0 -119
  245. package/src/utils/tokens.js +0 -92
  246. package/src/utils/toonFormat.js +0 -379
@@ -1,282 +0,0 @@
1
- /* eslint-disable no-console */
2
- /* eslint-disable @typescript-eslint/no-explicit-any */
3
- import { config } from 'dotenv';
4
- config();
5
- import { Calculator } from '@/tools/Calculator';
6
- import { HumanMessage, } from '@langchain/core/messages';
7
- import { ModelEndHandler, ToolEndHandler } from '@/events';
8
- import { capitalizeFirstLetter } from './spec.utils';
9
- import { createContentAggregator } from '@/stream';
10
- import { GraphEvents, Providers } from '@/common';
11
- import { getLLMConfig } from '@/utils/llmConfig';
12
- import { getArgs } from '@/scripts/args';
13
- import { Run } from '@/run';
14
- /**
15
- * These tests verify that prompt caching works correctly across multi-turn
16
- * conversations and that messages are not mutated in place.
17
- */
18
- describe('Prompt Caching Integration Tests', () => {
19
- jest.setTimeout(120000);
20
- const setupTest = () => {
21
- const collectedUsage = [];
22
- const { contentParts, aggregateContent } = createContentAggregator();
23
- const customHandlers = {
24
- [GraphEvents.TOOL_END]: new ToolEndHandler(),
25
- [GraphEvents.CHAT_MODEL_END]: new ModelEndHandler(collectedUsage),
26
- [GraphEvents.ON_RUN_STEP_COMPLETED]: {
27
- handle: (event, data) => {
28
- aggregateContent({
29
- event,
30
- data: data,
31
- });
32
- },
33
- },
34
- [GraphEvents.ON_RUN_STEP]: {
35
- handle: (event, data) => {
36
- aggregateContent({ event, data: data });
37
- },
38
- },
39
- [GraphEvents.ON_RUN_STEP_DELTA]: {
40
- handle: (event, data) => {
41
- aggregateContent({ event, data: data });
42
- },
43
- },
44
- [GraphEvents.ON_MESSAGE_DELTA]: {
45
- handle: (event, data) => {
46
- aggregateContent({ event, data: data });
47
- },
48
- },
49
- };
50
- return { collectedUsage, contentParts, customHandlers };
51
- };
52
- const streamConfig = {
53
- configurable: { thread_id: 'cache-test-thread' },
54
- streamMode: 'values',
55
- version: 'v2',
56
- };
57
- describe('Anthropic Prompt Caching', () => {
58
- const provider = Providers.ANTHROPIC;
59
- test(`${capitalizeFirstLetter(provider)}: multi-turn conversation with caching should not corrupt messages`, async () => {
60
- const { userName, location } = await getArgs();
61
- const llmConfig = getLLMConfig(provider);
62
- const { collectedUsage, customHandlers } = setupTest();
63
- const run = await Run.create({
64
- runId: 'cache-test-anthropic',
65
- graphConfig: {
66
- type: 'standard',
67
- llmConfig: { ...llmConfig, promptCache: true },
68
- tools: [new Calculator()],
69
- instructions: 'You are a helpful assistant.',
70
- additional_instructions: `User: ${userName}, Location: ${location}`,
71
- },
72
- returnContent: true,
73
- skipCleanup: true,
74
- customHandlers,
75
- });
76
- // Turn 1
77
- const turn1Messages = [
78
- new HumanMessage('Hello, what is 2+2?'),
79
- ];
80
- const turn1ContentSnapshot = JSON.stringify(turn1Messages[0].content);
81
- const turn1Result = await run.processStream({ messages: turn1Messages }, streamConfig);
82
- expect(turn1Result).toBeDefined();
83
- // Verify original message was NOT mutated
84
- expect(JSON.stringify(turn1Messages[0].content)).toBe(turn1ContentSnapshot);
85
- expect(turn1Messages[0].content).not.toContain('cache_control');
86
- const turn1RunMessages = run.getRunMessages();
87
- expect(turn1RunMessages).toBeDefined();
88
- expect(turn1RunMessages.length).toBeGreaterThan(0);
89
- // Turn 2 - build on conversation
90
- const turn2Messages = [
91
- ...turn1Messages,
92
- ...turn1RunMessages,
93
- new HumanMessage('Now multiply that by 10'),
94
- ];
95
- const turn2HumanContentSnapshot = JSON.stringify(turn2Messages[turn2Messages.length - 1].content);
96
- const run2 = await Run.create({
97
- runId: 'cache-test-anthropic-2',
98
- graphConfig: {
99
- type: 'standard',
100
- llmConfig: { ...llmConfig, promptCache: true },
101
- tools: [new Calculator()],
102
- instructions: 'You are a helpful assistant.',
103
- additional_instructions: `User: ${userName}, Location: ${location}`,
104
- },
105
- returnContent: true,
106
- skipCleanup: true,
107
- customHandlers,
108
- });
109
- const turn2Result = await run2.processStream({ messages: turn2Messages }, streamConfig);
110
- expect(turn2Result).toBeDefined();
111
- // Verify messages were NOT mutated
112
- expect(JSON.stringify(turn2Messages[turn2Messages.length - 1].content)).toBe(turn2HumanContentSnapshot);
113
- // Check that we got cache read tokens (indicating caching worked)
114
- console.log(`${provider} Usage:`, collectedUsage);
115
- expect(collectedUsage.length).toBeGreaterThan(0);
116
- console.log(`${capitalizeFirstLetter(provider)} multi-turn caching test passed - messages not mutated`);
117
- });
118
- test(`${capitalizeFirstLetter(provider)}: tool calls should work with caching enabled`, async () => {
119
- const llmConfig = getLLMConfig(provider);
120
- const { customHandlers } = setupTest();
121
- const run = await Run.create({
122
- runId: 'cache-test-anthropic-tools',
123
- graphConfig: {
124
- type: 'standard',
125
- llmConfig: { ...llmConfig, promptCache: true },
126
- tools: [new Calculator()],
127
- instructions: 'You are a math assistant. Use the calculator tool for all calculations.',
128
- },
129
- returnContent: true,
130
- skipCleanup: true,
131
- customHandlers,
132
- });
133
- const messages = [
134
- new HumanMessage('Calculate 123 * 456 using the calculator'),
135
- ];
136
- const result = await run.processStream({ messages }, streamConfig);
137
- expect(result).toBeDefined();
138
- const runMessages = run.getRunMessages();
139
- expect(runMessages).toBeDefined();
140
- // Should have used the calculator tool
141
- const hasToolUse = runMessages?.some((msg) => msg._getType() === 'ai' &&
142
- (msg.tool_calls?.length ?? 0) > 0);
143
- expect(hasToolUse).toBe(true);
144
- console.log(`${capitalizeFirstLetter(provider)} tool call with caching test passed`);
145
- });
146
- });
147
- describe('Bedrock Prompt Caching', () => {
148
- const provider = Providers.BEDROCK;
149
- test(`${capitalizeFirstLetter(provider)}: multi-turn conversation with caching should not corrupt messages`, async () => {
150
- const { userName, location } = await getArgs();
151
- const llmConfig = getLLMConfig(provider);
152
- const { collectedUsage, customHandlers } = setupTest();
153
- const run = await Run.create({
154
- runId: 'cache-test-bedrock',
155
- graphConfig: {
156
- type: 'standard',
157
- llmConfig: { ...llmConfig, promptCache: true },
158
- tools: [new Calculator()],
159
- instructions: 'You are a helpful assistant.',
160
- additional_instructions: `User: ${userName}, Location: ${location}`,
161
- },
162
- returnContent: true,
163
- skipCleanup: true,
164
- customHandlers,
165
- });
166
- // Turn 1
167
- const turn1Messages = [
168
- new HumanMessage('Hello, what is 5+5?'),
169
- ];
170
- const turn1ContentSnapshot = JSON.stringify(turn1Messages[0].content);
171
- const turn1Result = await run.processStream({ messages: turn1Messages }, streamConfig);
172
- expect(turn1Result).toBeDefined();
173
- // Verify original message was NOT mutated
174
- expect(JSON.stringify(turn1Messages[0].content)).toBe(turn1ContentSnapshot);
175
- const turn1RunMessages = run.getRunMessages();
176
- expect(turn1RunMessages).toBeDefined();
177
- expect(turn1RunMessages.length).toBeGreaterThan(0);
178
- // Turn 2
179
- const turn2Messages = [
180
- ...turn1Messages,
181
- ...turn1RunMessages,
182
- new HumanMessage('Multiply that by 3'),
183
- ];
184
- const turn2HumanContentSnapshot = JSON.stringify(turn2Messages[turn2Messages.length - 1].content);
185
- const run2 = await Run.create({
186
- runId: 'cache-test-bedrock-2',
187
- graphConfig: {
188
- type: 'standard',
189
- llmConfig: { ...llmConfig, promptCache: true },
190
- tools: [new Calculator()],
191
- instructions: 'You are a helpful assistant.',
192
- additional_instructions: `User: ${userName}, Location: ${location}`,
193
- },
194
- returnContent: true,
195
- skipCleanup: true,
196
- customHandlers,
197
- });
198
- const turn2Result = await run2.processStream({ messages: turn2Messages }, streamConfig);
199
- expect(turn2Result).toBeDefined();
200
- // Verify messages were NOT mutated
201
- expect(JSON.stringify(turn2Messages[turn2Messages.length - 1].content)).toBe(turn2HumanContentSnapshot);
202
- console.log(`${provider} Usage:`, collectedUsage);
203
- expect(collectedUsage.length).toBeGreaterThan(0);
204
- console.log(`${capitalizeFirstLetter(provider)} multi-turn caching test passed - messages not mutated`);
205
- });
206
- test(`${capitalizeFirstLetter(provider)}: tool calls should work with caching enabled`, async () => {
207
- const llmConfig = getLLMConfig(provider);
208
- const { customHandlers } = setupTest();
209
- const run = await Run.create({
210
- runId: 'cache-test-bedrock-tools',
211
- graphConfig: {
212
- type: 'standard',
213
- llmConfig: { ...llmConfig, promptCache: true },
214
- tools: [new Calculator()],
215
- instructions: 'You are a math assistant. Use the calculator tool for all calculations.',
216
- },
217
- returnContent: true,
218
- skipCleanup: true,
219
- customHandlers,
220
- });
221
- const messages = [
222
- new HumanMessage('Calculate 789 * 123 using the calculator'),
223
- ];
224
- const result = await run.processStream({ messages }, streamConfig);
225
- expect(result).toBeDefined();
226
- const runMessages = run.getRunMessages();
227
- expect(runMessages).toBeDefined();
228
- // Should have used the calculator tool
229
- const hasToolUse = runMessages?.some((msg) => msg._getType() === 'ai' &&
230
- (msg.tool_calls?.length ?? 0) > 0);
231
- expect(hasToolUse).toBe(true);
232
- console.log(`${capitalizeFirstLetter(provider)} tool call with caching test passed`);
233
- });
234
- });
235
- describe('Cross-provider message isolation', () => {
236
- test('Messages processed by Anthropic should not affect Bedrock processing', async () => {
237
- const anthropicConfig = getLLMConfig(Providers.ANTHROPIC);
238
- const bedrockConfig = getLLMConfig(Providers.BEDROCK);
239
- const { customHandlers: handlers1 } = setupTest();
240
- const { customHandlers: handlers2 } = setupTest();
241
- // Create a shared message array
242
- const sharedMessages = [
243
- new HumanMessage('Hello, what is the capital of France?'),
244
- ];
245
- const originalContent = JSON.stringify(sharedMessages[0].content);
246
- // Process with Anthropic first
247
- const anthropicRun = await Run.create({
248
- runId: 'cross-provider-anthropic',
249
- graphConfig: {
250
- type: 'standard',
251
- llmConfig: { ...anthropicConfig, promptCache: true },
252
- instructions: 'You are a helpful assistant.',
253
- },
254
- returnContent: true,
255
- skipCleanup: true,
256
- customHandlers: handlers1,
257
- });
258
- const anthropicResult = await anthropicRun.processStream({ messages: sharedMessages }, streamConfig);
259
- expect(anthropicResult).toBeDefined();
260
- // Verify message not mutated
261
- expect(JSON.stringify(sharedMessages[0].content)).toBe(originalContent);
262
- // Now process with Bedrock using the SAME messages
263
- const bedrockRun = await Run.create({
264
- runId: 'cross-provider-bedrock',
265
- graphConfig: {
266
- type: 'standard',
267
- llmConfig: { ...bedrockConfig, promptCache: true },
268
- instructions: 'You are a helpful assistant.',
269
- },
270
- returnContent: true,
271
- skipCleanup: true,
272
- customHandlers: handlers2,
273
- });
274
- const bedrockResult = await bedrockRun.processStream({ messages: sharedMessages }, streamConfig);
275
- expect(bedrockResult).toBeDefined();
276
- // Verify message STILL not mutated after both providers processed
277
- expect(JSON.stringify(sharedMessages[0].content)).toBe(originalContent);
278
- console.log('Cross-provider message isolation test passed');
279
- });
280
- });
281
- });
282
- //# sourceMappingURL=cache.simple.test.js.map
@@ -1,148 +0,0 @@
1
- import { HumanMessage } from '@langchain/core/messages';
2
- import { ContentTypes, GraphEvents, Providers } from '@/common';
3
- import { ToolEndHandler, ModelEndHandler } from '@/events';
4
- import { createContentAggregator } from '@/stream';
5
- import { Run } from '@/run';
6
- describe('Custom event handler awaitHandlers behavior', () => {
7
- jest.setTimeout(15000);
8
- const llmConfig = {
9
- provider: Providers.OPENAI,
10
- streaming: true,
11
- streamUsage: false,
12
- };
13
- const config = {
14
- configurable: {
15
- thread_id: 'test-thread',
16
- },
17
- streamMode: 'values',
18
- version: 'v2',
19
- };
20
- it('should fully aggregate all content before processStream returns', async () => {
21
- const longResponse = 'The quick brown fox jumps over the lazy dog and then runs across the field to find shelter from the rain';
22
- let aggregateCallCount = 0;
23
- const { contentParts, aggregateContent } = createContentAggregator();
24
- const wrappedAggregate = (params) => {
25
- aggregateCallCount++;
26
- aggregateContent(params);
27
- };
28
- let messageDeltaCount = 0;
29
- const customHandlers = {
30
- [GraphEvents.TOOL_END]: new ToolEndHandler(),
31
- [GraphEvents.CHAT_MODEL_END]: new ModelEndHandler(),
32
- [GraphEvents.ON_RUN_STEP_COMPLETED]: {
33
- handle: (event, data) => {
34
- wrappedAggregate({
35
- event,
36
- data: data,
37
- });
38
- },
39
- },
40
- [GraphEvents.ON_RUN_STEP]: {
41
- handle: (event, data) => {
42
- wrappedAggregate({ event, data: data });
43
- },
44
- },
45
- [GraphEvents.ON_RUN_STEP_DELTA]: {
46
- handle: (event, data) => {
47
- wrappedAggregate({ event, data: data });
48
- },
49
- },
50
- [GraphEvents.ON_MESSAGE_DELTA]: {
51
- handle: async (event, data) => {
52
- messageDeltaCount++;
53
- wrappedAggregate({ event, data: data });
54
- },
55
- },
56
- [GraphEvents.ON_REASONING_DELTA]: {
57
- handle: (event, data) => {
58
- wrappedAggregate({ event, data: data });
59
- },
60
- },
61
- };
62
- const run = await Run.create({
63
- runId: 'test-await-handlers',
64
- graphConfig: {
65
- type: 'standard',
66
- llmConfig,
67
- },
68
- returnContent: true,
69
- skipCleanup: true,
70
- customHandlers,
71
- });
72
- run.Graph.overrideTestModel([longResponse]);
73
- const inputs = { messages: [new HumanMessage('hello')] };
74
- const finalContentParts = await run.processStream(inputs, config);
75
- expect(finalContentParts).toBeDefined();
76
- expect(finalContentParts.length).toBeGreaterThan(0);
77
- expect(messageDeltaCount).toBeGreaterThan(0);
78
- expect(aggregateCallCount).toBeGreaterThan(0);
79
- const typedParts = contentParts;
80
- const textParts = typedParts.filter((p) => p !== undefined && p.type === ContentTypes.TEXT);
81
- expect(textParts.length).toBeGreaterThan(0);
82
- const aggregatedText = textParts
83
- .map((p) => p[ContentTypes.TEXT])
84
- .join('');
85
- expect(aggregatedText).toBe(longResponse);
86
- });
87
- it('should aggregate content from async handlers before processStream returns', async () => {
88
- const response = 'This is a test of async handler aggregation with multiple tokens';
89
- const { contentParts, aggregateContent } = createContentAggregator();
90
- let asyncHandlerCompletions = 0;
91
- const customHandlers = {
92
- [GraphEvents.TOOL_END]: new ToolEndHandler(),
93
- [GraphEvents.CHAT_MODEL_END]: new ModelEndHandler(),
94
- [GraphEvents.ON_RUN_STEP_COMPLETED]: {
95
- handle: (event, data) => {
96
- aggregateContent({
97
- event,
98
- data: data,
99
- });
100
- },
101
- },
102
- [GraphEvents.ON_RUN_STEP]: {
103
- handle: (event, data) => {
104
- aggregateContent({ event, data: data });
105
- },
106
- },
107
- [GraphEvents.ON_RUN_STEP_DELTA]: {
108
- handle: (event, data) => {
109
- aggregateContent({ event, data: data });
110
- },
111
- },
112
- [GraphEvents.ON_MESSAGE_DELTA]: {
113
- handle: async (event, data) => {
114
- await new Promise((resolve) => setTimeout(resolve, 5));
115
- aggregateContent({ event, data: data });
116
- asyncHandlerCompletions++;
117
- },
118
- },
119
- [GraphEvents.ON_REASONING_DELTA]: {
120
- handle: (event, data) => {
121
- aggregateContent({ event, data: data });
122
- },
123
- },
124
- };
125
- const run = await Run.create({
126
- runId: 'test-async-handlers',
127
- graphConfig: {
128
- type: 'standard',
129
- llmConfig,
130
- },
131
- returnContent: true,
132
- skipCleanup: true,
133
- customHandlers,
134
- });
135
- run.Graph.overrideTestModel([response]);
136
- const inputs = { messages: [new HumanMessage('hello')] };
137
- await run.processStream(inputs, config);
138
- expect(asyncHandlerCompletions).toBeGreaterThan(0);
139
- const typedParts = contentParts;
140
- const textParts = typedParts.filter((p) => p !== undefined && p.type === ContentTypes.TEXT);
141
- expect(textParts.length).toBeGreaterThan(0);
142
- const aggregatedText = textParts
143
- .map((p) => p[ContentTypes.TEXT])
144
- .join('');
145
- expect(aggregatedText).toBe(response);
146
- });
147
- });
148
- //# sourceMappingURL=custom-event-await.test.js.map
@@ -1,189 +0,0 @@
1
- /* eslint-disable no-console */
2
- /* eslint-disable @typescript-eslint/no-explicit-any */
3
- import { config } from 'dotenv';
4
- config();
5
- import { Calculator } from '@/tools/Calculator';
6
- import { HumanMessage, } from '@langchain/core/messages';
7
- import { ToolEndHandler, ModelEndHandler } from '@/events';
8
- import { ContentTypes, GraphEvents, Providers } from '@/common';
9
- import { capitalizeFirstLetter } from './spec.utils';
10
- import { createContentAggregator } from '@/stream';
11
- import { getLLMConfig } from '@/utils/llmConfig';
12
- import { Run } from '@/run';
13
- const provider = Providers.DEEPSEEK;
14
- const llmConfig = getLLMConfig(provider);
15
- const skipTests = process.env.DEEPSEEK_API_KEY == null;
16
- (skipTests ? describe.skip : describe)(`${capitalizeFirstLetter(provider)} Streaming Tests`, () => {
17
- jest.setTimeout(120000);
18
- let run;
19
- let collectedUsage;
20
- let conversationHistory;
21
- let aggregateContent;
22
- let _contentParts;
23
- const testConfig = {
24
- configurable: {
25
- thread_id: 'deepseek-test-1',
26
- },
27
- streamMode: 'values',
28
- version: 'v2',
29
- };
30
- beforeEach(async () => {
31
- conversationHistory = [];
32
- collectedUsage = [];
33
- const { contentParts: cp, aggregateContent: ac } = createContentAggregator();
34
- _contentParts = cp;
35
- aggregateContent = ac;
36
- });
37
- const onMessageDeltaSpy = jest.fn();
38
- const onReasoningDeltaSpy = jest.fn();
39
- const onRunStepSpy = jest.fn();
40
- afterAll(() => {
41
- onMessageDeltaSpy.mockReset();
42
- onReasoningDeltaSpy.mockReset();
43
- onRunStepSpy.mockReset();
44
- });
45
- const setupCustomHandlers = () => ({
46
- [GraphEvents.TOOL_END]: new ToolEndHandler(),
47
- [GraphEvents.CHAT_MODEL_END]: new ModelEndHandler(collectedUsage),
48
- [GraphEvents.ON_RUN_STEP_COMPLETED]: {
49
- handle: (event, data) => {
50
- aggregateContent({
51
- event,
52
- data: data,
53
- });
54
- },
55
- },
56
- [GraphEvents.ON_RUN_STEP]: {
57
- handle: (event, data, metadata, graph) => {
58
- onRunStepSpy(event, data, metadata, graph);
59
- aggregateContent({ event, data: data });
60
- },
61
- },
62
- [GraphEvents.ON_RUN_STEP_DELTA]: {
63
- handle: (event, data) => {
64
- aggregateContent({ event, data: data });
65
- },
66
- },
67
- [GraphEvents.ON_MESSAGE_DELTA]: {
68
- handle: (event, data, metadata, graph) => {
69
- onMessageDeltaSpy(event, data, metadata, graph);
70
- aggregateContent({ event, data: data });
71
- },
72
- },
73
- [GraphEvents.ON_REASONING_DELTA]: {
74
- handle: (event, data) => {
75
- onReasoningDeltaSpy(event, data);
76
- },
77
- },
78
- [GraphEvents.TOOL_START]: {
79
- handle: (_event, _data, _metadata) => {
80
- // Handle tool start
81
- },
82
- },
83
- });
84
- test(`${capitalizeFirstLetter(provider)}: should handle tool calls with reasoning_content preservation (streaming)`, async () => {
85
- const customHandlers = setupCustomHandlers();
86
- run = await Run.create({
87
- runId: 'deepseek-tool-test',
88
- graphConfig: {
89
- type: 'standard',
90
- llmConfig,
91
- tools: [new Calculator()],
92
- instructions: 'You are a helpful math assistant. Use the calculator tool to solve math problems.',
93
- },
94
- returnContent: true,
95
- skipCleanup: true,
96
- customHandlers,
97
- });
98
- const userMessage = 'What is 127 * 453?';
99
- conversationHistory.push(new HumanMessage(userMessage));
100
- const inputs = {
101
- messages: conversationHistory,
102
- };
103
- console.log('Starting DeepSeek streaming tool call test...');
104
- const finalContentParts = await run.processStream(inputs, testConfig);
105
- expect(finalContentParts).toBeDefined();
106
- console.log('Final content parts:', finalContentParts);
107
- const finalMessages = run.getRunMessages();
108
- expect(finalMessages).toBeDefined();
109
- expect(finalMessages?.length).toBeGreaterThan(0);
110
- const hasToolCall = finalMessages?.some((msg) => msg.getType() === 'ai' &&
111
- Array.isArray(msg.tool_calls) &&
112
- msg.tool_calls.length > 0);
113
- expect(hasToolCall).toBe(true);
114
- const hasToolResult = finalMessages?.some((msg) => msg.getType() === 'tool');
115
- expect(hasToolResult).toBe(true);
116
- console.log('Streaming tool call test passed - reasoning_content was preserved');
117
- console.log('Final response:', finalMessages?.[finalMessages.length - 1]?.content);
118
- });
119
- test(`${capitalizeFirstLetter(provider)}: should handle tool calls with disableStreaming`, async () => {
120
- const customHandlers = setupCustomHandlers();
121
- const nonStreamingLlmConfig = {
122
- ...llmConfig,
123
- disableStreaming: true,
124
- };
125
- run = await Run.create({
126
- runId: 'deepseek-non-streaming-tool-test',
127
- graphConfig: {
128
- type: 'standard',
129
- llmConfig: nonStreamingLlmConfig,
130
- tools: [new Calculator()],
131
- instructions: 'You are a helpful math assistant. Use the calculator tool to solve math problems.',
132
- },
133
- returnContent: true,
134
- skipCleanup: true,
135
- customHandlers,
136
- });
137
- const userMessage = 'What is 99 * 77?';
138
- conversationHistory.push(new HumanMessage(userMessage));
139
- const inputs = {
140
- messages: conversationHistory,
141
- };
142
- console.log('Starting DeepSeek non-streaming tool call test...');
143
- const finalContentParts = await run.processStream(inputs, testConfig);
144
- expect(finalContentParts).toBeDefined();
145
- console.log('Final content parts (non-streaming):', finalContentParts);
146
- const finalMessages = run.getRunMessages();
147
- expect(finalMessages).toBeDefined();
148
- expect(finalMessages?.length).toBeGreaterThan(0);
149
- const hasToolCall = finalMessages?.some((msg) => msg.getType() === 'ai' &&
150
- Array.isArray(msg.tool_calls) &&
151
- msg.tool_calls.length > 0);
152
- expect(hasToolCall).toBe(true);
153
- const hasToolResult = finalMessages?.some((msg) => msg.getType() === 'tool');
154
- expect(hasToolResult).toBe(true);
155
- console.log('Non-streaming tool call test passed');
156
- console.log('Final response:', finalMessages?.[finalMessages.length - 1]?.content);
157
- });
158
- test(`${capitalizeFirstLetter(provider)}: should process simple message without tools`, async () => {
159
- const customHandlers = setupCustomHandlers();
160
- run = await Run.create({
161
- runId: 'deepseek-simple-test',
162
- graphConfig: {
163
- type: 'standard',
164
- llmConfig,
165
- tools: [],
166
- instructions: 'You are a friendly AI assistant.',
167
- },
168
- returnContent: true,
169
- skipCleanup: true,
170
- customHandlers,
171
- });
172
- const userMessage = 'Hello! How are you today?';
173
- conversationHistory.push(new HumanMessage(userMessage));
174
- const inputs = {
175
- messages: conversationHistory,
176
- };
177
- const finalContentParts = await run.processStream(inputs, testConfig);
178
- expect(finalContentParts).toBeDefined();
179
- const allTextParts = finalContentParts?.every((part) => part.type === ContentTypes.TEXT);
180
- expect(allTextParts).toBe(true);
181
- expect(collectedUsage.length).toBeGreaterThan(0);
182
- expect(collectedUsage[0].input_tokens).toBeGreaterThan(0);
183
- expect(collectedUsage[0].output_tokens).toBeGreaterThan(0);
184
- const finalMessages = run.getRunMessages();
185
- expect(finalMessages).toBeDefined();
186
- console.log(`${capitalizeFirstLetter(provider)} response:`, finalMessages?.[finalMessages.length - 1]?.content);
187
- });
188
- });
189
- //# sourceMappingURL=deepseek.simple.test.js.map