@illuma-ai/agents 1.1.21 → 1.1.22

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (241) hide show
  1. package/dist/cjs/graphs/Graph.cjs +12 -1
  2. package/dist/cjs/graphs/Graph.cjs.map +1 -1
  3. package/dist/cjs/graphs/MultiAgentGraph.cjs +85 -1
  4. package/dist/cjs/graphs/MultiAgentGraph.cjs.map +1 -1
  5. package/dist/cjs/run.cjs +20 -9
  6. package/dist/cjs/run.cjs.map +1 -1
  7. package/dist/esm/graphs/Graph.mjs +12 -1
  8. package/dist/esm/graphs/Graph.mjs.map +1 -1
  9. package/dist/esm/graphs/MultiAgentGraph.mjs +85 -1
  10. package/dist/esm/graphs/MultiAgentGraph.mjs.map +1 -1
  11. package/dist/esm/run.mjs +20 -9
  12. package/dist/esm/run.mjs.map +1 -1
  13. package/dist/types/graphs/MultiAgentGraph.d.ts +17 -0
  14. package/package.json +1 -1
  15. package/src/graphs/Graph.ts +12 -1
  16. package/src/graphs/MultiAgentGraph.ts +105 -1
  17. package/src/graphs/__tests__/multi-agent-delegate.test.ts +191 -0
  18. package/src/run.ts +20 -11
  19. package/src/scripts/test-bedrock-handoff-autonomous.ts +231 -0
  20. package/src/agents/AgentContext.js +0 -782
  21. package/src/agents/AgentContext.test.js +0 -421
  22. package/src/agents/__tests__/AgentContext.test.js +0 -678
  23. package/src/agents/__tests__/resolveStructuredOutputMode.test.js +0 -117
  24. package/src/common/enum.js +0 -192
  25. package/src/common/index.js +0 -3
  26. package/src/events.js +0 -166
  27. package/src/graphs/Graph.js +0 -1857
  28. package/src/graphs/MultiAgentGraph.js +0 -1092
  29. package/src/graphs/__tests__/structured-output.integration.test.js +0 -624
  30. package/src/graphs/__tests__/structured-output.test.js +0 -144
  31. package/src/graphs/contextManagement.e2e.test.js +0 -718
  32. package/src/graphs/contextManagement.test.js +0 -485
  33. package/src/graphs/handoffValidation.test.js +0 -276
  34. package/src/graphs/index.js +0 -3
  35. package/src/index.js +0 -28
  36. package/src/instrumentation.js +0 -21
  37. package/src/llm/anthropic/index.js +0 -319
  38. package/src/llm/anthropic/types.js +0 -46
  39. package/src/llm/anthropic/utils/message_inputs.js +0 -627
  40. package/src/llm/anthropic/utils/message_outputs.js +0 -290
  41. package/src/llm/anthropic/utils/output_parsers.js +0 -89
  42. package/src/llm/anthropic/utils/tools.js +0 -25
  43. package/src/llm/bedrock/__tests__/bedrock-caching.test.js +0 -392
  44. package/src/llm/bedrock/index.js +0 -303
  45. package/src/llm/bedrock/types.js +0 -2
  46. package/src/llm/bedrock/utils/index.js +0 -6
  47. package/src/llm/bedrock/utils/message_inputs.js +0 -463
  48. package/src/llm/bedrock/utils/message_outputs.js +0 -269
  49. package/src/llm/fake.js +0 -92
  50. package/src/llm/google/index.js +0 -215
  51. package/src/llm/google/types.js +0 -12
  52. package/src/llm/google/utils/common.js +0 -670
  53. package/src/llm/google/utils/tools.js +0 -111
  54. package/src/llm/google/utils/zod_to_genai_parameters.js +0 -47
  55. package/src/llm/openai/index.js +0 -1033
  56. package/src/llm/openai/types.js +0 -2
  57. package/src/llm/openai/utils/index.js +0 -756
  58. package/src/llm/openai/utils/isReasoningModel.test.js +0 -79
  59. package/src/llm/openrouter/index.js +0 -261
  60. package/src/llm/openrouter/reasoning.test.js +0 -181
  61. package/src/llm/providers.js +0 -36
  62. package/src/llm/text.js +0 -65
  63. package/src/llm/vertexai/index.js +0 -402
  64. package/src/messages/__tests__/tools.test.js +0 -392
  65. package/src/messages/cache.js +0 -404
  66. package/src/messages/cache.test.js +0 -1167
  67. package/src/messages/content.js +0 -48
  68. package/src/messages/content.test.js +0 -314
  69. package/src/messages/core.js +0 -359
  70. package/src/messages/ensureThinkingBlock.test.js +0 -997
  71. package/src/messages/format.js +0 -973
  72. package/src/messages/formatAgentMessages.test.js +0 -2278
  73. package/src/messages/formatAgentMessages.tools.test.js +0 -362
  74. package/src/messages/formatMessage.test.js +0 -608
  75. package/src/messages/ids.js +0 -18
  76. package/src/messages/index.js +0 -9
  77. package/src/messages/labelContentByAgent.test.js +0 -725
  78. package/src/messages/prune.js +0 -438
  79. package/src/messages/reducer.js +0 -60
  80. package/src/messages/shiftIndexTokenCountMap.test.js +0 -63
  81. package/src/messages/summarize.js +0 -146
  82. package/src/messages/summarize.test.js +0 -332
  83. package/src/messages/tools.js +0 -90
  84. package/src/mockStream.js +0 -81
  85. package/src/prompts/collab.js +0 -7
  86. package/src/prompts/index.js +0 -3
  87. package/src/prompts/taskmanager.js +0 -58
  88. package/src/run.js +0 -427
  89. package/src/schemas/index.js +0 -3
  90. package/src/schemas/schema-preparation.test.js +0 -370
  91. package/src/schemas/validate.js +0 -314
  92. package/src/schemas/validate.test.js +0 -264
  93. package/src/scripts/abort.js +0 -127
  94. package/src/scripts/ant_web_search.js +0 -130
  95. package/src/scripts/ant_web_search_edge_case.js +0 -133
  96. package/src/scripts/ant_web_search_error_edge_case.js +0 -119
  97. package/src/scripts/args.js +0 -41
  98. package/src/scripts/bedrock-cache-debug.js +0 -186
  99. package/src/scripts/bedrock-content-aggregation-test.js +0 -195
  100. package/src/scripts/bedrock-merge-test.js +0 -80
  101. package/src/scripts/bedrock-parallel-tools-test.js +0 -150
  102. package/src/scripts/caching.js +0 -106
  103. package/src/scripts/cli.js +0 -152
  104. package/src/scripts/cli2.js +0 -119
  105. package/src/scripts/cli3.js +0 -163
  106. package/src/scripts/cli4.js +0 -165
  107. package/src/scripts/cli5.js +0 -165
  108. package/src/scripts/code_exec.js +0 -171
  109. package/src/scripts/code_exec_files.js +0 -180
  110. package/src/scripts/code_exec_multi_session.js +0 -185
  111. package/src/scripts/code_exec_ptc.js +0 -265
  112. package/src/scripts/code_exec_session.js +0 -217
  113. package/src/scripts/code_exec_simple.js +0 -120
  114. package/src/scripts/content.js +0 -111
  115. package/src/scripts/empty_input.js +0 -125
  116. package/src/scripts/handoff-test.js +0 -96
  117. package/src/scripts/image.js +0 -138
  118. package/src/scripts/memory.js +0 -83
  119. package/src/scripts/multi-agent-chain.js +0 -271
  120. package/src/scripts/multi-agent-conditional.js +0 -185
  121. package/src/scripts/multi-agent-document-review-chain.js +0 -171
  122. package/src/scripts/multi-agent-hybrid-flow.js +0 -264
  123. package/src/scripts/multi-agent-parallel-start.js +0 -214
  124. package/src/scripts/multi-agent-parallel.js +0 -346
  125. package/src/scripts/multi-agent-sequence.js +0 -184
  126. package/src/scripts/multi-agent-supervisor.js +0 -324
  127. package/src/scripts/multi-agent-test.js +0 -147
  128. package/src/scripts/parallel-asymmetric-tools-test.js +0 -202
  129. package/src/scripts/parallel-full-metadata-test.js +0 -176
  130. package/src/scripts/parallel-tools-test.js +0 -256
  131. package/src/scripts/programmatic_exec.js +0 -277
  132. package/src/scripts/programmatic_exec_agent.js +0 -168
  133. package/src/scripts/search.js +0 -118
  134. package/src/scripts/sequential-full-metadata-test.js +0 -143
  135. package/src/scripts/simple.js +0 -174
  136. package/src/scripts/single-agent-metadata-test.js +0 -152
  137. package/src/scripts/stream.js +0 -113
  138. package/src/scripts/test-custom-prompt-key.js +0 -132
  139. package/src/scripts/test-handoff-input.js +0 -143
  140. package/src/scripts/test-handoff-preamble.js +0 -227
  141. package/src/scripts/test-handoff-steering.js +0 -353
  142. package/src/scripts/test-multi-agent-list-handoff.js +0 -318
  143. package/src/scripts/test-parallel-agent-labeling.js +0 -253
  144. package/src/scripts/test-parallel-handoffs.js +0 -229
  145. package/src/scripts/test-thinking-handoff-bedrock.js +0 -132
  146. package/src/scripts/test-thinking-handoff.js +0 -132
  147. package/src/scripts/test-thinking-to-thinking-handoff-bedrock.js +0 -140
  148. package/src/scripts/test-tool-before-handoff-role-order.js +0 -223
  149. package/src/scripts/test-tools-before-handoff.js +0 -187
  150. package/src/scripts/test_code_api.js +0 -263
  151. package/src/scripts/thinking-bedrock.js +0 -128
  152. package/src/scripts/thinking-vertexai.js +0 -130
  153. package/src/scripts/thinking.js +0 -134
  154. package/src/scripts/tool_search.js +0 -114
  155. package/src/scripts/tools.js +0 -125
  156. package/src/specs/agent-handoffs-bedrock.integration.test.js +0 -280
  157. package/src/specs/agent-handoffs.test.js +0 -924
  158. package/src/specs/anthropic.simple.test.js +0 -287
  159. package/src/specs/azure.simple.test.js +0 -381
  160. package/src/specs/cache.simple.test.js +0 -282
  161. package/src/specs/custom-event-await.test.js +0 -148
  162. package/src/specs/deepseek.simple.test.js +0 -189
  163. package/src/specs/emergency-prune.test.js +0 -308
  164. package/src/specs/moonshot.simple.test.js +0 -237
  165. package/src/specs/observability.integration.test.js +0 -1337
  166. package/src/specs/openai.simple.test.js +0 -233
  167. package/src/specs/openrouter.simple.test.js +0 -202
  168. package/src/specs/prune.test.js +0 -733
  169. package/src/specs/reasoning.test.js +0 -144
  170. package/src/specs/spec.utils.js +0 -4
  171. package/src/specs/thinking-handoff.test.js +0 -486
  172. package/src/specs/thinking-prune.test.js +0 -600
  173. package/src/specs/token-distribution-edge-case.test.js +0 -246
  174. package/src/specs/token-memoization.test.js +0 -32
  175. package/src/specs/tokens.test.js +0 -49
  176. package/src/specs/tool-error.test.js +0 -139
  177. package/src/splitStream.js +0 -204
  178. package/src/splitStream.test.js +0 -504
  179. package/src/stream.js +0 -650
  180. package/src/stream.test.js +0 -225
  181. package/src/test/mockTools.js +0 -340
  182. package/src/tools/BrowserTools.js +0 -245
  183. package/src/tools/Calculator.js +0 -38
  184. package/src/tools/Calculator.test.js +0 -225
  185. package/src/tools/CodeExecutor.js +0 -233
  186. package/src/tools/ProgrammaticToolCalling.js +0 -602
  187. package/src/tools/StreamingToolCallBuffer.js +0 -179
  188. package/src/tools/ToolNode.js +0 -930
  189. package/src/tools/ToolSearch.js +0 -904
  190. package/src/tools/__tests__/BrowserTools.test.js +0 -306
  191. package/src/tools/__tests__/ProgrammaticToolCalling.integration.test.js +0 -276
  192. package/src/tools/__tests__/ProgrammaticToolCalling.test.js +0 -807
  193. package/src/tools/__tests__/StreamingToolCallBuffer.test.js +0 -175
  194. package/src/tools/__tests__/ToolApproval.test.js +0 -675
  195. package/src/tools/__tests__/ToolNode.recovery.test.js +0 -200
  196. package/src/tools/__tests__/ToolNode.session.test.js +0 -319
  197. package/src/tools/__tests__/ToolSearch.integration.test.js +0 -125
  198. package/src/tools/__tests__/ToolSearch.test.js +0 -812
  199. package/src/tools/__tests__/handlers.test.js +0 -799
  200. package/src/tools/__tests__/truncation-recovery.integration.test.js +0 -362
  201. package/src/tools/handlers.js +0 -306
  202. package/src/tools/schema.js +0 -25
  203. package/src/tools/search/anthropic.js +0 -34
  204. package/src/tools/search/content.js +0 -116
  205. package/src/tools/search/content.test.js +0 -133
  206. package/src/tools/search/firecrawl.js +0 -173
  207. package/src/tools/search/format.js +0 -198
  208. package/src/tools/search/highlights.js +0 -241
  209. package/src/tools/search/index.js +0 -3
  210. package/src/tools/search/jina-reranker.test.js +0 -106
  211. package/src/tools/search/rerankers.js +0 -165
  212. package/src/tools/search/schema.js +0 -102
  213. package/src/tools/search/search.js +0 -561
  214. package/src/tools/search/serper-scraper.js +0 -126
  215. package/src/tools/search/test.js +0 -129
  216. package/src/tools/search/tool.js +0 -453
  217. package/src/tools/search/types.js +0 -2
  218. package/src/tools/search/utils.js +0 -59
  219. package/src/types/graph.js +0 -24
  220. package/src/types/graph.test.js +0 -192
  221. package/src/types/index.js +0 -7
  222. package/src/types/llm.js +0 -2
  223. package/src/types/messages.js +0 -2
  224. package/src/types/run.js +0 -2
  225. package/src/types/stream.js +0 -2
  226. package/src/types/tools.js +0 -2
  227. package/src/utils/contextAnalytics.js +0 -79
  228. package/src/utils/contextAnalytics.test.js +0 -166
  229. package/src/utils/events.js +0 -26
  230. package/src/utils/graph.js +0 -11
  231. package/src/utils/handlers.js +0 -65
  232. package/src/utils/index.js +0 -10
  233. package/src/utils/llm.js +0 -21
  234. package/src/utils/llmConfig.js +0 -205
  235. package/src/utils/logging.js +0 -37
  236. package/src/utils/misc.js +0 -51
  237. package/src/utils/run.js +0 -69
  238. package/src/utils/schema.js +0 -21
  239. package/src/utils/title.js +0 -119
  240. package/src/utils/tokens.js +0 -92
  241. package/src/utils/toonFormat.js +0 -379
