illuma-agents 1.0.37 → 1.0.39

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 (139) hide show
  1. package/dist/cjs/agents/AgentContext.cjs +112 -14
  2. package/dist/cjs/agents/AgentContext.cjs.map +1 -1
  3. package/dist/cjs/common/enum.cjs +5 -1
  4. package/dist/cjs/common/enum.cjs.map +1 -1
  5. package/dist/cjs/graphs/Graph.cjs +148 -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 +22 -7
  12. package/dist/cjs/main.cjs.map +1 -1
  13. package/dist/cjs/messages/cache.cjs +140 -46
  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/schemas/validate.cjs +173 -0
  20. package/dist/cjs/schemas/validate.cjs.map +1 -0
  21. package/dist/cjs/stream.cjs +4 -2
  22. package/dist/cjs/stream.cjs.map +1 -1
  23. package/dist/cjs/tools/BrowserTools.cjs.map +1 -1
  24. package/dist/cjs/tools/CodeExecutor.cjs +22 -21
  25. package/dist/cjs/tools/CodeExecutor.cjs.map +1 -1
  26. package/dist/cjs/tools/ProgrammaticToolCalling.cjs +14 -11
  27. package/dist/cjs/tools/ProgrammaticToolCalling.cjs.map +1 -1
  28. package/dist/cjs/tools/ToolNode.cjs +101 -2
  29. package/dist/cjs/tools/ToolNode.cjs.map +1 -1
  30. package/dist/cjs/tools/ToolSearch.cjs +862 -0
  31. package/dist/cjs/tools/ToolSearch.cjs.map +1 -0
  32. package/dist/esm/agents/AgentContext.mjs +112 -14
  33. package/dist/esm/agents/AgentContext.mjs.map +1 -1
  34. package/dist/esm/common/enum.mjs +5 -1
  35. package/dist/esm/common/enum.mjs.map +1 -1
  36. package/dist/esm/graphs/Graph.mjs +149 -9
  37. package/dist/esm/graphs/Graph.mjs.map +1 -1
  38. package/dist/esm/graphs/MultiAgentGraph.mjs +278 -12
  39. package/dist/esm/graphs/MultiAgentGraph.mjs.map +1 -1
  40. package/dist/esm/llm/bedrock/index.mjs +127 -60
  41. package/dist/esm/llm/bedrock/index.mjs.map +1 -1
  42. package/dist/esm/main.mjs +2 -1
  43. package/dist/esm/main.mjs.map +1 -1
  44. package/dist/esm/messages/cache.mjs +140 -46
  45. package/dist/esm/messages/cache.mjs.map +1 -1
  46. package/dist/esm/messages/core.mjs +1 -1
  47. package/dist/esm/messages/core.mjs.map +1 -1
  48. package/dist/esm/messages/tools.mjs +2 -2
  49. package/dist/esm/messages/tools.mjs.map +1 -1
  50. package/dist/esm/schemas/validate.mjs +167 -0
  51. package/dist/esm/schemas/validate.mjs.map +1 -0
  52. package/dist/esm/stream.mjs +4 -2
  53. package/dist/esm/stream.mjs.map +1 -1
  54. package/dist/esm/tools/BrowserTools.mjs.map +1 -1
  55. package/dist/esm/tools/CodeExecutor.mjs +22 -21
  56. package/dist/esm/tools/CodeExecutor.mjs.map +1 -1
  57. package/dist/esm/tools/ProgrammaticToolCalling.mjs +14 -11
  58. package/dist/esm/tools/ProgrammaticToolCalling.mjs.map +1 -1
  59. package/dist/esm/tools/ToolNode.mjs +102 -3
  60. package/dist/esm/tools/ToolNode.mjs.map +1 -1
  61. package/dist/esm/tools/ToolSearch.mjs +827 -0
  62. package/dist/esm/tools/ToolSearch.mjs.map +1 -0
  63. package/dist/types/agents/AgentContext.d.ts +51 -1
  64. package/dist/types/common/enum.d.ts +6 -2
  65. package/dist/types/graphs/Graph.d.ts +12 -0
  66. package/dist/types/graphs/MultiAgentGraph.d.ts +16 -0
  67. package/dist/types/index.d.ts +2 -1
  68. package/dist/types/llm/bedrock/index.d.ts +89 -11
  69. package/dist/types/llm/bedrock/types.d.ts +27 -0
  70. package/dist/types/llm/bedrock/utils/index.d.ts +5 -0
  71. package/dist/types/llm/bedrock/utils/message_inputs.d.ts +31 -0
  72. package/dist/types/llm/bedrock/utils/message_outputs.d.ts +33 -0
  73. package/dist/types/messages/cache.d.ts +4 -1
  74. package/dist/types/schemas/index.d.ts +1 -0
  75. package/dist/types/schemas/validate.d.ts +36 -0
  76. package/dist/types/tools/CodeExecutor.d.ts +0 -3
  77. package/dist/types/tools/ProgrammaticToolCalling.d.ts +0 -3
  78. package/dist/types/tools/ToolNode.d.ts +3 -1
  79. package/dist/types/tools/ToolSearch.d.ts +148 -0
  80. package/dist/types/types/graph.d.ts +71 -0
  81. package/dist/types/types/llm.d.ts +3 -1
  82. package/dist/types/types/tools.d.ts +42 -2
  83. package/package.json +13 -6
  84. package/src/agents/AgentContext.test.ts +312 -0
  85. package/src/agents/AgentContext.ts +144 -16
  86. package/src/common/enum.ts +5 -1
  87. package/src/graphs/Graph.ts +214 -13
  88. package/src/graphs/MultiAgentGraph.ts +350 -13
  89. package/src/index.ts +4 -1
  90. package/src/llm/bedrock/index.ts +221 -99
  91. package/src/llm/bedrock/llm.spec.ts +616 -0
  92. package/src/llm/bedrock/types.ts +51 -0
  93. package/src/llm/bedrock/utils/index.ts +18 -0
  94. package/src/llm/bedrock/utils/message_inputs.ts +563 -0
  95. package/src/llm/bedrock/utils/message_outputs.ts +310 -0
  96. package/src/messages/__tests__/tools.test.ts +21 -21
  97. package/src/messages/cache.test.ts +304 -0
  98. package/src/messages/cache.ts +183 -53
  99. package/src/messages/core.ts +1 -1
  100. package/src/messages/tools.ts +2 -2
  101. package/src/schemas/index.ts +2 -0
  102. package/src/schemas/validate.test.ts +358 -0
  103. package/src/schemas/validate.ts +238 -0
  104. package/src/scripts/caching.ts +27 -19
  105. package/src/scripts/code_exec_files.ts +58 -15
  106. package/src/scripts/code_exec_multi_session.ts +241 -0
  107. package/src/scripts/code_exec_session.ts +282 -0
  108. package/src/scripts/multi-agent-conditional.ts +1 -0
  109. package/src/scripts/multi-agent-supervisor.ts +1 -0
  110. package/src/scripts/programmatic_exec_agent.ts +4 -4
  111. package/src/scripts/test-handoff-preamble.ts +277 -0
  112. package/src/scripts/test-parallel-handoffs.ts +291 -0
  113. package/src/scripts/test-tools-before-handoff.ts +8 -4
  114. package/src/scripts/test_code_api.ts +361 -0
  115. package/src/scripts/thinking-bedrock.ts +159 -0
  116. package/src/scripts/thinking.ts +39 -18
  117. package/src/scripts/{tool_search_regex.ts → tool_search.ts} +5 -5
  118. package/src/scripts/tools.ts +7 -3
  119. package/src/specs/cache.simple.test.ts +396 -0
  120. package/src/stream.ts +4 -2
  121. package/src/tools/BrowserTools.ts +39 -17
  122. package/src/tools/CodeExecutor.ts +26 -23
  123. package/src/tools/ProgrammaticToolCalling.ts +18 -14
  124. package/src/tools/ToolNode.ts +114 -1
  125. package/src/tools/ToolSearch.ts +1041 -0
  126. package/src/tools/__tests__/ProgrammaticToolCalling.test.ts +0 -2
  127. package/src/tools/__tests__/{ToolSearchRegex.integration.test.ts → ToolSearch.integration.test.ts} +6 -6
  128. package/src/tools/__tests__/ToolSearch.test.ts +1003 -0
  129. package/src/types/graph.test.ts +183 -0
  130. package/src/types/graph.ts +73 -0
  131. package/src/types/llm.ts +3 -1
  132. package/src/types/tools.ts +51 -2
  133. package/dist/cjs/tools/ToolSearchRegex.cjs +0 -455
  134. package/dist/cjs/tools/ToolSearchRegex.cjs.map +0 -1
  135. package/dist/esm/tools/ToolSearchRegex.mjs +0 -448
  136. package/dist/esm/tools/ToolSearchRegex.mjs.map +0 -1
  137. package/dist/types/tools/ToolSearchRegex.d.ts +0 -80
  138. package/src/tools/ToolSearchRegex.ts +0 -535
  139. package/src/tools/__tests__/ToolSearchRegex.test.ts +0 -232
