@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,392 +0,0 @@
1
- /**
2
- * Unit tests for Bedrock Prompt Caching functionality
3
- *
4
- * Tests cover:
5
- * 1. CustomChatBedrockConverse - Tool caching with cachePoint via invocationParams
6
- * 2. AgentContext - System message format per provider:
7
- * - Bedrock: plain string (cachePoint is added at the tool level by invocationParams)
8
- * - Anthropic: cache_control added inline by AgentContext
9
- * - OpenAI: plain string (no caching)
10
- */
11
- import { CustomChatBedrockConverse } from '../index';
12
- import { AgentContext } from '@/agents/AgentContext';
13
- import { Providers } from '@/common';
14
- describe('Bedrock Prompt Caching', () => {
15
- describe('CustomChatBedrockConverse - Tool Caching', () => {
16
- describe('invocationParams with promptCache enabled', () => {
17
- it('should add cachePoint to tools array when promptCache is true', () => {
18
- const model = new CustomChatBedrockConverse({
19
- model: 'anthropic.claude-3-haiku-20240307-v1:0',
20
- region: 'us-east-1',
21
- promptCache: true,
22
- });
23
- const mockTools = [
24
- {
25
- toolSpec: {
26
- name: 'get_weather',
27
- description: 'Get weather for a location',
28
- inputSchema: { json: { type: 'object', properties: {} } },
29
- },
30
- },
31
- {
32
- toolSpec: {
33
- name: 'search_web',
34
- description: 'Search the web',
35
- inputSchema: { json: { type: 'object', properties: {} } },
36
- },
37
- },
38
- ];
39
- const params = model.invocationParams({
40
- tools: mockTools,
41
- });
42
- // Should have tools + cachePoint
43
- expect(params.toolConfig?.tools).toHaveLength(3);
44
- expect(params.toolConfig?.tools?.[2]).toEqual({
45
- cachePoint: { type: 'default' },
46
- });
47
- });
48
- it('should NOT add cachePoint when promptCache is false', () => {
49
- const model = new CustomChatBedrockConverse({
50
- model: 'anthropic.claude-3-haiku-20240307-v1:0',
51
- region: 'us-east-1',
52
- promptCache: false,
53
- });
54
- const mockTools = [
55
- {
56
- toolSpec: {
57
- name: 'get_weather',
58
- description: 'Get weather',
59
- inputSchema: { json: { type: 'object', properties: {} } },
60
- },
61
- },
62
- ];
63
- const params = model.invocationParams({
64
- tools: mockTools,
65
- });
66
- // Should only have original tools, no cachePoint
67
- expect(params.toolConfig?.tools).toHaveLength(1);
68
- expect(params.toolConfig?.tools?.[0]).toEqual(mockTools[0]);
69
- });
70
- it('should NOT add cachePoint when promptCache is undefined (default)', () => {
71
- const model = new CustomChatBedrockConverse({
72
- model: 'anthropic.claude-3-haiku-20240307-v1:0',
73
- region: 'us-east-1',
74
- });
75
- const mockTools = [
76
- {
77
- toolSpec: {
78
- name: 'get_weather',
79
- description: 'Get weather',
80
- inputSchema: { json: { type: 'object', properties: {} } },
81
- },
82
- },
83
- ];
84
- const params = model.invocationParams({
85
- tools: mockTools,
86
- });
87
- // Should only have original tools
88
- expect(params.toolConfig?.tools).toHaveLength(1);
89
- });
90
- it('should NOT add cachePoint when no tools are provided', () => {
91
- const model = new CustomChatBedrockConverse({
92
- model: 'anthropic.claude-3-haiku-20240307-v1:0',
93
- region: 'us-east-1',
94
- promptCache: true,
95
- });
96
- const params = model.invocationParams({});
97
- // toolConfig should be undefined or have no tools
98
- expect(params.toolConfig?.tools).toBeUndefined();
99
- });
100
- it('should NOT add cachePoint when tools array is empty', () => {
101
- const model = new CustomChatBedrockConverse({
102
- model: 'anthropic.claude-3-haiku-20240307-v1:0',
103
- region: 'us-east-1',
104
- promptCache: true,
105
- });
106
- const params = model.invocationParams({
107
- tools: [],
108
- });
109
- // Empty tools array results in undefined toolConfig
110
- expect(params.toolConfig).toBeUndefined();
111
- });
112
- it('should preserve other invocationParams properties', () => {
113
- const model = new CustomChatBedrockConverse({
114
- model: 'anthropic.claude-3-haiku-20240307-v1:0',
115
- region: 'us-east-1',
116
- promptCache: true,
117
- temperature: 0.7,
118
- maxTokens: 1000,
119
- });
120
- const mockTools = [
121
- {
122
- toolSpec: {
123
- name: 'test_tool',
124
- description: 'Test',
125
- inputSchema: { json: { type: 'object', properties: {} } },
126
- },
127
- },
128
- ];
129
- const params = model.invocationParams({
130
- tools: mockTools,
131
- });
132
- // Check that other params are preserved
133
- expect(params.inferenceConfig?.temperature).toBe(0.7);
134
- expect(params.inferenceConfig?.maxTokens).toBe(1000);
135
- // And cachePoint is still added
136
- expect(params.toolConfig?.tools).toHaveLength(2);
137
- });
138
- });
139
- describe('promptCache property', () => {
140
- it('should store promptCache value from constructor', () => {
141
- const modelWithCache = new CustomChatBedrockConverse({
142
- model: 'test-model',
143
- region: 'us-east-1',
144
- promptCache: true,
145
- });
146
- const modelWithoutCache = new CustomChatBedrockConverse({
147
- model: 'test-model',
148
- region: 'us-east-1',
149
- promptCache: false,
150
- });
151
- expect(modelWithCache.promptCache).toBe(true);
152
- expect(modelWithoutCache.promptCache).toBe(false);
153
- });
154
- it('should default promptCache to false when not provided', () => {
155
- const model = new CustomChatBedrockConverse({
156
- model: 'test-model',
157
- region: 'us-east-1',
158
- });
159
- expect(model.promptCache).toBe(false);
160
- });
161
- });
162
- });
163
- describe('AgentContext - System Message Caching', () => {
164
- const createBedrockContext = (options) => {
165
- const clientOptions = {
166
- model: 'anthropic.claude-3-haiku-20240307-v1:0',
167
- region: 'us-east-1',
168
- promptCache: options.promptCache,
169
- };
170
- return AgentContext.fromConfig({
171
- agentId: 'test-bedrock-agent',
172
- provider: Providers.BEDROCK,
173
- instructions: options.instructions,
174
- additional_instructions: options.additionalInstructions,
175
- clientOptions,
176
- });
177
- };
178
- const createAnthropicContext = (options) => {
179
- const clientOptions = {
180
- promptCache: options.promptCachingEnabled,
181
- };
182
- return AgentContext.fromConfig({
183
- agentId: 'test-anthropic-agent',
184
- provider: Providers.ANTHROPIC,
185
- instructions: options.instructions,
186
- clientOptions,
187
- });
188
- };
189
- describe('Bedrock system message with promptCache: true', () => {
190
- it('should produce plain string system message (cachePoint is handled at tool level)', async () => {
191
- const ctx = createBedrockContext({
192
- instructions: 'You are a helpful assistant.',
193
- promptCache: true,
194
- });
195
- const systemRunnable = ctx.systemRunnable;
196
- expect(systemRunnable).toBeDefined();
197
- // Invoke the runnable to get the messages
198
- const result = await systemRunnable.invoke([]);
199
- const systemMessage = result[0];
200
- // Bedrock system messages are plain strings — cachePoint is added
201
- // at the tool level by IllumaBedrockConverse.invocationParams()
202
- expect(typeof systemMessage.content).toBe('string');
203
- expect(systemMessage.content).toBe('You are a helpful assistant.');
204
- });
205
- it('should include combined instructions and additional_instructions as plain string', async () => {
206
- const ctx = createBedrockContext({
207
- instructions: 'Base instructions.',
208
- additionalInstructions: 'Additional context.',
209
- promptCache: true,
210
- });
211
- const result = await ctx.systemRunnable.invoke([]);
212
- const systemMessage = result[0];
213
- // Bedrock system messages are plain strings even with promptCache
214
- expect(typeof systemMessage.content).toBe('string');
215
- expect(systemMessage.content).toContain('Base instructions.');
216
- expect(systemMessage.content).toContain('Additional context.');
217
- });
218
- });
219
- describe('Bedrock system message with promptCache: false', () => {
220
- it('should NOT add cachePoint when promptCache is false', async () => {
221
- const ctx = createBedrockContext({
222
- instructions: 'You are a helpful assistant.',
223
- promptCache: false,
224
- });
225
- const result = await ctx.systemRunnable.invoke([]);
226
- const systemMessage = result[0];
227
- // Content should be plain string, not array with cachePoint
228
- expect(typeof systemMessage.content).toBe('string');
229
- expect(systemMessage.content).toBe('You are a helpful assistant.');
230
- });
231
- it('should NOT add cachePoint when promptCache is undefined', async () => {
232
- const ctx = createBedrockContext({
233
- instructions: 'You are a helpful assistant.',
234
- promptCache: undefined,
235
- });
236
- const result = await ctx.systemRunnable.invoke([]);
237
- const systemMessage = result[0];
238
- expect(typeof systemMessage.content).toBe('string');
239
- });
240
- });
241
- describe('Anthropic system message caching (for comparison)', () => {
242
- it('should add cache_control for Anthropic with prompt-caching beta', async () => {
243
- const ctx = createAnthropicContext({
244
- instructions: 'You are a helpful assistant.',
245
- promptCachingEnabled: true,
246
- });
247
- const result = await ctx.systemRunnable.invoke([]);
248
- const systemMessage = result[0];
249
- const content = systemMessage.content;
250
- expect(content).toHaveLength(1);
251
- expect(content[0]).toEqual({
252
- type: 'text',
253
- text: 'You are a helpful assistant.',
254
- cache_control: { type: 'ephemeral' },
255
- });
256
- });
257
- it('should NOT add cache_control for Anthropic without beta header', async () => {
258
- const ctx = createAnthropicContext({
259
- instructions: 'You are a helpful assistant.',
260
- promptCachingEnabled: false,
261
- });
262
- const result = await ctx.systemRunnable.invoke([]);
263
- const systemMessage = result[0];
264
- expect(typeof systemMessage.content).toBe('string');
265
- });
266
- });
267
- describe('Provider-specific caching behavior', () => {
268
- it('should produce plain string for Bedrock (cachePoint handled at tool level)', async () => {
269
- const bedrockCtx = createBedrockContext({
270
- instructions: 'Test',
271
- promptCache: true,
272
- });
273
- const result = await bedrockCtx.systemRunnable.invoke([]);
274
- // Bedrock system messages are plain strings — cachePoint is added
275
- // at the tool level by IllumaBedrockConverse.invocationParams(),
276
- // not inline in the system message content
277
- expect(typeof result[0].content).toBe('string');
278
- expect(result[0].content).toBe('Test');
279
- });
280
- it('should use cache_control format for Anthropic, not cachePoint', async () => {
281
- const anthropicCtx = createAnthropicContext({
282
- instructions: 'Test',
283
- promptCachingEnabled: true,
284
- });
285
- const result = await anthropicCtx.systemRunnable.invoke([]);
286
- const content = result[0].content;
287
- // Anthropic uses cache_control inline in system message content
288
- expect(content.some((c) => 'cache_control' in c)).toBe(true);
289
- expect(content.some((c) => 'cachePoint' in c)).toBe(false);
290
- });
291
- it('should not add any caching for OpenAI provider', async () => {
292
- const openaiCtx = AgentContext.fromConfig({
293
- agentId: 'test-openai-agent',
294
- provider: Providers.OPENAI,
295
- instructions: 'Test instructions',
296
- });
297
- const result = await openaiCtx.systemRunnable.invoke([]);
298
- const systemMessage = result[0];
299
- // OpenAI should have plain string content
300
- expect(typeof systemMessage.content).toBe('string');
301
- expect(systemMessage.content).toBe('Test instructions');
302
- });
303
- });
304
- });
305
- describe('Integration scenarios', () => {
306
- it('should handle multi-turn caching scenario', async () => {
307
- // Simulate: Query 1 with tools → Query 2 with same tools
308
- // Both should have cachePoint, enabling cache reuse
309
- const model = new CustomChatBedrockConverse({
310
- model: 'anthropic.claude-3-haiku-20240307-v1:0',
311
- region: 'us-east-1',
312
- promptCache: true,
313
- });
314
- const tools = [
315
- {
316
- toolSpec: {
317
- name: 'execute_code',
318
- description: 'Execute Python code',
319
- inputSchema: { json: { type: 'object', properties: {} } },
320
- },
321
- },
322
- {
323
- toolSpec: {
324
- name: 'file_search',
325
- description: 'Search files',
326
- inputSchema: { json: { type: 'object', properties: {} } },
327
- },
328
- },
329
- ];
330
- // Query 1
331
- const params1 = model.invocationParams({
332
- tools,
333
- });
334
- // Query 2 (same tools)
335
- const params2 = model.invocationParams({
336
- tools,
337
- });
338
- // Both should have identical tool configs with cachePoint
339
- expect(params1.toolConfig?.tools).toEqual(params2.toolConfig?.tools);
340
- expect(params1.toolConfig?.tools).toHaveLength(3); // 2 tools + cachePoint
341
- });
342
- it('should handle dynamic tool selection scenario', async () => {
343
- // Simulate: Query 1 with [A, B] → Query 2 with [A, B, C]
344
- // Tool set changed, so cache won't match (expected behavior)
345
- const model = new CustomChatBedrockConverse({
346
- model: 'anthropic.claude-3-haiku-20240307-v1:0',
347
- region: 'us-east-1',
348
- promptCache: true,
349
- });
350
- const toolA = {
351
- toolSpec: {
352
- name: 'tool_a',
353
- description: 'Tool A',
354
- inputSchema: { json: { type: 'object', properties: {} } },
355
- },
356
- };
357
- const toolB = {
358
- toolSpec: {
359
- name: 'tool_b',
360
- description: 'Tool B',
361
- inputSchema: { json: { type: 'object', properties: {} } },
362
- },
363
- };
364
- const toolC = {
365
- toolSpec: {
366
- name: 'tool_c',
367
- description: 'Tool C',
368
- inputSchema: { json: { type: 'object', properties: {} } },
369
- },
370
- };
371
- // Query 1: [A, B]
372
- const params1 = model.invocationParams({
373
- tools: [toolA, toolB],
374
- });
375
- // Query 2: [A, B, C] - different tool set
376
- const params2 = model.invocationParams({
377
- tools: [toolA, toolB, toolC],
378
- });
379
- // Different lengths (cache prefix won't match beyond common prefix)
380
- expect(params1.toolConfig?.tools).toHaveLength(3); // 2 tools + cachePoint
381
- expect(params2.toolConfig?.tools).toHaveLength(4); // 3 tools + cachePoint
382
- // But both have cachePoint at the end
383
- expect(params1.toolConfig?.tools?.[2]).toEqual({
384
- cachePoint: { type: 'default' },
385
- });
386
- expect(params2.toolConfig?.tools?.[3]).toEqual({
387
- cachePoint: { type: 'default' },
388
- });
389
- });
390
- });
391
- });
392
- //# sourceMappingURL=bedrock-caching.test.js.map