@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,324 +0,0 @@
1
- import { config } from 'dotenv';
2
- config();
3
- import { HumanMessage } from '@langchain/core/messages';
4
- import { ChatModelStreamHandler, createContentAggregator } from '@/stream';
5
- import { ToolEndHandler, ModelEndHandler } from '@/events';
6
- import { Providers, GraphEvents } from '@/common';
7
- import { sleep } from '@/utils/run';
8
- import { Run } from '@/run';
9
- const conversationHistory = [];
10
- /**
11
- * Example of supervisor-based multi-agent system
12
- *
13
- * The supervisor has handoff tools for 5 different specialists.
14
- * To demonstrate the concept while respecting LangGraph constraints,
15
- * we show two approaches:
16
- *
17
- * 1. All 5 specialists exist but share the same adaptive configuration
18
- * 2. Only 2 agents total by using a single adaptive specialist (requires workaround)
19
- */
20
- async function testSupervisorMultiAgent() {
21
- console.log('Testing Supervisor-Based Multi-Agent System...\n');
22
- // NOTE: To truly have only 2 agents with 5 handoff tools, you would need:
23
- // 1. Custom tool implementation (see multi-agent-supervisor-mock.ts)
24
- // 2. Or modify MultiAgentGraph to support "virtual" agents
25
- // 3. Or use a single conditional edge with role parameter
26
- //
27
- // This example shows the concept using 6 agents that share configuration
28
- // Set up content aggregator
29
- const { contentParts, aggregateContent } = createContentAggregator();
30
- // Define configurations for all possible specialists
31
- const specialistConfigs = {
32
- data_analyst: {
33
- provider: Providers.OPENAI,
34
- clientOptions: {
35
- modelName: 'gpt-4.1',
36
- apiKey: process.env.OPENAI_API_KEY,
37
- },
38
- instructions: `You are a Data Analyst specialist. Your expertise includes:
39
- - Statistical analysis and data visualization
40
- - SQL queries and database optimization
41
- - Python/R for data science
42
- - Machine learning model evaluation
43
- - A/B testing and experiment design
44
-
45
- Follow the supervisor's specific instructions carefully.`,
46
- maxContextTokens: 8000,
47
- },
48
- security_expert: {
49
- provider: Providers.OPENAI,
50
- clientOptions: {
51
- modelName: 'gpt-4.1',
52
- apiKey: process.env.OPENAI_API_KEY,
53
- },
54
- instructions: `You are a Security Expert. Your expertise includes:
55
- - Cybersecurity best practices
56
- - Vulnerability assessment and penetration testing
57
- - Security architecture and threat modeling
58
- - Compliance (GDPR, HIPAA, SOC2, etc.)
59
- - Incident response and forensics
60
-
61
- Follow the supervisor's specific instructions carefully.`,
62
- maxContextTokens: 8000,
63
- },
64
- product_designer: {
65
- provider: Providers.OPENAI,
66
- clientOptions: {
67
- modelName: 'gpt-4.1',
68
- apiKey: process.env.OPENAI_API_KEY,
69
- },
70
- instructions: `You are a Product Designer. Your expertise includes:
71
- - User experience (UX) design principles
72
- - User interface (UI) design and prototyping
73
- - Design systems and component libraries
74
- - User research and usability testing
75
- - Accessibility and inclusive design
76
-
77
- Follow the supervisor's specific instructions carefully.`,
78
- maxContextTokens: 8000,
79
- },
80
- devops_engineer: {
81
- provider: Providers.OPENAI,
82
- clientOptions: {
83
- modelName: 'gpt-4.1',
84
- apiKey: process.env.OPENAI_API_KEY,
85
- },
86
- instructions: `You are a DevOps Engineer. Your expertise includes:
87
- - CI/CD pipeline design and optimization
88
- - Infrastructure as Code (Terraform, CloudFormation)
89
- - Container orchestration (Kubernetes, Docker)
90
- - Cloud platforms (AWS, GCP, Azure)
91
- - Monitoring, logging, and observability
92
-
93
- Follow the supervisor's specific instructions carefully.`,
94
- maxContextTokens: 8000,
95
- },
96
- legal_advisor: {
97
- provider: Providers.OPENAI,
98
- clientOptions: {
99
- modelName: 'gpt-4.1',
100
- apiKey: process.env.OPENAI_API_KEY,
101
- },
102
- instructions: `You are a Legal Advisor specializing in technology. Your expertise includes:
103
- - Software licensing and open source compliance
104
- - Data privacy and protection laws
105
- - Intellectual property and patents
106
- - Contract review and negotiation
107
- - Regulatory compliance for tech companies
108
-
109
- Follow the supervisor's specific instructions carefully.`,
110
- maxContextTokens: 8000,
111
- },
112
- };
113
- // Track which specialist role was selected
114
- let selectedRole = '';
115
- let roleInstructions = '';
116
- // Create custom handlers
117
- const customHandlers = {
118
- [GraphEvents.TOOL_END]: new ToolEndHandler(),
119
- [GraphEvents.CHAT_MODEL_END]: new ModelEndHandler(),
120
- [GraphEvents.CHAT_MODEL_STREAM]: new ChatModelStreamHandler(),
121
- [GraphEvents.ON_RUN_STEP]: {
122
- handle: (event, data) => {
123
- const runStepData = data;
124
- if (runStepData?.name) {
125
- console.log(`\n[${runStepData.name}] Processing...`);
126
- }
127
- aggregateContent({ event, data: data });
128
- },
129
- },
130
- [GraphEvents.ON_RUN_STEP_COMPLETED]: {
131
- handle: (event, data) => {
132
- aggregateContent({
133
- event,
134
- data: data,
135
- });
136
- },
137
- },
138
- [GraphEvents.ON_MESSAGE_DELTA]: {
139
- handle: (event, data) => {
140
- console.dir(data, { depth: null });
141
- aggregateContent({ event, data: data });
142
- },
143
- },
144
- [GraphEvents.TOOL_START]: {
145
- handle: (_event, data, metadata) => {
146
- const toolData = data;
147
- if (toolData?.name?.includes('transfer_to_')) {
148
- const specialist = toolData.name.replace('transfer_to_', '');
149
- console.log(`\n🔀 Transferring to ${specialist}...`);
150
- selectedRole = specialist;
151
- }
152
- },
153
- },
154
- };
155
- // Function to create the graph with supervisor having multiple handoff options
156
- function createSupervisorGraph() {
157
- console.log(`\nCreating graph with supervisor and 5 specialist agents.`);
158
- console.log('All specialists share the same adaptive configuration.\n');
159
- // Define the adaptive specialist configuration that will be reused
160
- const specialistConfig = {
161
- provider: Providers.OPENAI,
162
- clientOptions: {
163
- modelName: 'gpt-4.1',
164
- apiKey: process.env.OPENAI_API_KEY,
165
- },
166
- instructions: `You are an Adaptive Specialist. Your agent ID indicates your role:
167
-
168
- - data_analyst: Focus on statistical analysis, metrics, ML evaluation, A/B testing
169
- - security_expert: Focus on cybersecurity, vulnerability assessment, compliance
170
- - product_designer: Focus on UX/UI design, user research, accessibility
171
- - devops_engineer: Focus on CI/CD, infrastructure, cloud platforms, monitoring
172
- - legal_advisor: Focus on licensing, privacy laws, contracts, regulatory compliance
173
-
174
- The supervisor will provide specific instructions. Follow them while maintaining your expert perspective.`,
175
- maxContextTokens: 8000,
176
- };
177
- // Create the graph with supervisor and all 5 specialists
178
- // All specialists share the same adaptive configuration
179
- const agents = [
180
- {
181
- agentId: 'supervisor',
182
- provider: Providers.OPENAI,
183
- clientOptions: {
184
- modelName: 'gpt-4.1-mini',
185
- apiKey: process.env.OPENAI_API_KEY,
186
- },
187
- instructions: `You are a Task Supervisor with access to 5 specialist agents:
188
- 1. transfer_to_data_analyst - For statistical analysis and metrics
189
- 2. transfer_to_security_expert - For cybersecurity and vulnerability assessment
190
- 3. transfer_to_product_designer - For UX/UI design
191
- 4. transfer_to_devops_engineer - For infrastructure and deployment
192
- 5. transfer_to_legal_advisor - For compliance and licensing
193
-
194
- Your role is to:
195
- 1. Analyze the incoming request
196
- 2. Decide which specialist is best suited
197
- 3. Use the appropriate transfer tool (e.g., transfer_to_data_analyst)
198
- 4. Provide specific instructions to guide their work
199
-
200
- Be specific about what you need from the specialist.`,
201
- maxContextTokens: 8000,
202
- },
203
- // Include all 5 specialists with the same adaptive configuration
204
- {
205
- agentId: 'data_analyst',
206
- ...specialistConfig,
207
- },
208
- {
209
- agentId: 'security_expert',
210
- ...specialistConfig,
211
- },
212
- {
213
- agentId: 'product_designer',
214
- ...specialistConfig,
215
- },
216
- {
217
- agentId: 'devops_engineer',
218
- ...specialistConfig,
219
- },
220
- {
221
- agentId: 'legal_advisor',
222
- ...specialistConfig,
223
- },
224
- ];
225
- // Create edges from supervisor to all 5 specialists
226
- const edges = [
227
- {
228
- from: 'supervisor',
229
- to: 'data_analyst',
230
- description: 'Transfer to data analyst for statistical analysis and metrics',
231
- edgeType: 'transfer',
232
- },
233
- {
234
- from: 'supervisor',
235
- to: 'security_expert',
236
- description: 'Transfer to security expert for cybersecurity assessment',
237
- edgeType: 'transfer',
238
- },
239
- {
240
- from: 'supervisor',
241
- to: 'product_designer',
242
- description: 'Transfer to product designer for UX/UI design',
243
- edgeType: 'transfer',
244
- },
245
- {
246
- from: 'supervisor',
247
- to: 'devops_engineer',
248
- description: 'Transfer to DevOps engineer for infrastructure and deployment',
249
- edgeType: 'transfer',
250
- },
251
- {
252
- from: 'supervisor',
253
- to: 'legal_advisor',
254
- description: 'Transfer to legal advisor for compliance and licensing',
255
- edgeType: 'transfer',
256
- },
257
- ];
258
- return {
259
- runId: `supervisor-multi-agent-${Date.now()}`,
260
- graphConfig: {
261
- type: 'multi-agent',
262
- agents,
263
- edges,
264
- },
265
- customHandlers,
266
- returnContent: true,
267
- skipCleanup: true,
268
- };
269
- }
270
- try {
271
- // Test with different queries
272
- const testQueries = [
273
- 'How can we analyze user engagement metrics to improve our product?',
274
- // 'What security measures should we implement for our new API?',
275
- // 'Can you help design a better onboarding flow for our mobile app?',
276
- // 'We need to set up a CI/CD pipeline for our microservices.',
277
- // 'What are the legal implications of using GPL-licensed code in our product?',
278
- ];
279
- const config = {
280
- configurable: {
281
- thread_id: 'supervisor-conversation-1',
282
- },
283
- streamMode: 'values',
284
- version: 'v2',
285
- };
286
- for (const query of testQueries) {
287
- console.log(`\n${'='.repeat(60)}`);
288
- console.log(`USER QUERY: "${query}"`);
289
- console.log('='.repeat(60));
290
- // Reset conversation
291
- conversationHistory.length = 0;
292
- conversationHistory.push(new HumanMessage(query));
293
- // Create graph with supervisor having 5 handoff tools to 1 adaptive specialist
294
- const runConfig = createSupervisorGraph();
295
- const run = await Run.create(runConfig);
296
- console.log('Processing request...');
297
- // Process with streaming
298
- const inputs = {
299
- messages: conversationHistory,
300
- };
301
- const finalContentParts = await run.processStream(inputs, config);
302
- const finalMessages = run.getRunMessages();
303
- if (finalMessages) {
304
- conversationHistory.push(...finalMessages);
305
- }
306
- // Show summary
307
- console.log(`\n${'─'.repeat(60)}`);
308
- console.log(`Agents in graph: 6 total (supervisor + 5 specialists)`);
309
- console.log(`All specialists share the same adaptive configuration`);
310
- console.log(`Supervisor tools: transfer_to_data_analyst, transfer_to_security_expert,`);
311
- console.log(` transfer_to_product_designer, transfer_to_devops_engineer,`);
312
- console.log(` transfer_to_legal_advisor`);
313
- console.log('─'.repeat(60));
314
- console.dir(contentParts, { depth: null });
315
- }
316
- await sleep(3000);
317
- }
318
- catch (error) {
319
- console.error('Error in supervisor multi-agent test:', error);
320
- }
321
- }
322
- // Run the test
323
- testSupervisorMultiAgent();
324
- //# sourceMappingURL=multi-agent-supervisor.js.map
@@ -1,147 +0,0 @@
1
- import { config } from 'dotenv';
2
- config();
3
- import { HumanMessage } from '@langchain/core/messages';
4
- import { Run } from '@/run';
5
- import { Providers, GraphEvents } from '@/common';
6
- import { ChatModelStreamHandler, createContentAggregator } from '@/stream';
7
- import { ToolEndHandler, ModelEndHandler } from '@/events';
8
- const conversationHistory = [];
9
- async function testMultiAgentHandoff() {
10
- console.log('Testing Multi-Agent Handoff System...\n');
11
- // Set up content aggregator
12
- const { contentParts, aggregateContent } = createContentAggregator();
13
- // Define agent configurations
14
- const agents = [
15
- {
16
- agentId: 'flight_assistant',
17
- provider: Providers.ANTHROPIC,
18
- clientOptions: {
19
- modelName: 'claude-haiku-4-5',
20
- apiKey: process.env.ANTHROPIC_API_KEY,
21
- },
22
- instructions: 'You are a flight booking assistant. Help users book flights between airports.',
23
- maxContextTokens: 28000,
24
- },
25
- {
26
- agentId: 'hotel_assistant',
27
- provider: Providers.ANTHROPIC,
28
- clientOptions: {
29
- modelName: 'claude-haiku-4-5',
30
- apiKey: process.env.ANTHROPIC_API_KEY,
31
- },
32
- instructions: 'You are a hotel booking assistant. Help users book hotel stays.',
33
- maxContextTokens: 28000,
34
- },
35
- ];
36
- // Define edges (handoff relationships)
37
- // These edges create handoff tools that agents can use to transfer control dynamically
38
- const edges = [
39
- {
40
- from: 'flight_assistant',
41
- to: 'hotel_assistant',
42
- description: 'Transfer to hotel booking assistant when user needs hotel assistance',
43
- // edgeType defaults to 'handoff' for single-to-single edges
44
- },
45
- {
46
- from: 'hotel_assistant',
47
- to: 'flight_assistant',
48
- description: 'Transfer to flight booking assistant when user needs flight assistance',
49
- // edgeType defaults to 'handoff' for single-to-single edges
50
- },
51
- ];
52
- // Create custom handlers similar to examples
53
- const customHandlers = {
54
- [GraphEvents.TOOL_END]: new ToolEndHandler(),
55
- [GraphEvents.CHAT_MODEL_END]: new ModelEndHandler(),
56
- [GraphEvents.CHAT_MODEL_STREAM]: new ChatModelStreamHandler(),
57
- [GraphEvents.ON_RUN_STEP_COMPLETED]: {
58
- handle: (event, data) => {
59
- console.log('====== ON_RUN_STEP_COMPLETED ======');
60
- console.dir(data, { depth: null });
61
- aggregateContent({
62
- event,
63
- data: data,
64
- });
65
- },
66
- },
67
- [GraphEvents.ON_RUN_STEP]: {
68
- handle: (event, data) => {
69
- console.log('====== ON_RUN_STEP ======');
70
- console.dir(data, { depth: null });
71
- aggregateContent({ event, data: data });
72
- },
73
- },
74
- [GraphEvents.ON_RUN_STEP_DELTA]: {
75
- handle: (event, data) => {
76
- console.log('====== ON_RUN_STEP_DELTA ======');
77
- console.dir(data, { depth: null });
78
- aggregateContent({ event, data: data });
79
- },
80
- },
81
- [GraphEvents.ON_MESSAGE_DELTA]: {
82
- handle: (event, data) => {
83
- console.log('====== ON_MESSAGE_DELTA ======');
84
- console.dir(data, { depth: null });
85
- aggregateContent({ event, data: data });
86
- },
87
- },
88
- [GraphEvents.ON_REASONING_DELTA]: {
89
- handle: (event, data) => {
90
- console.log('====== ON_REASONING_DELTA ======');
91
- console.dir(data, { depth: null });
92
- aggregateContent({ event, data: data });
93
- },
94
- },
95
- [GraphEvents.TOOL_START]: {
96
- handle: (_event, data, metadata) => {
97
- console.log('====== TOOL_START ======');
98
- console.dir(data, { depth: null });
99
- },
100
- },
101
- };
102
- // Create multi-agent run configuration
103
- const runConfig = {
104
- runId: `multi-agent-test-${Date.now()}`,
105
- graphConfig: {
106
- type: 'multi-agent',
107
- agents,
108
- edges,
109
- },
110
- customHandlers,
111
- returnContent: true,
112
- skipCleanup: true,
113
- };
114
- try {
115
- // Create and execute the run
116
- const run = await Run.create(runConfig);
117
- const userMessage = 'I need to book a flight from Boston to New York, and also need a hotel near Times Square.';
118
- conversationHistory.push(new HumanMessage(userMessage));
119
- console.log('Invoking multi-agent graph...\n');
120
- const config = {
121
- configurable: {
122
- thread_id: 'multi-agent-conversation-1',
123
- },
124
- streamMode: 'values',
125
- version: 'v2',
126
- };
127
- // Process with streaming
128
- const inputs = {
129
- messages: conversationHistory,
130
- };
131
- const finalContentParts = await run.processStream(inputs, config);
132
- const finalMessages = run.getRunMessages();
133
- if (finalMessages) {
134
- conversationHistory.push(...finalMessages);
135
- console.log('\n\nConversation history:');
136
- console.dir(conversationHistory, { depth: null });
137
- }
138
- console.log('\n\nFinal content parts:');
139
- console.dir(contentParts, { depth: null });
140
- }
141
- catch (error) {
142
- console.error('Error in multi-agent test:', error);
143
- }
144
- }
145
- // Run the test
146
- testMultiAgentHandoff();
147
- //# sourceMappingURL=multi-agent-test.js.map
@@ -1,202 +0,0 @@
1
- import { config } from 'dotenv';
2
- config();
3
- import { HumanMessage } from '@langchain/core/messages';
4
- import { ChatModelStreamHandler, createContentAggregator } from '@/stream';
5
- import { Providers, GraphEvents } from '@/common';
6
- import { sleep } from '@/utils/run';
7
- import { Run } from '@/run';
8
- import { Calculator } from '@/tools/Calculator';
9
- const conversationHistory = [];
10
- /**
11
- * Test ASYMMETRIC parallel execution:
12
- * - agent1: NO tools (will finish quickly in step 1)
13
- * - agent2: HAS tools (will go step 1 → step 2 → step 3)
14
- *
15
- * This tests whether langgraph_step can still detect parallel execution
16
- * when agents have different tool-calling patterns.
17
- */
18
- async function testAsymmetricParallelTools() {
19
- console.log('Testing ASYMMETRIC Parallel Agents (one with tools, one without)...\n');
20
- const { contentParts, aggregateContent } = createContentAggregator();
21
- // Track metadata for analysis
22
- const metadataLog = [];
23
- const startTime = Date.now();
24
- // Define two agents - one WITH tools, one WITHOUT
25
- const agents = [
26
- {
27
- agentId: 'simple_agent',
28
- provider: Providers.ANTHROPIC,
29
- clientOptions: {
30
- modelName: 'claude-haiku-4-5',
31
- apiKey: process.env.ANTHROPIC_API_KEY,
32
- },
33
- // NO TOOLS - will complete in single step
34
- instructions: `You are a simple assistant. Just answer the question directly in 1-2 sentences. Start with "🗣️ SIMPLE:". Do NOT try to use any tools.`,
35
- },
36
- {
37
- agentId: 'math_agent',
38
- provider: Providers.ANTHROPIC,
39
- clientOptions: {
40
- modelName: 'claude-haiku-4-5',
41
- apiKey: process.env.ANTHROPIC_API_KEY,
42
- },
43
- tools: [new Calculator()],
44
- instructions: `You are a MATH SPECIALIST. ALWAYS use the calculator tool to perform calculations, even simple ones. Start your response with "🧮 MATH:". Keep your response concise.`,
45
- },
46
- ];
47
- // No edges - both run in parallel from start
48
- const edges = [];
49
- const agentTimings = {};
50
- // Helper to log metadata
51
- const logMetadata = (eventName, metadata) => {
52
- if (metadata) {
53
- const entry = {
54
- event: eventName,
55
- langgraph_step: metadata.langgraph_step,
56
- langgraph_node: metadata.langgraph_node,
57
- timestamp: Date.now() - startTime,
58
- };
59
- metadataLog.push(entry);
60
- console.log(`📊 [${entry.timestamp}ms] ${eventName}: step=${entry.langgraph_step}, node=${entry.langgraph_node}`);
61
- }
62
- };
63
- const customHandlers = {
64
- [GraphEvents.TOOL_END]: {
65
- handle: (_event, data, metadata) => {
66
- console.log('\n====== TOOL_END ======');
67
- logMetadata('TOOL_END', metadata);
68
- },
69
- },
70
- [GraphEvents.TOOL_START]: {
71
- handle: (_event, _data, metadata) => {
72
- console.log('\n====== TOOL_START ======');
73
- logMetadata('TOOL_START', metadata);
74
- },
75
- },
76
- [GraphEvents.CHAT_MODEL_END]: {
77
- handle: (_event, _data, metadata) => {
78
- console.log('\n====== CHAT_MODEL_END ======');
79
- logMetadata('CHAT_MODEL_END', metadata);
80
- const nodeName = metadata?.langgraph_node;
81
- if (nodeName) {
82
- const elapsed = Date.now() - startTime;
83
- agentTimings[nodeName] = agentTimings[nodeName] || {};
84
- agentTimings[nodeName].end = elapsed;
85
- }
86
- },
87
- },
88
- [GraphEvents.CHAT_MODEL_START]: {
89
- handle: (_event, _data, metadata) => {
90
- console.log('\n====== CHAT_MODEL_START ======');
91
- logMetadata('CHAT_MODEL_START', metadata);
92
- const nodeName = metadata?.langgraph_node;
93
- if (nodeName) {
94
- const elapsed = Date.now() - startTime;
95
- agentTimings[nodeName] = agentTimings[nodeName] || {};
96
- if (!agentTimings[nodeName].start) {
97
- agentTimings[nodeName].start = elapsed;
98
- }
99
- }
100
- },
101
- },
102
- [GraphEvents.CHAT_MODEL_STREAM]: new ChatModelStreamHandler(),
103
- [GraphEvents.ON_RUN_STEP]: {
104
- handle: (event, data, metadata) => {
105
- console.log('\n====== ON_RUN_STEP ======');
106
- logMetadata('ON_RUN_STEP', metadata);
107
- aggregateContent({ event, data: data });
108
- },
109
- },
110
- [GraphEvents.ON_RUN_STEP_DELTA]: {
111
- handle: (event, data, metadata) => {
112
- // Don't log these to reduce noise
113
- aggregateContent({ event, data: data });
114
- },
115
- },
116
- [GraphEvents.ON_MESSAGE_DELTA]: {
117
- handle: (event, data, metadata) => {
118
- // Don't log these to reduce noise
119
- aggregateContent({ event, data: data });
120
- },
121
- },
122
- };
123
- const runConfig = {
124
- runId: `asymmetric-parallel-${Date.now()}`,
125
- graphConfig: {
126
- type: 'multi-agent',
127
- agents,
128
- edges,
129
- },
130
- customHandlers,
131
- returnContent: true,
132
- skipCleanup: true,
133
- };
134
- try {
135
- const run = await Run.create(runConfig);
136
- // Ask a question that will trigger only the math agent to use tools
137
- const userMessage = `What is 42 * 17?`;
138
- conversationHistory.push(new HumanMessage(userMessage));
139
- console.log('User message:', userMessage);
140
- console.log('\nExpected behavior:');
141
- console.log(' - simple_agent: Step 1 only (no tools)');
142
- console.log(' - math_agent: Step 1 → Step 2 (tool) → Step 3 (response)');
143
- console.log('\n');
144
- const config = {
145
- configurable: {
146
- thread_id: 'asymmetric-test-1',
147
- },
148
- streamMode: 'values',
149
- version: 'v2',
150
- };
151
- const inputs = {
152
- messages: conversationHistory,
153
- };
154
- await run.processStream(inputs, config);
155
- // Analysis
156
- console.log('\n\n========== METADATA ANALYSIS ==========');
157
- console.log('\nAll events by step and node:');
158
- console.table(metadataLog);
159
- // Group by step
160
- const stepGroups = new Map();
161
- for (const entry of metadataLog) {
162
- if (!stepGroups.has(entry.langgraph_step)) {
163
- stepGroups.set(entry.langgraph_step, new Map());
164
- }
165
- const nodeMap = stepGroups.get(entry.langgraph_step);
166
- if (!nodeMap.has(entry.langgraph_node)) {
167
- nodeMap.set(entry.langgraph_node, []);
168
- }
169
- nodeMap.get(entry.langgraph_node).push(entry.event);
170
- }
171
- console.log('\n\n========== STEP BREAKDOWN ==========');
172
- for (const [step, nodeMap] of stepGroups) {
173
- console.log(`\nStep ${step}:`);
174
- for (const [node, events] of nodeMap) {
175
- console.log(` ${node}: ${events.join(', ')}`);
176
- }
177
- console.log(` → ${nodeMap.size} unique node(s) at this step`);
178
- }
179
- console.log('\n\n========== PARALLEL DETECTION CHALLENGE ==========');
180
- console.log('\nAt which steps can we detect parallel execution?');
181
- for (const [step, nodeMap] of stepGroups) {
182
- if (nodeMap.size > 1) {
183
- console.log(` ✅ Step ${step}: ${nodeMap.size} agents detected - PARALLEL`);
184
- }
185
- else {
186
- const [nodeName] = nodeMap.keys();
187
- console.log(` ⚠️ Step ${step}: Only 1 agent (${nodeName}) - looks sequential!`);
188
- }
189
- }
190
- console.log('\n\n========== KEY INSIGHT ==========');
191
- console.log('If we only look at step 2 or 3, we miss the parallel context!');
192
- console.log('We need to detect parallelism EARLY (at step 1) and carry that forward.');
193
- console.log('\n\nFinal content parts:');
194
- console.dir(contentParts, { depth: null });
195
- await sleep(2000);
196
- }
197
- catch (error) {
198
- console.error('Error:', error);
199
- }
200
- }
201
- testAsymmetricParallelTools();
202
- //# sourceMappingURL=parallel-asymmetric-tools-test.js.map