@illuma-ai/agents 1.1.21 → 1.1.23

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 (244) 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 +105 -1
  4. package/dist/cjs/graphs/MultiAgentGraph.cjs.map +1 -1
  5. package/dist/cjs/run.cjs +20 -9
  6. package/dist/cjs/run.cjs.map +1 -1
  7. package/dist/cjs/utils/llm.cjs.map +1 -1
  8. package/dist/esm/graphs/Graph.mjs +12 -1
  9. package/dist/esm/graphs/Graph.mjs.map +1 -1
  10. package/dist/esm/graphs/MultiAgentGraph.mjs +105 -1
  11. package/dist/esm/graphs/MultiAgentGraph.mjs.map +1 -1
  12. package/dist/esm/run.mjs +20 -9
  13. package/dist/esm/run.mjs.map +1 -1
  14. package/dist/esm/utils/llm.mjs.map +1 -1
  15. package/dist/types/graphs/MultiAgentGraph.d.ts +17 -0
  16. package/package.json +1 -1
  17. package/src/graphs/Graph.ts +13 -1
  18. package/src/graphs/MultiAgentGraph.ts +128 -1
  19. package/src/graphs/__tests__/multi-agent-delegate.test.ts +205 -0
  20. package/src/run.ts +20 -11
  21. package/src/scripts/test-bedrock-handoff-autonomous.ts +231 -0
  22. package/src/utils/llm.ts +1 -0
  23. package/src/agents/AgentContext.js +0 -782
  24. package/src/agents/AgentContext.test.js +0 -421
  25. package/src/agents/__tests__/AgentContext.test.js +0 -678
  26. package/src/agents/__tests__/resolveStructuredOutputMode.test.js +0 -117
  27. package/src/common/enum.js +0 -192
  28. package/src/common/index.js +0 -3
  29. package/src/events.js +0 -166
  30. package/src/graphs/Graph.js +0 -1857
  31. package/src/graphs/MultiAgentGraph.js +0 -1092
  32. package/src/graphs/__tests__/structured-output.integration.test.js +0 -624
  33. package/src/graphs/__tests__/structured-output.test.js +0 -144
  34. package/src/graphs/contextManagement.e2e.test.js +0 -718
  35. package/src/graphs/contextManagement.test.js +0 -485
  36. package/src/graphs/handoffValidation.test.js +0 -276
  37. package/src/graphs/index.js +0 -3
  38. package/src/index.js +0 -28
  39. package/src/instrumentation.js +0 -21
  40. package/src/llm/anthropic/index.js +0 -319
  41. package/src/llm/anthropic/types.js +0 -46
  42. package/src/llm/anthropic/utils/message_inputs.js +0 -627
  43. package/src/llm/anthropic/utils/message_outputs.js +0 -290
  44. package/src/llm/anthropic/utils/output_parsers.js +0 -89
  45. package/src/llm/anthropic/utils/tools.js +0 -25
  46. package/src/llm/bedrock/__tests__/bedrock-caching.test.js +0 -392
  47. package/src/llm/bedrock/index.js +0 -303
  48. package/src/llm/bedrock/types.js +0 -2
  49. package/src/llm/bedrock/utils/index.js +0 -6
  50. package/src/llm/bedrock/utils/message_inputs.js +0 -463
  51. package/src/llm/bedrock/utils/message_outputs.js +0 -269
  52. package/src/llm/fake.js +0 -92
  53. package/src/llm/google/index.js +0 -215
  54. package/src/llm/google/types.js +0 -12
  55. package/src/llm/google/utils/common.js +0 -670
  56. package/src/llm/google/utils/tools.js +0 -111
  57. package/src/llm/google/utils/zod_to_genai_parameters.js +0 -47
  58. package/src/llm/openai/index.js +0 -1033
  59. package/src/llm/openai/types.js +0 -2
  60. package/src/llm/openai/utils/index.js +0 -756
  61. package/src/llm/openai/utils/isReasoningModel.test.js +0 -79
  62. package/src/llm/openrouter/index.js +0 -261
  63. package/src/llm/openrouter/reasoning.test.js +0 -181
  64. package/src/llm/providers.js +0 -36
  65. package/src/llm/text.js +0 -65
  66. package/src/llm/vertexai/index.js +0 -402
  67. package/src/messages/__tests__/tools.test.js +0 -392
  68. package/src/messages/cache.js +0 -404
  69. package/src/messages/cache.test.js +0 -1167
  70. package/src/messages/content.js +0 -48
  71. package/src/messages/content.test.js +0 -314
  72. package/src/messages/core.js +0 -359
  73. package/src/messages/ensureThinkingBlock.test.js +0 -997
  74. package/src/messages/format.js +0 -973
  75. package/src/messages/formatAgentMessages.test.js +0 -2278
  76. package/src/messages/formatAgentMessages.tools.test.js +0 -362
  77. package/src/messages/formatMessage.test.js +0 -608
  78. package/src/messages/ids.js +0 -18
  79. package/src/messages/index.js +0 -9
  80. package/src/messages/labelContentByAgent.test.js +0 -725
  81. package/src/messages/prune.js +0 -438
  82. package/src/messages/reducer.js +0 -60
  83. package/src/messages/shiftIndexTokenCountMap.test.js +0 -63
  84. package/src/messages/summarize.js +0 -146
  85. package/src/messages/summarize.test.js +0 -332
  86. package/src/messages/tools.js +0 -90
  87. package/src/mockStream.js +0 -81
  88. package/src/prompts/collab.js +0 -7
  89. package/src/prompts/index.js +0 -3
  90. package/src/prompts/taskmanager.js +0 -58
  91. package/src/run.js +0 -427
  92. package/src/schemas/index.js +0 -3
  93. package/src/schemas/schema-preparation.test.js +0 -370
  94. package/src/schemas/validate.js +0 -314
  95. package/src/schemas/validate.test.js +0 -264
  96. package/src/scripts/abort.js +0 -127
  97. package/src/scripts/ant_web_search.js +0 -130
  98. package/src/scripts/ant_web_search_edge_case.js +0 -133
  99. package/src/scripts/ant_web_search_error_edge_case.js +0 -119
  100. package/src/scripts/args.js +0 -41
  101. package/src/scripts/bedrock-cache-debug.js +0 -186
  102. package/src/scripts/bedrock-content-aggregation-test.js +0 -195
  103. package/src/scripts/bedrock-merge-test.js +0 -80
  104. package/src/scripts/bedrock-parallel-tools-test.js +0 -150
  105. package/src/scripts/caching.js +0 -106
  106. package/src/scripts/cli.js +0 -152
  107. package/src/scripts/cli2.js +0 -119
  108. package/src/scripts/cli3.js +0 -163
  109. package/src/scripts/cli4.js +0 -165
  110. package/src/scripts/cli5.js +0 -165
  111. package/src/scripts/code_exec.js +0 -171
  112. package/src/scripts/code_exec_files.js +0 -180
  113. package/src/scripts/code_exec_multi_session.js +0 -185
  114. package/src/scripts/code_exec_ptc.js +0 -265
  115. package/src/scripts/code_exec_session.js +0 -217
  116. package/src/scripts/code_exec_simple.js +0 -120
  117. package/src/scripts/content.js +0 -111
  118. package/src/scripts/empty_input.js +0 -125
  119. package/src/scripts/handoff-test.js +0 -96
  120. package/src/scripts/image.js +0 -138
  121. package/src/scripts/memory.js +0 -83
  122. package/src/scripts/multi-agent-chain.js +0 -271
  123. package/src/scripts/multi-agent-conditional.js +0 -185
  124. package/src/scripts/multi-agent-document-review-chain.js +0 -171
  125. package/src/scripts/multi-agent-hybrid-flow.js +0 -264
  126. package/src/scripts/multi-agent-parallel-start.js +0 -214
  127. package/src/scripts/multi-agent-parallel.js +0 -346
  128. package/src/scripts/multi-agent-sequence.js +0 -184
  129. package/src/scripts/multi-agent-supervisor.js +0 -324
  130. package/src/scripts/multi-agent-test.js +0 -147
  131. package/src/scripts/parallel-asymmetric-tools-test.js +0 -202
  132. package/src/scripts/parallel-full-metadata-test.js +0 -176
  133. package/src/scripts/parallel-tools-test.js +0 -256
  134. package/src/scripts/programmatic_exec.js +0 -277
  135. package/src/scripts/programmatic_exec_agent.js +0 -168
  136. package/src/scripts/search.js +0 -118
  137. package/src/scripts/sequential-full-metadata-test.js +0 -143
  138. package/src/scripts/simple.js +0 -174
  139. package/src/scripts/single-agent-metadata-test.js +0 -152
  140. package/src/scripts/stream.js +0 -113
  141. package/src/scripts/test-custom-prompt-key.js +0 -132
  142. package/src/scripts/test-handoff-input.js +0 -143
  143. package/src/scripts/test-handoff-preamble.js +0 -227
  144. package/src/scripts/test-handoff-steering.js +0 -353
  145. package/src/scripts/test-multi-agent-list-handoff.js +0 -318
  146. package/src/scripts/test-parallel-agent-labeling.js +0 -253
  147. package/src/scripts/test-parallel-handoffs.js +0 -229
  148. package/src/scripts/test-thinking-handoff-bedrock.js +0 -132
  149. package/src/scripts/test-thinking-handoff.js +0 -132
  150. package/src/scripts/test-thinking-to-thinking-handoff-bedrock.js +0 -140
  151. package/src/scripts/test-tool-before-handoff-role-order.js +0 -223
  152. package/src/scripts/test-tools-before-handoff.js +0 -187
  153. package/src/scripts/test_code_api.js +0 -263
  154. package/src/scripts/thinking-bedrock.js +0 -128
  155. package/src/scripts/thinking-vertexai.js +0 -130
  156. package/src/scripts/thinking.js +0 -134
  157. package/src/scripts/tool_search.js +0 -114
  158. package/src/scripts/tools.js +0 -125
  159. package/src/specs/agent-handoffs-bedrock.integration.test.js +0 -280
  160. package/src/specs/agent-handoffs.test.js +0 -924
  161. package/src/specs/anthropic.simple.test.js +0 -287
  162. package/src/specs/azure.simple.test.js +0 -381
  163. package/src/specs/cache.simple.test.js +0 -282
  164. package/src/specs/custom-event-await.test.js +0 -148
  165. package/src/specs/deepseek.simple.test.js +0 -189
  166. package/src/specs/emergency-prune.test.js +0 -308
  167. package/src/specs/moonshot.simple.test.js +0 -237
  168. package/src/specs/observability.integration.test.js +0 -1337
  169. package/src/specs/openai.simple.test.js +0 -233
  170. package/src/specs/openrouter.simple.test.js +0 -202
  171. package/src/specs/prune.test.js +0 -733
  172. package/src/specs/reasoning.test.js +0 -144
  173. package/src/specs/spec.utils.js +0 -4
  174. package/src/specs/thinking-handoff.test.js +0 -486
  175. package/src/specs/thinking-prune.test.js +0 -600
  176. package/src/specs/token-distribution-edge-case.test.js +0 -246
  177. package/src/specs/token-memoization.test.js +0 -32
  178. package/src/specs/tokens.test.js +0 -49
  179. package/src/specs/tool-error.test.js +0 -139
  180. package/src/splitStream.js +0 -204
  181. package/src/splitStream.test.js +0 -504
  182. package/src/stream.js +0 -650
  183. package/src/stream.test.js +0 -225
  184. package/src/test/mockTools.js +0 -340
  185. package/src/tools/BrowserTools.js +0 -245
  186. package/src/tools/Calculator.js +0 -38
  187. package/src/tools/Calculator.test.js +0 -225
  188. package/src/tools/CodeExecutor.js +0 -233
  189. package/src/tools/ProgrammaticToolCalling.js +0 -602
  190. package/src/tools/StreamingToolCallBuffer.js +0 -179
  191. package/src/tools/ToolNode.js +0 -930
  192. package/src/tools/ToolSearch.js +0 -904
  193. package/src/tools/__tests__/BrowserTools.test.js +0 -306
  194. package/src/tools/__tests__/ProgrammaticToolCalling.integration.test.js +0 -276
  195. package/src/tools/__tests__/ProgrammaticToolCalling.test.js +0 -807
  196. package/src/tools/__tests__/StreamingToolCallBuffer.test.js +0 -175
  197. package/src/tools/__tests__/ToolApproval.test.js +0 -675
  198. package/src/tools/__tests__/ToolNode.recovery.test.js +0 -200
  199. package/src/tools/__tests__/ToolNode.session.test.js +0 -319
  200. package/src/tools/__tests__/ToolSearch.integration.test.js +0 -125
  201. package/src/tools/__tests__/ToolSearch.test.js +0 -812
  202. package/src/tools/__tests__/handlers.test.js +0 -799
  203. package/src/tools/__tests__/truncation-recovery.integration.test.js +0 -362
  204. package/src/tools/handlers.js +0 -306
  205. package/src/tools/schema.js +0 -25
  206. package/src/tools/search/anthropic.js +0 -34
  207. package/src/tools/search/content.js +0 -116
  208. package/src/tools/search/content.test.js +0 -133
  209. package/src/tools/search/firecrawl.js +0 -173
  210. package/src/tools/search/format.js +0 -198
  211. package/src/tools/search/highlights.js +0 -241
  212. package/src/tools/search/index.js +0 -3
  213. package/src/tools/search/jina-reranker.test.js +0 -106
  214. package/src/tools/search/rerankers.js +0 -165
  215. package/src/tools/search/schema.js +0 -102
  216. package/src/tools/search/search.js +0 -561
  217. package/src/tools/search/serper-scraper.js +0 -126
  218. package/src/tools/search/test.js +0 -129
  219. package/src/tools/search/tool.js +0 -453
  220. package/src/tools/search/types.js +0 -2
  221. package/src/tools/search/utils.js +0 -59
  222. package/src/types/graph.js +0 -24
  223. package/src/types/graph.test.js +0 -192
  224. package/src/types/index.js +0 -7
  225. package/src/types/llm.js +0 -2
  226. package/src/types/messages.js +0 -2
  227. package/src/types/run.js +0 -2
  228. package/src/types/stream.js +0 -2
  229. package/src/types/tools.js +0 -2
  230. package/src/utils/contextAnalytics.js +0 -79
  231. package/src/utils/contextAnalytics.test.js +0 -166
  232. package/src/utils/events.js +0 -26
  233. package/src/utils/graph.js +0 -11
  234. package/src/utils/handlers.js +0 -65
  235. package/src/utils/index.js +0 -10
  236. package/src/utils/llm.js +0 -21
  237. package/src/utils/llmConfig.js +0 -205
  238. package/src/utils/logging.js +0 -37
  239. package/src/utils/misc.js +0 -51
  240. package/src/utils/run.js +0 -69
  241. package/src/utils/schema.js +0 -21
  242. package/src/utils/title.js +0 -119
  243. package/src/utils/tokens.js +0 -92
  244. package/src/utils/toonFormat.js +0 -379