@@ -19,7 +19,7 @@ config();
19
19
  const imageMessage = 'Image is already displayed to the user';
20
20
  const otherMessage = 'File is already downloaded by the user';
21
21
  const accessMessage =
22
- 'Note: Files are READ-ONLY. Save changes to NEW filenames. To access these files in future executions, provide the `session_id` as a parameter (not in your code).';
22
+ 'Note: Files from previous executions are automatically available and can be modified.';
23
23
  const emptyOutputMessage =
24
24
  'stdout: Empty. Ensure you\'re writing output explicitly.\n';
25
25
 
@@ -68,12 +68,6 @@ Rules:
68
68
  - Tools are pre-defined—DO NOT write function definitions
69
69
  - Only print() output returns to the model`
70
70
  ),
71
- session_id: z
72
- .string()
73
- .optional()
74
- .describe(
75
- 'Session ID for file access (same as regular code execution). Files load into /mnt/data/ and are READ-ONLY.'
76
- ),
77
71
  timeout: z
78
72
  .number()
79
73
  .int()
@@ -542,7 +536,7 @@ export function formatCompletedResponse(
542
536
  }
543
537
  }
544
538
 
545
- formatted += `\nsession_id: ${response.session_id}\n\n${accessMessage}`;
539
+ formatted += `\n\n${accessMessage}`;
546
540
  }
547
541
 
548
542
  return [
@@ -613,7 +607,7 @@ Rules:
613
607
  - Do NOT define \`async def main()\` or call \`asyncio.run()\`—just write code with await
614
608
  - Tools are pre-defined—DO NOT write function definitions
615
609
  - Only \`print()\` output returns; tool results are raw dicts/lists/strings
616
- - Use \`session_id\` param for file persistence across calls
610
+ - Generated files are automatically available in /mnt/data/ for subsequent executions
617
611
  - Tool names normalized: hyphens→underscores, keywords get \`_tool\` suffix
618
612
 
619
613
  When to use: loops, conditionals, parallel (\`asyncio.gather\`), multi-step pipelines.
@@ -624,11 +618,15 @@ Example (complete pipeline):
624
618
 
625
619
  return tool<typeof ProgrammaticToolCallingSchema>(
626
620
  async (params, config) => {
627
- const { code, session_id, timeout = DEFAULT_TIMEOUT } = params;
621
+ const { code, timeout = DEFAULT_TIMEOUT } = params;
628
622
 
629
623
  // Extra params injected by ToolNode (follows web_search pattern)
630
- const { toolMap, toolDefs } = (config.toolCall ?? {}) as ToolCall &
631
- Partial<t.ProgrammaticCache>;
624
+ const { toolMap, toolDefs, session_id, _injected_files } =
625
+ (config.toolCall ?? {}) as ToolCall &
626
+ Partial<t.ProgrammaticCache> & {
627
+ session_id?: string;
628
+ _injected_files?: t.CodeEnvFile[];
629
+ };
632
630
 
633
631
  if (toolMap == null || toolMap.size === 0) {
634
632
  throw new Error(
@@ -661,9 +659,15 @@ Example (complete pipeline):
661
659
  );
662
660
  }
663
661
 
664
- // Fetch files from previous session if session_id is provided
662
+ /**
663
+ * File injection priority:
664
+ * 1. Use _injected_files from ToolNode (avoids /files endpoint race condition)
665
+ * 2. Fall back to fetching from /files endpoint if session_id provided but no injected files
666
+ */
665
667
  let files: t.CodeEnvFile[] | undefined;
666
- if (session_id != null && session_id.length > 0) {
668
+ if (_injected_files && _injected_files.length > 0) {
669
+ files = _injected_files;
670
+ } else if (session_id != null && session_id.length > 0) {
667
671
  files = await fetchSessionFiles(baseUrl, apiKey, session_id, proxy);
668
672
  }
669
673
 
@@ -80,6 +80,8 @@ export class ToolNode<T = any> extends RunnableCallable<T, T> {
80
80
  private toolRegistry?: t.LCToolRegistry;
81
81
  /** Cached programmatic tools (computed once on first PTC call) */
82
82
  private programmaticCache?: t.ProgrammaticCache;
83
+ /** Reference to Graph's sessions map for automatic session injection */
84
+ private sessions?: t.ToolSessionMap;
83
85
 
84
86
  constructor({
85
87
  tools,
@@ -91,6 +93,7 @@ export class ToolNode<T = any> extends RunnableCallable<T, T> {
91
93
  handleToolErrors,
92
94
  loadRuntimeTools,
93
95
  toolRegistry,
96
+ sessions,
94
97
  }: t.ToolNodeConstructorParams) {
95
98
  super({ name, tags, func: (input, config) => this.run(input, config) });
96
99
  this.toolMap = toolMap ?? new Map(tools.map((tool) => [tool.name, tool]));
@@ -100,6 +103,7 @@ export class ToolNode<T = any> extends RunnableCallable<T, T> {
100
103
  this.errorHandler = errorHandler;
101
104
  this.toolUsageCount = new Map<string, number>();
102
105
  this.toolRegistry = toolRegistry;
106
+ this.sessions = sessions;
103
107
  }
104
108
 
105
109
  /**
@@ -170,13 +174,46 @@ export class ToolNode<T = any> extends RunnableCallable<T, T> {
170
174
  toolMap,
171
175
  toolDefs,
172
176
  };
173
- } else if (call.name === Constants.TOOL_SEARCH_REGEX) {
177
+ } else if (call.name === Constants.TOOL_SEARCH) {
174
178
  invokeParams = {
175
179
  ...invokeParams,
176
180
  toolRegistry: this.toolRegistry,
177
181
  };
178
182
  }
179
183
 
184
+ /**
185
+ * Inject session context for code execution tools when available.
186
+ * Each file uses its own session_id (supporting multi-session file tracking).
187
+ * Both session_id and _injected_files are injected directly to invokeParams
188
+ * (not inside args) so they bypass Zod schema validation and reach config.toolCall.
189
+ */
190
+ if (
191
+ call.name === Constants.EXECUTE_CODE ||
192
+ call.name === Constants.PROGRAMMATIC_TOOL_CALLING
193
+ ) {
194
+ const codeSession = this.sessions?.get(Constants.EXECUTE_CODE) as
195
+ | t.CodeSessionContext
196
+ | undefined;
197
+ if (codeSession?.files != null && codeSession.files.length > 0) {
198
+ /**
199
+ * Convert tracked files to CodeEnvFile format for the API.
200
+ * Each file uses its own session_id (set when file was created).
201
+ * This supports files from multiple parallel/sequential executions.
202
+ */
203
+ const fileRefs: t.CodeEnvFile[] = codeSession.files.map((file) => ({
204
+ session_id: file.session_id ?? codeSession.session_id,
205
+ id: file.id,
206
+ name: file.name,
207
+ }));
208
+ /** Inject latest session_id and files - bypasses Zod, reaches config.toolCall */
209
+ invokeParams = {
210
+ ...invokeParams,
211
+ session_id: codeSession.session_id,
212
+ _injected_files: fileRefs,
213
+ };
214
+ }
215
+ }
216
+
180
217
  const output = await tool.invoke(invokeParams, config);
181
218
 
182
219
  // Handle Command outputs directly
@@ -354,6 +391,13 @@ export class ToolNode<T = any> extends RunnableCallable<T, T> {
354
391
  )[] = [];
355
392
  let parentCommand: Command | null = null;
356
393
 
394
+ /**
395
+ * Collect handoff commands (Commands with string goto and Command.PARENT)
396
+ * for potential parallel handoff aggregation
397
+ */
398
+ const handoffCommands: Command[] = [];
399
+ const nonCommandOutputs: BaseMessage[] = [];
400
+
357
401
  for (const output of outputs) {
358
402
  if (isCommand(output)) {
359
403
  if (
@@ -361,6 +405,7 @@ export class ToolNode<T = any> extends RunnableCallable<T, T> {
361
405
  Array.isArray(output.goto) &&
362
406
  output.goto.every((send): send is Send => isSend(send))
363
407
  ) {
408
+ /** Aggregate Send-based commands */
364
409
  if (parentCommand) {
365
410
  (parentCommand.goto as Send[]).push(...(output.goto as Send[]));
366
411
  } else {
@@ -369,16 +414,84 @@ export class ToolNode<T = any> extends RunnableCallable<T, T> {
369
414
  goto: output.goto,
370
415
  });
371
416
  }
417
+ } else if (output.graph === Command.PARENT) {
418
+ /**
419
+ * Handoff Command with destination.
420
+ * Handle both string ('agent') and array (['agent']) formats.
421
+ * Collect for potential parallel aggregation.
422
+ */
423
+ const goto = output.goto;
424
+ const isSingleStringDest = typeof goto === 'string';
425
+ const isSingleArrayDest =
426
+ Array.isArray(goto) &&
427
+ goto.length === 1 &&
428
+ typeof goto[0] === 'string';
429
+
430
+ if (isSingleStringDest || isSingleArrayDest) {
431
+ handoffCommands.push(output);
432
+ } else {
433
+ /** Multi-destination or other command - pass through */
434
+ combinedOutputs.push(output);
435
+ }
372
436
  } else {
437
+ /** Other commands - pass through */
373
438
  combinedOutputs.push(output);
374
439
  }
375
440
  } else {
441
+ nonCommandOutputs.push(output);
376
442
  combinedOutputs.push(
377
443
  Array.isArray(input) ? [output] : { messages: [output] }
378
444
  );
379
445
  }
380
446
  }
381
447
 
448
+ /**
449
+ * Handle handoff commands - convert to Send objects for parallel execution
450
+ * when multiple handoffs are requested
451
+ */
452
+ if (handoffCommands.length > 1) {
453
+ /**
454
+ * Multiple parallel handoffs - convert to Send objects.
455
+ * Each Send carries its own state with the appropriate messages.
456
+ * This enables LLM-initiated parallel execution when calling multiple
457
+ * transfer tools simultaneously.
458
+ */
459
+
460
+ /** Collect all destinations for sibling tracking */
461
+ const allDestinations = handoffCommands.map((cmd) => {
462
+ const goto = cmd.goto;
463
+ return typeof goto === 'string' ? goto : (goto as string[])[0];
464
+ });
465
+
466
+ const sends = handoffCommands.map((cmd, idx) => {
467
+ const destination = allDestinations[idx];
468
+ /** Get siblings (other destinations, not this one) */
469
+ const siblings = allDestinations.filter((d) => d !== destination);
470
+
471
+ /** Add siblings to ToolMessage additional_kwargs */
472
+ const update = cmd.update as { messages?: BaseMessage[] } | undefined;
473
+ if (update && update.messages) {
474
+ for (const msg of update.messages) {
475
+ if (msg.getType() === 'tool') {
476
+ (msg as ToolMessage).additional_kwargs.handoff_parallel_siblings =
477
+ siblings;
478
+ }
479
+ }
480
+ }
481
+
482
+ return new Send(destination, cmd.update);
483
+ });
484
+
485
+ const parallelCommand = new Command({
486
+ graph: Command.PARENT,
487
+ goto: sends,
488
+ });
489
+ combinedOutputs.push(parallelCommand);
490
+ } else if (handoffCommands.length === 1) {
491
+ /** Single handoff - pass through as-is */
492
+ combinedOutputs.push(handoffCommands[0]);
493
+ }
494
+
382
495
  if (parentCommand) {
383
496
  combinedOutputs.push(parentCommand);
384
497
  }