@@ -1,132 +0,0 @@
1
- #!/usr/bin/env bun
2
- import { config } from 'dotenv';
3
- config();
4
- import { HumanMessage } from '@langchain/core/messages';
5
- import { Run } from '@/run';
6
- import { Providers } from '@/common';
7
- /**
8
- * Test the custom promptKey feature for handoff edges
9
- * This demonstrates how to use custom parameter names instead of "instructions"
10
- */
11
- async function testCustomPromptKey() {
12
- console.log('Testing Custom Prompt Key Feature...\n');
13
- const runConfig = {
14
- runId: `test-custom-prompt-key-${Date.now()}`,
15
- graphConfig: {
16
- type: 'multi-agent',
17
- agents: [
18
- {
19
- agentId: 'supervisor',
20
- provider: Providers.ANTHROPIC,
21
- clientOptions: {
22
- modelName: 'claude-haiku-4-5',
23
- apiKey: process.env.ANTHROPIC_API_KEY,
24
- },
25
- instructions: `You are a Task Supervisor managing different agents:
26
-
27
- 1. transfer_to_researcher - For research tasks (uses "query" parameter)
28
- 2. transfer_to_designer - For design tasks (uses "requirements" parameter)
29
- 3. transfer_to_coder - For coding tasks (uses "specification" parameter)
30
-
31
- Each agent expects different parameter names in their handoff tools.
32
- Pay attention to the parameter names when calling each tool.`,
33
- maxContextTokens: 8000,
34
- },
35
- {
36
- agentId: 'researcher',
37
- provider: Providers.ANTHROPIC,
38
- clientOptions: {
39
- modelName: 'claude-haiku-4-5',
40
- apiKey: process.env.ANTHROPIC_API_KEY,
41
- },
42
- instructions: `You are a Research Agent. You receive research queries to investigate.
43
- Look for the "Query:" field in the transfer message.`,
44
- maxContextTokens: 8000,
45
- },
46
- {
47
- agentId: 'designer',
48
- provider: Providers.ANTHROPIC,
49
- clientOptions: {
50
- modelName: 'claude-haiku-4-5',
51
- apiKey: process.env.ANTHROPIC_API_KEY,
52
- },
53
- instructions: `You are a Design Agent. You receive design requirements to implement.
54
- Look for the "Requirements:" field in the transfer message.`,
55
- maxContextTokens: 8000,
56
- },
57
- {
58
- agentId: 'coder',
59
- provider: Providers.ANTHROPIC,
60
- clientOptions: {
61
- modelName: 'claude-haiku-4-5',
62
- apiKey: process.env.ANTHROPIC_API_KEY,
63
- },
64
- instructions: `You are a Coding Agent. You receive technical specifications to implement.
65
- Look for the "Specification:" field in the transfer message.`,
66
- maxContextTokens: 8000,
67
- },
68
- ],
69
- edges: [
70
- {
71
- from: 'supervisor',
72
- to: 'researcher',
73
- edgeType: 'transfer',
74
- // Custom parameter name: "query"
75
- prompt: 'The research question or topic to investigate',
76
- promptKey: 'query',
77
- },
78
- {
79
- from: 'supervisor',
80
- to: 'designer',
81
- edgeType: 'transfer',
82
- // Custom parameter name: "requirements"
83
- prompt: 'The design requirements and constraints',
84
- promptKey: 'requirements',
85
- },
86
- {
87
- from: 'supervisor',
88
- to: 'coder',
89
- edgeType: 'transfer',
90
- // Custom parameter name: "specification"
91
- prompt: 'The technical specification for the code to implement',
92
- promptKey: 'specification',
93
- },
94
- ],
95
- },
96
- };
97
- const run = await Run.create(runConfig);
98
- // Test queries for different agents
99
- const testQueries = [
100
- // 'Research the latest trends in sustainable energy storage technologies',
101
- 'Design a mobile app interface for a fitness tracking application',
102
- // 'Write a Python function that calculates the Fibonacci sequence recursively',
103
- ];
104
- const config = {
105
- configurable: {
106
- thread_id: 'custom-prompt-key-test-1',
107
- },
108
- streamMode: 'values',
109
- version: 'v2',
110
- };
111
- for (const query of testQueries) {
112
- console.log(`\n${'='.repeat(60)}`);
113
- console.log(`USER QUERY: "${query}"`);
114
- console.log('='.repeat(60));
115
- const inputs = {
116
- messages: [new HumanMessage(query)],
117
- };
118
- await run.processStream(inputs, config);
119
- console.log(`\n${'─'.repeat(60)}`);
120
- console.log('Each agent receives instructions via their custom parameter:');
121
- console.log('- Researcher expects "query"');
122
- console.log('- Designer expects "requirements"');
123
- console.log('- Coder expects "specification"');
124
- console.log('─'.repeat(60));
125
- }
126
- console.log('\n\nDemonstration complete!');
127
- console.log('The promptKey feature allows for more semantic parameter names');
128
- console.log('that better match the domain and purpose of each agent.');
129
- }
130
- // Run the test
131
- testCustomPromptKey().catch(console.error);
132
- //# sourceMappingURL=test-custom-prompt-key.js.map
@@ -1,143 +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
- /**
9
- * Test the new handoff input feature using the prompt field
10
- * This demonstrates how supervisors can pass specific instructions to specialists
11
- */
12
- async function testHandoffInput() {
13
- console.log('Testing Handoff Input Feature...\n');
14
- // Set up content aggregator
15
- const { contentParts, aggregateContent } = createContentAggregator();
16
- // Track which specialist role was selected
17
- let selectedRole = '';
18
- let roleInstructions = '';
19
- // Create custom handlers
20
- const customHandlers = {
21
- [GraphEvents.TOOL_END]: new ToolEndHandler(),
22
- [GraphEvents.CHAT_MODEL_END]: new ModelEndHandler(),
23
- [GraphEvents.CHAT_MODEL_STREAM]: new ChatModelStreamHandler(),
24
- [GraphEvents.ON_RUN_STEP]: {
25
- handle: (event, data) => {
26
- const runStepData = data;
27
- if (runStepData?.name) {
28
- console.log(`\n[${runStepData.name}] Processing...`);
29
- }
30
- aggregateContent({ event, data: data });
31
- },
32
- },
33
- [GraphEvents.ON_RUN_STEP_COMPLETED]: {
34
- handle: (event, data) => {
35
- aggregateContent({
36
- event,
37
- data: data,
38
- });
39
- },
40
- },
41
- [GraphEvents.ON_MESSAGE_DELTA]: {
42
- handle: (event, data) => {
43
- console.dir(data, { depth: null });
44
- aggregateContent({ event, data: data });
45
- },
46
- },
47
- [GraphEvents.TOOL_START]: {
48
- handle: (_event, data, metadata) => {
49
- const toolData = data;
50
- if (toolData?.name?.includes('transfer_to_')) {
51
- const specialist = toolData.name.replace('transfer_to_', '');
52
- console.log(`\n🔀 Transferring to ${specialist}...`);
53
- selectedRole = specialist;
54
- }
55
- },
56
- },
57
- };
58
- const runConfig = {
59
- customHandlers,
60
- runId: `test-handoff-input-${Date.now()}`,
61
- graphConfig: {
62
- type: 'multi-agent',
63
- agents: [
64
- {
65
- agentId: 'supervisor',
66
- provider: Providers.ANTHROPIC,
67
- clientOptions: {
68
- modelName: 'claude-haiku-4-5',
69
- apiKey: process.env.ANTHROPIC_API_KEY,
70
- },
71
- instructions: `You are a Task Supervisor. You have access to two specialist agents:
72
-
73
- 1. transfer_to_analyst - For data analysis tasks
74
- 2. transfer_to_writer - For content creation tasks
75
-
76
- When transferring to a specialist, you MUST provide specific instructions
77
- in the tool call to guide their work. Be detailed about what you need.`,
78
- maxContextTokens: 8000,
79
- },
80
- {
81
- agentId: 'analyst',
82
- provider: Providers.ANTHROPIC,
83
- clientOptions: {
84
- modelName: 'claude-haiku-4-5',
85
- apiKey: process.env.ANTHROPIC_API_KEY,
86
- },
87
- instructions: `You are a Data Analyst. Follow the supervisor's instructions carefully.
88
- When you receive instructions, acknowledge them and perform the requested analysis.`,
89
- maxContextTokens: 8000,
90
- },
91
- {
92
- agentId: 'writer',
93
- provider: Providers.ANTHROPIC,
94
- clientOptions: {
95
- modelName: 'claude-haiku-4-5',
96
- apiKey: process.env.ANTHROPIC_API_KEY,
97
- },
98
- instructions: `You are a Content Writer. Follow the supervisor's instructions carefully.
99
- When you receive instructions, acknowledge them and create the requested content.`,
100
- maxContextTokens: 8000,
101
- },
102
- ],
103
- edges: [
104
- {
105
- from: 'supervisor',
106
- to: ['analyst', 'writer'],
107
- edgeType: 'transfer',
108
- // This prompt field now serves as the description for the input parameter
109
- prompt: 'Specific instructions for the specialist to follow. Be detailed about what analysis to perform, what data to focus on, or what content to create.',
110
- },
111
- ],
112
- },
113
- };
114
- const run = await Run.create(runConfig);
115
- // Test queries that should result in different handoffs with specific instructions
116
- const testQueries = [
117
- // 'Analyze our Q4 sales data and identify the top 3 performing products',
118
- 'Write a blog post about the benefits of remote work for software developers',
119
- ];
120
- const config = {
121
- configurable: {
122
- thread_id: 'handoff-input-test-1',
123
- },
124
- streamMode: 'values',
125
- version: 'v2',
126
- };
127
- for (const query of testQueries) {
128
- console.log(`\n${'='.repeat(60)}`);
129
- console.log(`USER QUERY: "${query}"`);
130
- console.log('='.repeat(60));
131
- const inputs = {
132
- messages: [new HumanMessage(query)],
133
- };
134
- const finalContentParts = await run.processStream(inputs, config);
135
- console.log(`\n${'─'.repeat(60)}`);
136
- console.log('Notice how the supervisor passes specific instructions');
137
- console.log('to the specialist through the handoff tool input parameter.');
138
- console.log('─'.repeat(60));
139
- }
140
- }
141
- // Run the test
142
- testHandoffInput().catch(console.error);
143
- //# sourceMappingURL=test-handoff-input.js.map
@@ -1,227 +0,0 @@
1
- /**
2
- * Test script for multi-turn handoff behavior.
3
- *
4
- * This tests the fix for the issue where receiving agents would see transfer messages
5
- * and prematurely produce end tokens, thinking the work was already done.
6
- *
7
- * The fix:
8
- * 1. Filters out transfer tool calls and ToolMessages from the receiving agent's context
9
- * 2. Injects any passthrough instructions as a HumanMessage to ground the receiving agent
10
- */
11
- import { config } from 'dotenv';
12
- config();
13
- import { HumanMessage } from '@langchain/core/messages';
14
- import { ChatModelStreamHandler, createContentAggregator } from '@/stream';
15
- import { ToolEndHandler, ModelEndHandler } from '@/events';
16
- import { GraphEvents, Providers } from '@/common';
17
- import { Run } from '@/run';
18
- const conversationHistory = [];
19
- /**
20
- * Test multi-turn handoff between a coordinator and a specialist
21
- */
22
- async function testHandoffPreamble() {
23
- console.log('='.repeat(60));
24
- console.log('Testing Multi-Turn Handoff with Preamble Injection');
25
- console.log('='.repeat(60));
26
- console.log('\nThis test verifies that:');
27
- console.log('1. Transfer messages are filtered from receiving agent context');
28
- console.log('2. Passthrough instructions are injected as a HumanMessage');
29
- console.log('3. Multi-turn conversations work correctly after handoffs\n');
30
- const { contentParts, aggregateContent } = createContentAggregator();
31
- /** Track which agent is responding */
32
- let currentAgent = '';
33
- const customHandlers = {
34
- [GraphEvents.TOOL_END]: new ToolEndHandler(),
35
- [GraphEvents.CHAT_MODEL_END]: new ModelEndHandler(),
36
- [GraphEvents.CHAT_MODEL_STREAM]: new ChatModelStreamHandler(),
37
- [GraphEvents.ON_RUN_STEP]: {
38
- handle: (event, data) => {
39
- const runStep = data;
40
- if (runStep.agentId) {
41
- currentAgent = runStep.agentId;
42
- console.log(`\n[Agent: ${currentAgent}] Processing...`);
43
- }
44
- aggregateContent({ event, data: runStep });
45
- },
46
- },
47
- [GraphEvents.ON_RUN_STEP_COMPLETED]: {
48
- handle: (event, data) => {
49
- aggregateContent({
50
- event,
51
- data: data,
52
- });
53
- },
54
- },
55
- [GraphEvents.ON_MESSAGE_DELTA]: {
56
- handle: (event, data) => {
57
- console.log('====== ON_MESSAGE_DELTA ======');
58
- console.dir(data, { depth: null });
59
- aggregateContent({ event, data: data });
60
- },
61
- },
62
- [GraphEvents.TOOL_START]: {
63
- handle: (_event, data, _metadata) => {
64
- const toolData = data;
65
- if (toolData?.name?.includes('transfer_to_')) {
66
- const specialist = toolData.name.replace('lc_transfer_to_', '');
67
- console.log(`\n🔀 Handing off to: ${specialist}`);
68
- }
69
- },
70
- },
71
- };
72
- /**
73
- * Create agents:
74
- * - coordinator: Decides when to hand off to specialist
75
- * - specialist: Handles specific tasks delegated by coordinator
76
- */
77
- const agents = [
78
- {
79
- agentId: 'coordinator',
80
- provider: Providers.OPENAI,
81
- clientOptions: {
82
- modelName: 'gpt-4.1-mini',
83
- apiKey: process.env.OPENAI_API_KEY,
84
- },
85
- instructions: `You are a Task Coordinator. Your role is to:
86
- 1. Understand user requests
87
- 2. If the request involves technical analysis, use the transfer_to_specialist tool to hand off
88
- 3. When handing off, provide clear instructions about what needs to be done
89
-
90
- IMPORTANT: When using the handoff tool, include specific instructions for the specialist.`,
91
- maxContextTokens: 8000,
92
- },
93
- {
94
- agentId: 'specialist',
95
- provider: Providers.OPENAI,
96
- clientOptions: {
97
- modelName: 'gpt-4.1-mini',
98
- apiKey: process.env.OPENAI_API_KEY,
99
- },
100
- instructions: `You are a Technical Specialist. When you receive a request:
101
- 1. Carefully read any instructions provided
102
- 2. Provide a detailed technical response
103
- 3. Do NOT just acknowledge - provide substantive help
104
-
105
- IMPORTANT: You are the specialist - provide a complete, helpful response to the task.`,
106
- maxContextTokens: 8000,
107
- },
108
- ];
109
- /** Create handoff edge with passthrough instructions */
110
- const edges = [
111
- {
112
- from: 'coordinator',
113
- to: 'specialist',
114
- description: 'Transfer to technical specialist for analysis',
115
- edgeType: 'transfer',
116
- prompt: 'Specific instructions for the specialist about what to analyze',
117
- promptKey: 'instructions',
118
- },
119
- ];
120
- const runConfig = {
121
- runId: `handoff-test-${Date.now()}`,
122
- graphConfig: {
123
- type: 'multi-agent',
124
- agents,
125
- edges,
126
- },
127
- customHandlers,
128
- returnContent: true,
129
- skipCleanup: true,
130
- };
131
- const run = await Run.create(runConfig);
132
- const config = {
133
- configurable: {
134
- thread_id: 'handoff-test-conversation-1',
135
- },
136
- streamMode: 'values',
137
- version: 'v2',
138
- };
139
- /** TURN 1: Initial request that triggers handoff */
140
- console.log('\n' + '─'.repeat(60));
141
- console.log('TURN 1: Initial request (should trigger handoff)');
142
- console.log('─'.repeat(60));
143
- const userMessage1 = `
144
- Hi! Can you help me understand the time complexity of quicksort?
145
- I need a technical explanation.
146
- `;
147
- conversationHistory.push(new HumanMessage(userMessage1));
148
- console.log('\nUser:', userMessage1.trim());
149
- console.log('\nResponse:');
150
- let inputs = { messages: conversationHistory };
151
- await run.processStream(inputs, config);
152
- const messages1 = run.getRunMessages();
153
- if (messages1) {
154
- conversationHistory.push(...messages1);
155
- }
156
- console.log('\n');
157
- /** TURN 2: Follow-up question to test multi-turn after handoff */
158
- console.log('\n' + '─'.repeat(60));
159
- console.log('TURN 2: Follow-up question (tests context after handoff)');
160
- console.log('─'.repeat(60));
161
- const userMessage2 = `
162
- Thanks! Can you also explain the space complexity and when quicksort
163
- might not be the best choice?
164
- `;
165
- conversationHistory.push(new HumanMessage(userMessage2));
166
- console.log('\nUser:', userMessage2.trim());
167
- console.log('\nResponse:');
168
- inputs = { messages: conversationHistory };
169
- await run.processStream(inputs, config);
170
- const messages2 = run.getRunMessages();
171
- if (messages2) {
172
- conversationHistory.push(...messages2);
173
- }
174
- console.log('\n');
175
- /** TURN 3: Another follow-up to verify sustained conversation */
176
- console.log('\n' + '─'.repeat(60));
177
- console.log('TURN 3: Third turn (tests sustained multi-turn)');
178
- console.log('─'.repeat(60));
179
- const userMessage3 = `
180
- Great explanation! One more question - how does quicksort compare
181
- to mergesort in practice?
182
- `;
183
- conversationHistory.push(new HumanMessage(userMessage3));
184
- console.log('\nUser:', userMessage3.trim());
185
- console.log('\nResponse:');
186
- inputs = { messages: conversationHistory };
187
- await run.processStream(inputs, config);
188
- const messages3 = run.getRunMessages();
189
- if (messages3) {
190
- conversationHistory.push(...messages3);
191
- }
192
- /** Summary */
193
- console.log('\n\n' + '='.repeat(60));
194
- console.log('TEST SUMMARY');
195
- console.log('='.repeat(60));
196
- console.log('\nTotal messages in conversation:', conversationHistory.length);
197
- console.log('\nMessage types:');
198
- for (let i = 0; i < conversationHistory.length; i++) {
199
- const msg = conversationHistory[i];
200
- const type = msg.getType();
201
- const preview = typeof msg.content === 'string'
202
- ? msg.content.slice(0, 50).replace(/\n/g, ' ')
203
- : '[complex content]';
204
- console.log(` ${i + 1}. [${type}] ${preview}...`);
205
- }
206
- console.log('\n✅ Test completed. Review the output above to verify:');
207
- console.log(' - Specialist received and acted on instructions');
208
- console.log(' - No premature end tokens after handoff');
209
- console.log(' - Multi-turn conversation continued smoothly');
210
- console.dir(contentParts, { depth: null });
211
- }
212
- process.on('unhandledRejection', (reason, promise) => {
213
- console.error('Unhandled Rejection at:', promise, 'reason:', reason);
214
- console.log('\nConversation history at failure:');
215
- console.dir(conversationHistory, { depth: null });
216
- process.exit(1);
217
- });
218
- process.on('uncaughtException', (err) => {
219
- console.error('Uncaught Exception:', err);
220
- });
221
- testHandoffPreamble().catch((err) => {
222
- console.error('Test failed:', err);
223
- console.log('\nConversation history at failure:');
224
- console.dir(conversationHistory, { depth: null });
225
- process.exit(1);
226
- });
227
- //# sourceMappingURL=test-handoff-preamble.js.map