@@ -1,277 +0,0 @@
1
- // src/scripts/programmatic_exec.ts
2
- /**
3
- * Test script for Programmatic Tool Calling (PTC).
4
- * Run with: npm run programmatic_exec
5
- *
6
- * Demonstrates:
7
- * 1. Runtime toolMap injection - the tool map is passed at invocation time
8
- * 2. Tool classification with allowed_callers (inspired by Anthropic's API)
9
- * - 'direct': Tool can only be called directly by the LLM (default)
10
- * - 'code_execution': Tool can only be called from within PTC
11
- * - Both: Tool can be called either way
12
- *
13
- * IMPORTANT: The Python code passed to PTC should NOT define the tool functions.
14
- * The Code API automatically generates async function stubs from the tool definitions.
15
- * The code should just CALL the tools as if they're already available:
16
- * - result = await get_weather(city="SF")
17
- * - results = await asyncio.gather(tool1(), tool2())
18
- */
19
- import { config } from 'dotenv';
20
- config();
21
- import { createProgrammaticToolCallingTool } from '@/tools/ProgrammaticToolCalling';
22
- import { createGetTeamMembersTool, createGetExpensesTool, createGetWeatherTool, createCalculatorTool, createProgrammaticToolRegistry, } from '@/test/mockTools';
23
- async function runTest(ptcTool, testName, code, options) {
24
- console.log(`\n${'='.repeat(70)}`);
25
- console.log(`TEST: ${testName}`);
26
- console.log('='.repeat(70));
27
- console.log('\nCode:');
28
- console.log('```python');
29
- console.log(code.trim());
30
- console.log('```\n');
31
- try {
32
- const startTime = Date.now();
33
- // Manual testing: schema params + extras (LangChain moves extras to config.toolCall)
34
- const result = await ptcTool.invoke({
35
- code,
36
- tools: options.tools,
37
- session_id: options.session_id,
38
- timeout: options.timeout,
39
- toolMap: options.toolMap, // Non-schema field → config.toolCall.toolMap
40
- });
41
- const duration = Date.now() - startTime;
42
- console.log(`Result (${duration}ms):`);
43
- if (Array.isArray(result)) {
44
- console.log(result[0]);
45
- if (options.showArtifact) {
46
- console.log('\n--- Artifact ---');
47
- console.dir(result[1], { depth: null });
48
- }
49
- }
50
- else {
51
- console.log(result);
52
- }
53
- }
54
- catch (error) {
55
- console.error('Error:', error instanceof Error ? error.message : error);
56
- }
57
- }
58
- // ============================================================================
59
- // Main
60
- // ============================================================================
61
- async function main() {
62
- console.log('Programmatic Tool Calling (PTC) - Test Script');
63
- console.log('==============================================');
64
- console.log('Demonstrating runtime toolMap injection\n');
65
- const apiKey = process.env.CODE_EXECUTOR_API_KEY;
66
- if (!apiKey) {
67
- console.error('Error: CODE_EXECUTOR_API_KEY environment variable is not set.');
68
- console.log('Please set it in your .env file or environment.');
69
- process.exit(1);
70
- }
71
- console.log('Creating mock tools...');
72
- const mockTools = [
73
- createGetTeamMembersTool(),
74
- createGetExpensesTool(),
75
- createGetWeatherTool(),
76
- createCalculatorTool(),
77
- ];
78
- const toolMap = new Map(mockTools.map((t) => [t.name, t]));
79
- const toolDefinitions = Array.from(createProgrammaticToolRegistry().values());
80
- console.log(`ToolMap contains ${toolMap.size} tools: ${Array.from(toolMap.keys()).join(', ')}`);
81
- console.log('\nCreating PTC tool (without toolMap)...');
82
- const ptcTool = createProgrammaticToolCallingTool({ apiKey });
83
- console.log('PTC tool created successfully!');
84
- console.log('Note: toolMap will be passed at runtime with each invocation.\n');
85
- const baseOptions = { toolMap, tools: toolDefinitions };
86
- // =========================================================================
87
- // Test 1: Simple async tool call
88
- // =========================================================================
89
- await runTest(ptcTool, 'Simple async tool call', `
90
- # Tools are auto-generated as async functions - just await them
91
- result = await get_weather(city="San Francisco")
92
- print(f"Weather in SF: {result['temperature']}°F, {result['condition']}")
93
- `, { ...baseOptions, showArtifact: true });
94
- // =========================================================================
95
- // Test 2: Sequential loop with await
96
- // =========================================================================
97
- await runTest(ptcTool, 'Sequential loop - Process team expenses', `
98
- # Each tool call uses await
99
- team = await get_team_members()
100
- print("Team expense report:")
101
- print("-" * 30)
102
- total = 0
103
- for member in team:
104
- expenses = await get_expenses(user_id=member['id'])
105
- member_total = sum(e['amount'] for e in expenses)
106
- total += member_total
107
- print(f"{member['name']}: \${member_total:.2f}")
108
- print("-" * 30)
109
- print(f"Total: \${total:.2f}")
110
- `, baseOptions);
111
- // =========================================================================
112
- // Test 3: Parallel execution with asyncio.gather
113
- // =========================================================================
114
- await runTest(ptcTool, 'Parallel execution - Weather for multiple cities', `
115
- # Use asyncio.gather for parallel tool calls - single round-trip!
116
- import asyncio
117
-
118
- cities = ["San Francisco", "New York", "London"]
119
- results = await asyncio.gather(*[
120
- get_weather(city=city)
121
- for city in cities
122
- ])
123
-
124
- print("Weather report:")
125
- for city, weather in zip(cities, results):
126
- print(f" {city}: {weather['temperature']}°F, {weather['condition']}")
127
- `, baseOptions);
128
- // =========================================================================
129
- // Test 4: Chained dependencies
130
- // =========================================================================
131
- await runTest(ptcTool, 'Chained dependencies - Get team then process each', `
132
- # Get team first, then fetch expenses for each
133
- team = await get_team_members()
134
- engineering = [m for m in team if m['department'] == 'Engineering']
135
-
136
- print(f"Engineering team ({len(engineering)} members):")
137
- for member in engineering:
138
- expenses = await get_expenses(user_id=member['id'])
139
- equipment = sum(e['amount'] for e in expenses if e['category'] == 'equipment')
140
- print(f" {member['name']}: \${equipment:.2f} on equipment")
141
- `, baseOptions);
142
- // =========================================================================
143
- // Test 5: Conditional logic
144
- // =========================================================================
145
- await runTest(ptcTool, 'Conditional logic - Find high spenders', `
146
- team = await get_team_members()
147
- high_spenders = []
148
-
149
- for member in team:
150
- expenses = await get_expenses(user_id=member['id'])
151
- total = sum(e['amount'] for e in expenses)
152
- if total > 300:
153
- high_spenders.append((member['name'], total))
154
-
155
- if high_spenders:
156
- print("High spenders (over $300):")
157
- for name, amount in sorted(high_spenders, key=lambda x: x[1], reverse=True):
158
- print(f" {name}: \${amount:.2f}")
159
- else:
160
- print("No high spenders found.")
161
- `, baseOptions);
162
- // =========================================================================
163
- // Test 6: Mixed parallel and sequential
164
- // =========================================================================
165
- await runTest(ptcTool, 'Mixed - Parallel expense fetch after sequential team fetch', `
166
- import asyncio
167
-
168
- # Step 1: Get team (one tool call)
169
- team = await get_team_members()
170
- print(f"Fetched {len(team)} team members")
171
-
172
- # Step 2: Get all expenses in parallel (single round-trip for all!)
173
- all_expenses = await asyncio.gather(*[
174
- get_expenses(user_id=member['id'])
175
- for member in team
176
- ])
177
-
178
- # Step 3: Process and output
179
- print("\\nExpense summary:")
180
- for member, expenses in zip(team, all_expenses):
181
- total = sum(e['amount'] for e in expenses)
182
- print(f" {member['name']}: \${total:.2f} ({len(expenses)} items)")
183
- `, baseOptions);
184
- // =========================================================================
185
- // Test 7: Calculator usage
186
- // =========================================================================
187
- await runTest(ptcTool, 'Calculator tool usage', `
188
- # All tools are async - use await
189
- result1 = await calculator(expression="2 + 2 * 3")
190
- result2 = await calculator(expression="(10 + 5) / 3")
191
-
192
- print(f"2 + 2 * 3 = {result1['result']}")
193
- print(f"(10 + 5) / 3 = {result2['result']:.2f}")
194
- `, baseOptions);
195
- // =========================================================================
196
- // Test 8: Error handling in code
197
- // =========================================================================
198
- await runTest(ptcTool, 'Error handling - Invalid city', `
199
- # Tool errors become Python exceptions - handle with try/except
200
- cities = ["San Francisco", "InvalidCity", "New York"]
201
-
202
- for city in cities:
203
- try:
204
- weather = await get_weather(city=city)
205
- print(f"{city}: {weather['temperature']}°F")
206
- except Exception as e:
207
- print(f"{city}: Error - {e}")
208
- `, baseOptions);
209
- // =========================================================================
210
- // Test 9: Early termination
211
- // =========================================================================
212
- await runTest(ptcTool, 'Early termination - Stop when condition met', `
213
- # Stop as soon as we find what we need - no wasted tool calls
214
- team = await get_team_members()
215
-
216
- for member in team:
217
- expenses = await get_expenses(user_id=member['id'])
218
- if any(e['category'] == 'equipment' for e in expenses):
219
- print(f"First team member with equipment expense: {member['name']}")
220
- equipment_total = sum(e['amount'] for e in expenses if e['category'] == 'equipment')
221
- print(f"Equipment total: \${equipment_total:.2f}")
222
- break
223
- else:
224
- print("No team member has equipment expenses")
225
- `, baseOptions);
226
- // =========================================================================
227
- // Test 10: Subset of tools
228
- // =========================================================================
229
- await runTest(ptcTool, 'Subset of tools - Only weather', `
230
- # Only the weather tool is available in this execution
231
- import asyncio
232
-
233
- sf, nyc = await asyncio.gather(
234
- get_weather(city="San Francisco"),
235
- get_weather(city="New York")
236
- )
237
- print(f"SF: {sf['temperature']}°F vs NYC: {nyc['temperature']}°F")
238
- difference = abs(sf['temperature'] - nyc['temperature'])
239
- print(f"Temperature difference: {difference}°F")
240
- `, {
241
- ...baseOptions,
242
- tools: [toolDefinitions.find((t) => t.name === 'get_weather')],
243
- });
244
- // =========================================================================
245
- // Test 11: Note about ToolNode injection
246
- // =========================================================================
247
- console.log(`\n${'='.repeat(70)}`);
248
- console.log('NOTE: ToolNode Runtime Injection');
249
- console.log('='.repeat(70));
250
- console.log('\nWhen PTC is invoked through ToolNode in a real agent:\n' +
251
- '- ToolNode detects call.name === "run_tools_with_code"\n' +
252
- '- ToolNode injects: { ...invokeParams, toolMap, toolDefs }\n' +
253
- '- PTC tool extracts these from params (not from config)\n' +
254
- '- No explicit tools parameter needed in schema\n\n' +
255
- 'This test demonstrates param injection with explicit tools:\n');
256
- await runTest(ptcTool, 'Runtime injection with explicit tools', `
257
- # ToolNode would inject toolMap+toolDefs
258
- # For this test, we pass tools explicitly (same effect)
259
- team = await get_team_members()
260
- print(f"Team size: {len(team)}")
261
- for member in team:
262
- print(f"- {member['name']} ({member['department']})")
263
- `, baseOptions);
264
- console.log('\n' + '='.repeat(70));
265
- console.log('All tests completed!');
266
- console.log('='.repeat(70) + '\n');
267
- console.log('Summary of allowed_callers patterns:');
268
- console.log('- get_team_members, get_expenses, calculator: code_execution only');
269
- console.log('- get_weather: both direct and code_execution');
270
- console.log('\nIn a real agent setup, the LLM would only see tools with allowed_callers');
271
- console.log('including "direct", while PTC can call any tool with "code_execution".\n');
272
- }
273
- main().catch((err) => {
274
- console.error('Fatal error:', err);
275
- process.exit(1);
276
- });
277
- //# sourceMappingURL=programmatic_exec.js.map
@@ -1,168 +0,0 @@
1
- // src/scripts/programmatic_exec_agent.ts
2
- /**
3
- * Test script for Programmatic Tool Calling (PTC) with agent integration.
4
- * Run with: npm run programmatic_exec_agent
5
- *
6
- * Demonstrates:
7
- * 1. Tool classification with allowed_callers:
8
- * - direct: Tool bound to LLM (can be called directly)
9
- * - code_execution: Tool available for PTC (not bound to LLM)
10
- * - Both: Tool bound to LLM AND available for PTC
11
- * 2. Deferred loading with defer_loading: true (for tool search)
12
- * 3. Agent-level tool configuration via toolRegistry
13
- * 4. ToolNode runtime injection of programmatic tools
14
- *
15
- * This shows the real-world integration pattern with agents.
16
- */
17
- import { config } from 'dotenv';
18
- config();
19
- import { HumanMessage } from '@langchain/core/messages';
20
- import { createCodeExecutionTool } from '@/tools/CodeExecutor';
21
- import { createProgrammaticToolCallingTool } from '@/tools/ProgrammaticToolCalling';
22
- import { createToolSearch } from '@/tools/ToolSearch';
23
- import { getLLMConfig } from '@/utils/llmConfig';
24
- import { getArgs } from '@/scripts/args';
25
- import { Run } from '@/run';
26
- import { createGetTeamMembersTool, createGetExpensesTool, createGetWeatherTool, createProgrammaticToolRegistry, } from '@/test/mockTools';
27
- // ============================================================================
28
- // Tool Registry (Metadata)
29
- // ============================================================================
30
- /**
31
- * Tool registry only needs business logic tools that require filtering.
32
- * Special tools (execute_code, run_tools_with_code, tool_search)
33
- * are always bound directly to the LLM and don't need registry entries.
34
- */
35
- function createAgentToolRegistry() {
36
- // Use shared programmatic tool registry (get_team_members, get_expenses, etc.)
37
- return createProgrammaticToolRegistry();
38
- }
39
- // ============================================================================
40
- // Main
41
- // ============================================================================
42
- const conversationHistory = [];
43
- async function main() {
44
- console.log('Programmatic Tool Calling - Agent Integration Test');
45
- console.log('===================================================\n');
46
- const { userName, location, provider } = await getArgs();
47
- const llmConfig = getLLMConfig(provider);
48
- // Create all tool instances
49
- const mockTools = [
50
- createGetTeamMembersTool(),
51
- createGetExpensesTool(),
52
- createGetWeatherTool(),
53
- ];
54
- const toolMap = new Map(mockTools.map((t) => [t.name, t]));
55
- // Create special tools (PTC, code execution, tool search)
56
- const codeExecTool = createCodeExecutionTool();
57
- const ptcTool = createProgrammaticToolCallingTool();
58
- const toolSearchTool = createToolSearch();
59
- // Build complete tool list and map
60
- const allTools = [...mockTools, codeExecTool, ptcTool, toolSearchTool];
61
- const completeToolMap = new Map(allTools.map((t) => [t.name, t]));
62
- // Create tool registry with allowed_callers configuration
63
- // Only includes business logic tools (not special tools like execute_code, PTC, tool_search)
64
- const toolRegistry = createAgentToolRegistry();
65
- console.log('Tool configuration:');
66
- console.log('- Total tools:', allTools.length);
67
- console.log('- Programmatic-allowed:', Array.from(toolRegistry.values())
68
- .filter((t) => t.allowed_callers?.includes('code_execution'))
69
- .map((t) => t.name)
70
- .join(', '));
71
- console.log('- Direct-only:', Array.from(toolRegistry.values())
72
- .filter((t) => !t.allowed_callers ||
73
- (t.allowed_callers.includes('direct') &&
74
- !t.allowed_callers.includes('code_execution')))
75
- .map((t) => t.name)
76
- .join(', '));
77
- console.log('- Both:', Array.from(toolRegistry.values())
78
- .filter((t) => t.allowed_callers?.includes('direct') &&
79
- t.allowed_callers?.includes('code_execution'))
80
- .map((t) => t.name)
81
- .join(', '));
82
- // Create run with toolRegistry configuration
83
- const run = await Run.create({
84
- runId: 'ptc-agent-test',
85
- graphConfig: {
86
- type: 'standard',
87
- llmConfig,
88
- agents: [
89
- {
90
- agentId: 'default',
91
- provider: llmConfig.provider,
92
- clientOptions: llmConfig,
93
- tools: allTools,
94
- toolMap: completeToolMap,
95
- toolRegistry, // Pass tool registry for programmatic/deferred tool config
96
- instructions: 'You are an AI assistant with access to programmatic tool calling. ' +
97
- 'When you need to process multiple items or perform complex data operations, ' +
98
- 'use the run_tools_with_code tool to write Python code that calls tools efficiently.',
99
- },
100
- ],
101
- },
102
- returnContent: true,
103
- skipCleanup: true,
104
- });
105
- const config = {
106
- configurable: {
107
- provider,
108
- thread_id: 'ptc-test-conversation',
109
- },
110
- streamMode: 'values',
111
- version: 'v2',
112
- };
113
- console.log('\n' + '='.repeat(70));
114
- console.log('Test: Process team expenses using PTC');
115
- console.log('='.repeat(70) + '\n');
116
- const userMessage = new HumanMessage(`Hi! I need you to analyze our team's expenses. Please:
117
- 1. Get the list of team members
118
- 2. For each member, get their expense records
119
- 3. Calculate the total expenses per member
120
- 4. Identify anyone who spent more than $300
121
- 5. Show me the results in a nice format
122
-
123
- Use the run_tools_with_code tool to do this efficiently - don't call each tool separately!`);
124
- conversationHistory.push(userMessage);
125
- const inputs = {
126
- messages: conversationHistory,
127
- };
128
- console.log('Running agent with PTC capability...\n');
129
- const finalContentParts = await run.processStream(inputs, config);
130
- const finalMessages = run.getRunMessages();
131
- if (finalMessages) {
132
- conversationHistory.push(...finalMessages);
133
- }
134
- console.log('\n' + '='.repeat(70));
135
- console.log('Agent Response:');
136
- console.log('='.repeat(70));
137
- if (finalContentParts) {
138
- for (const part of finalContentParts) {
139
- if (part?.type === 'text' && part.text) {
140
- console.log(part.text);
141
- }
142
- }
143
- }
144
- console.log('\n' + '='.repeat(70));
145
- console.log('Test completed successfully!');
146
- console.log('='.repeat(70));
147
- console.log('\nKey observations:');
148
- console.log('1. LLM only sees tools with allowed_callers including "direct" (get_weather, execute_code, run_tools_with_code, tool_search)');
149
- console.log('2. When PTC is invoked, ToolNode automatically injects programmatic tools (get_team_members, get_expenses, get_weather)');
150
- console.log('3. No need to manually configure runtime toolMap - handled by agent context');
151
- console.log('4. Tool filtering based on allowed_callers happens automatically\n');
152
- }
153
- process.on('unhandledRejection', (reason, promise) => {
154
- console.error('Unhandled Rejection at:', promise, 'reason:', reason);
155
- console.log('Conversation history:');
156
- console.dir(conversationHistory, { depth: null });
157
- process.exit(1);
158
- });
159
- process.on('uncaughtException', (err) => {
160
- console.error('Uncaught Exception:', err);
161
- });
162
- main().catch((err) => {
163
- console.error('Fatal error:', err);
164
- console.log('Conversation history:');
165
- console.dir(conversationHistory, { depth: null });
166
- process.exit(1);
167
- });
168
- //# sourceMappingURL=programmatic_exec_agent.js.map
@@ -1,118 +0,0 @@
1
- /* eslint-disable no-console */
2
- // src/scripts/cli.ts
3
- import { config } from 'dotenv';
4
- config();
5
- import { HumanMessage } from '@langchain/core/messages';
6
- import { ChatModelStreamHandler, createContentAggregator } from '@/stream';
7
- import { ToolEndHandler, ModelEndHandler } from '@/events';
8
- import { createSearchTool } from '@/tools/search';
9
- import { getArgs } from '@/scripts/args';
10
- import { Run } from '@/run';
11
- import { GraphEvents, Providers } from '@/common';
12
- import { getLLMConfig } from '@/utils/llmConfig';
13
- const conversationHistory = [];
14
- async function testStandardStreaming() {
15
- const { userName, location, provider, currentDate } = await getArgs();
16
- const { contentParts, aggregateContent } = createContentAggregator();
17
- const customHandlers = {
18
- [GraphEvents.TOOL_END]: new ToolEndHandler(),
19
- [GraphEvents.CHAT_MODEL_END]: new ModelEndHandler(),
20
- [GraphEvents.CHAT_MODEL_STREAM]: new ChatModelStreamHandler(),
21
- [GraphEvents.ON_RUN_STEP_COMPLETED]: {
22
- handle: (event, data) => {
23
- console.log('====== ON_RUN_STEP_COMPLETED ======');
24
- // console.dir(data, { depth: null });
25
- aggregateContent({
26
- event,
27
- data: data,
28
- });
29
- },
30
- },
31
- [GraphEvents.ON_RUN_STEP]: {
32
- handle: (event, data) => {
33
- aggregateContent({ event, data: data });
34
- },
35
- },
36
- [GraphEvents.ON_RUN_STEP_DELTA]: {
37
- handle: (event, data) => {
38
- aggregateContent({ event, data: data });
39
- },
40
- },
41
- [GraphEvents.ON_MESSAGE_DELTA]: {
42
- handle: (event, data) => {
43
- aggregateContent({ event, data: data });
44
- },
45
- },
46
- [GraphEvents.TOOL_START]: {
47
- handle: (_event, data, metadata) => {
48
- console.log('====== TOOL_START ======');
49
- // console.dir(data, { depth: null });
50
- },
51
- },
52
- };
53
- const llmConfig = getLLMConfig(provider);
54
- if (llmConfig.provider === Providers.BEDROCK) {
55
- llmConfig.promptCache = true;
56
- }
57
- const run = await Run.create({
58
- runId: 'test-run-id',
59
- graphConfig: {
60
- type: 'standard',
61
- llmConfig,
62
- tools: [
63
- createSearchTool({
64
- scraperProvider: 'serper',
65
- }),
66
- ],
67
- instructions: 'You are a friendly AI assistant. Always address the user by their name.',
68
- // additional_instructions: `The user's name is ${userName} and they are located in ${location}.`,
69
- },
70
- returnContent: true,
71
- skipCleanup: true,
72
- customHandlers,
73
- });
74
- const config = {
75
- configurable: {
76
- provider,
77
- thread_id: 'conversation-num-1',
78
- },
79
- streamMode: 'values',
80
- version: 'v2',
81
- };
82
- console.log('Test 1: Search query (search tool test)');
83
- // const userMessage = `
84
- // Make a search for the weather in ${location} today, which is ${currentDate}.
85
- // Before making the search, please let me know what you're about to do, then immediately start searching without hesitation.
86
- // Make sure to always refer to me by name, which is ${userName}.
87
- // After giving me a thorough summary, tell me a joke about the weather forecast we went over.
88
- // `;
89
- // const userMessage = 'Are massage guns good?';
90
- // const userMessage = 'What is functional programming?';
91
- const userMessage = "Get me today's trending news.";
92
- // const userMessage = "search recent italy earthquake volcano activity";
93
- // const userMessage =
94
- // "use 'Trump' as the exact search query and tell me what you find.";
95
- conversationHistory.push(new HumanMessage(userMessage));
96
- const inputs = {
97
- messages: conversationHistory,
98
- };
99
- const finalContentParts = await run.processStream(inputs, config);
100
- const finalMessages = run.getRunMessages();
101
- if (finalMessages) {
102
- conversationHistory.push(...finalMessages);
103
- console.dir(conversationHistory, { depth: null });
104
- }
105
- // console.dir(finalContentParts, { depth: null });
106
- console.log('\n\n====================\n\n');
107
- // console.dir(contentParts, { depth: null });
108
- }
109
- process.on('unhandledRejection', (reason, promise) => {
110
- console.warn('Unhandled Rejection (non-fatal):', reason);
111
- });
112
- testStandardStreaming().catch((err) => {
113
- console.error(err);
114
- console.log('Conversation history:');
115
- console.dir(conversationHistory, { depth: null });
116
- process.exit(1);
117
- });
118
- //# sourceMappingURL=search.js.map