@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.
- package/dist/cjs/graphs/Graph.cjs +12 -1
- package/dist/cjs/graphs/Graph.cjs.map +1 -1
- package/dist/cjs/graphs/MultiAgentGraph.cjs +85 -1
- package/dist/cjs/graphs/MultiAgentGraph.cjs.map +1 -1
- package/dist/cjs/run.cjs +20 -9
- package/dist/cjs/run.cjs.map +1 -1
- package/dist/esm/graphs/Graph.mjs +12 -1
- package/dist/esm/graphs/Graph.mjs.map +1 -1
- package/dist/esm/graphs/MultiAgentGraph.mjs +85 -1
- package/dist/esm/graphs/MultiAgentGraph.mjs.map +1 -1
- package/dist/esm/run.mjs +20 -9
- package/dist/esm/run.mjs.map +1 -1
- package/dist/types/graphs/MultiAgentGraph.d.ts +17 -0
- package/package.json +1 -1
- package/src/graphs/Graph.ts +12 -1
- package/src/graphs/MultiAgentGraph.ts +105 -1
- package/src/graphs/__tests__/multi-agent-delegate.test.ts +191 -0
- package/src/run.ts +20 -11
- package/src/scripts/test-bedrock-handoff-autonomous.ts +231 -0
- package/src/agents/AgentContext.js +0 -782
- package/src/agents/AgentContext.test.js +0 -421
- package/src/agents/__tests__/AgentContext.test.js +0 -678
- package/src/agents/__tests__/resolveStructuredOutputMode.test.js +0 -117
- package/src/common/enum.js +0 -192
- package/src/common/index.js +0 -3
- package/src/events.js +0 -166
- package/src/graphs/Graph.js +0 -1857
- package/src/graphs/MultiAgentGraph.js +0 -1092
- package/src/graphs/__tests__/structured-output.integration.test.js +0 -624
- package/src/graphs/__tests__/structured-output.test.js +0 -144
- package/src/graphs/contextManagement.e2e.test.js +0 -718
- package/src/graphs/contextManagement.test.js +0 -485
- package/src/graphs/handoffValidation.test.js +0 -276
- package/src/graphs/index.js +0 -3
- package/src/index.js +0 -28
- package/src/instrumentation.js +0 -21
- package/src/llm/anthropic/index.js +0 -319
- package/src/llm/anthropic/types.js +0 -46
- package/src/llm/anthropic/utils/message_inputs.js +0 -627
- package/src/llm/anthropic/utils/message_outputs.js +0 -290
- package/src/llm/anthropic/utils/output_parsers.js +0 -89
- package/src/llm/anthropic/utils/tools.js +0 -25
- package/src/llm/bedrock/__tests__/bedrock-caching.test.js +0 -392
- package/src/llm/bedrock/index.js +0 -303
- package/src/llm/bedrock/types.js +0 -2
- package/src/llm/bedrock/utils/index.js +0 -6
- package/src/llm/bedrock/utils/message_inputs.js +0 -463
- package/src/llm/bedrock/utils/message_outputs.js +0 -269
- package/src/llm/fake.js +0 -92
- package/src/llm/google/index.js +0 -215
- package/src/llm/google/types.js +0 -12
- package/src/llm/google/utils/common.js +0 -670
- package/src/llm/google/utils/tools.js +0 -111
- package/src/llm/google/utils/zod_to_genai_parameters.js +0 -47
- package/src/llm/openai/index.js +0 -1033
- package/src/llm/openai/types.js +0 -2
- package/src/llm/openai/utils/index.js +0 -756
- package/src/llm/openai/utils/isReasoningModel.test.js +0 -79
- package/src/llm/openrouter/index.js +0 -261
- package/src/llm/openrouter/reasoning.test.js +0 -181
- package/src/llm/providers.js +0 -36
- package/src/llm/text.js +0 -65
- package/src/llm/vertexai/index.js +0 -402
- package/src/messages/__tests__/tools.test.js +0 -392
- package/src/messages/cache.js +0 -404
- package/src/messages/cache.test.js +0 -1167
- package/src/messages/content.js +0 -48
- package/src/messages/content.test.js +0 -314
- package/src/messages/core.js +0 -359
- package/src/messages/ensureThinkingBlock.test.js +0 -997
- package/src/messages/format.js +0 -973
- package/src/messages/formatAgentMessages.test.js +0 -2278
- package/src/messages/formatAgentMessages.tools.test.js +0 -362
- package/src/messages/formatMessage.test.js +0 -608
- package/src/messages/ids.js +0 -18
- package/src/messages/index.js +0 -9
- package/src/messages/labelContentByAgent.test.js +0 -725
- package/src/messages/prune.js +0 -438
- package/src/messages/reducer.js +0 -60
- package/src/messages/shiftIndexTokenCountMap.test.js +0 -63
- package/src/messages/summarize.js +0 -146
- package/src/messages/summarize.test.js +0 -332
- package/src/messages/tools.js +0 -90
- package/src/mockStream.js +0 -81
- package/src/prompts/collab.js +0 -7
- package/src/prompts/index.js +0 -3
- package/src/prompts/taskmanager.js +0 -58
- package/src/run.js +0 -427
- package/src/schemas/index.js +0 -3
- package/src/schemas/schema-preparation.test.js +0 -370
- package/src/schemas/validate.js +0 -314
- package/src/schemas/validate.test.js +0 -264
- package/src/scripts/abort.js +0 -127
- package/src/scripts/ant_web_search.js +0 -130
- package/src/scripts/ant_web_search_edge_case.js +0 -133
- package/src/scripts/ant_web_search_error_edge_case.js +0 -119
- package/src/scripts/args.js +0 -41
- package/src/scripts/bedrock-cache-debug.js +0 -186
- package/src/scripts/bedrock-content-aggregation-test.js +0 -195
- package/src/scripts/bedrock-merge-test.js +0 -80
- package/src/scripts/bedrock-parallel-tools-test.js +0 -150
- package/src/scripts/caching.js +0 -106
- package/src/scripts/cli.js +0 -152
- package/src/scripts/cli2.js +0 -119
- package/src/scripts/cli3.js +0 -163
- package/src/scripts/cli4.js +0 -165
- package/src/scripts/cli5.js +0 -165
- package/src/scripts/code_exec.js +0 -171
- package/src/scripts/code_exec_files.js +0 -180
- package/src/scripts/code_exec_multi_session.js +0 -185
- package/src/scripts/code_exec_ptc.js +0 -265
- package/src/scripts/code_exec_session.js +0 -217
- package/src/scripts/code_exec_simple.js +0 -120
- package/src/scripts/content.js +0 -111
- package/src/scripts/empty_input.js +0 -125
- package/src/scripts/handoff-test.js +0 -96
- package/src/scripts/image.js +0 -138
- package/src/scripts/memory.js +0 -83
- package/src/scripts/multi-agent-chain.js +0 -271
- package/src/scripts/multi-agent-conditional.js +0 -185
- package/src/scripts/multi-agent-document-review-chain.js +0 -171
- package/src/scripts/multi-agent-hybrid-flow.js +0 -264
- package/src/scripts/multi-agent-parallel-start.js +0 -214
- package/src/scripts/multi-agent-parallel.js +0 -346
- package/src/scripts/multi-agent-sequence.js +0 -184
- package/src/scripts/multi-agent-supervisor.js +0 -324
- package/src/scripts/multi-agent-test.js +0 -147
- package/src/scripts/parallel-asymmetric-tools-test.js +0 -202
- package/src/scripts/parallel-full-metadata-test.js +0 -176
- package/src/scripts/parallel-tools-test.js +0 -256
- package/src/scripts/programmatic_exec.js +0 -277
- package/src/scripts/programmatic_exec_agent.js +0 -168
- package/src/scripts/search.js +0 -118
- package/src/scripts/sequential-full-metadata-test.js +0 -143
- package/src/scripts/simple.js +0 -174
- package/src/scripts/single-agent-metadata-test.js +0 -152
- package/src/scripts/stream.js +0 -113
- package/src/scripts/test-custom-prompt-key.js +0 -132
- package/src/scripts/test-handoff-input.js +0 -143
- package/src/scripts/test-handoff-preamble.js +0 -227
- package/src/scripts/test-handoff-steering.js +0 -353
- package/src/scripts/test-multi-agent-list-handoff.js +0 -318
- package/src/scripts/test-parallel-agent-labeling.js +0 -253
- package/src/scripts/test-parallel-handoffs.js +0 -229
- package/src/scripts/test-thinking-handoff-bedrock.js +0 -132
- package/src/scripts/test-thinking-handoff.js +0 -132
- package/src/scripts/test-thinking-to-thinking-handoff-bedrock.js +0 -140
- package/src/scripts/test-tool-before-handoff-role-order.js +0 -223
- package/src/scripts/test-tools-before-handoff.js +0 -187
- package/src/scripts/test_code_api.js +0 -263
- package/src/scripts/thinking-bedrock.js +0 -128
- package/src/scripts/thinking-vertexai.js +0 -130
- package/src/scripts/thinking.js +0 -134
- package/src/scripts/tool_search.js +0 -114
- package/src/scripts/tools.js +0 -125
- package/src/specs/agent-handoffs-bedrock.integration.test.js +0 -280
- package/src/specs/agent-handoffs.test.js +0 -924
- package/src/specs/anthropic.simple.test.js +0 -287
- package/src/specs/azure.simple.test.js +0 -381
- package/src/specs/cache.simple.test.js +0 -282
- package/src/specs/custom-event-await.test.js +0 -148
- package/src/specs/deepseek.simple.test.js +0 -189
- package/src/specs/emergency-prune.test.js +0 -308
- package/src/specs/moonshot.simple.test.js +0 -237
- package/src/specs/observability.integration.test.js +0 -1337
- package/src/specs/openai.simple.test.js +0 -233
- package/src/specs/openrouter.simple.test.js +0 -202
- package/src/specs/prune.test.js +0 -733
- package/src/specs/reasoning.test.js +0 -144
- package/src/specs/spec.utils.js +0 -4
- package/src/specs/thinking-handoff.test.js +0 -486
- package/src/specs/thinking-prune.test.js +0 -600
- package/src/specs/token-distribution-edge-case.test.js +0 -246
- package/src/specs/token-memoization.test.js +0 -32
- package/src/specs/tokens.test.js +0 -49
- package/src/specs/tool-error.test.js +0 -139
- package/src/splitStream.js +0 -204
- package/src/splitStream.test.js +0 -504
- package/src/stream.js +0 -650
- package/src/stream.test.js +0 -225
- package/src/test/mockTools.js +0 -340
- package/src/tools/BrowserTools.js +0 -245
- package/src/tools/Calculator.js +0 -38
- package/src/tools/Calculator.test.js +0 -225
- package/src/tools/CodeExecutor.js +0 -233
- package/src/tools/ProgrammaticToolCalling.js +0 -602
- package/src/tools/StreamingToolCallBuffer.js +0 -179
- package/src/tools/ToolNode.js +0 -930
- package/src/tools/ToolSearch.js +0 -904
- package/src/tools/__tests__/BrowserTools.test.js +0 -306
- package/src/tools/__tests__/ProgrammaticToolCalling.integration.test.js +0 -276
- package/src/tools/__tests__/ProgrammaticToolCalling.test.js +0 -807
- package/src/tools/__tests__/StreamingToolCallBuffer.test.js +0 -175
- package/src/tools/__tests__/ToolApproval.test.js +0 -675
- package/src/tools/__tests__/ToolNode.recovery.test.js +0 -200
- package/src/tools/__tests__/ToolNode.session.test.js +0 -319
- package/src/tools/__tests__/ToolSearch.integration.test.js +0 -125
- package/src/tools/__tests__/ToolSearch.test.js +0 -812
- package/src/tools/__tests__/handlers.test.js +0 -799
- package/src/tools/__tests__/truncation-recovery.integration.test.js +0 -362
- package/src/tools/handlers.js +0 -306
- package/src/tools/schema.js +0 -25
- package/src/tools/search/anthropic.js +0 -34
- package/src/tools/search/content.js +0 -116
- package/src/tools/search/content.test.js +0 -133
- package/src/tools/search/firecrawl.js +0 -173
- package/src/tools/search/format.js +0 -198
- package/src/tools/search/highlights.js +0 -241
- package/src/tools/search/index.js +0 -3
- package/src/tools/search/jina-reranker.test.js +0 -106
- package/src/tools/search/rerankers.js +0 -165
- package/src/tools/search/schema.js +0 -102
- package/src/tools/search/search.js +0 -561
- package/src/tools/search/serper-scraper.js +0 -126
- package/src/tools/search/test.js +0 -129
- package/src/tools/search/tool.js +0 -453
- package/src/tools/search/types.js +0 -2
- package/src/tools/search/utils.js +0 -59
- package/src/types/graph.js +0 -24
- package/src/types/graph.test.js +0 -192
- package/src/types/index.js +0 -7
- package/src/types/llm.js +0 -2
- package/src/types/messages.js +0 -2
- package/src/types/run.js +0 -2
- package/src/types/stream.js +0 -2
- package/src/types/tools.js +0 -2
- package/src/utils/contextAnalytics.js +0 -79
- package/src/utils/contextAnalytics.test.js +0 -166
- package/src/utils/events.js +0 -26
- package/src/utils/graph.js +0 -11
- package/src/utils/handlers.js +0 -65
- package/src/utils/index.js +0 -10
- package/src/utils/llm.js +0 -21
- package/src/utils/llmConfig.js +0 -205
- package/src/utils/logging.js +0 -37
- package/src/utils/misc.js +0 -51
- package/src/utils/run.js +0 -69
- package/src/utils/schema.js +0 -21
- package/src/utils/title.js +0 -119
- package/src/utils/tokens.js +0 -92
- package/src/utils/toonFormat.js +0 -379
|
@@ -1,217 +0,0 @@
|
|
|
1
|
-
// src/scripts/code_exec_session.ts
|
|
2
|
-
/**
|
|
3
|
-
* Test script for automatic session tracking in code execution tools.
|
|
4
|
-
*
|
|
5
|
-
* This tests the automatic session_id injection feature where:
|
|
6
|
-
* 1. First code execution generates files and returns a session_id
|
|
7
|
-
* 2. Session context is stored in Graph.sessions
|
|
8
|
-
* 3. Subsequent code executions automatically have access to previous files
|
|
9
|
-
* without the LLM needing to explicitly pass session_id
|
|
10
|
-
*
|
|
11
|
-
* Run with: npm run code_exec_session
|
|
12
|
-
*/
|
|
13
|
-
import { config } from 'dotenv';
|
|
14
|
-
config();
|
|
15
|
-
import { HumanMessage } from '@langchain/core/messages';
|
|
16
|
-
import { ChatModelStreamHandler, createContentAggregator } from '@/stream';
|
|
17
|
-
import { ToolEndHandler, ModelEndHandler, createMetadataAggregator, } from '@/events';
|
|
18
|
-
import { getLLMConfig } from '@/utils/llmConfig';
|
|
19
|
-
import { getArgs } from '@/scripts/args';
|
|
20
|
-
import { Constants, GraphEvents } from '@/common';
|
|
21
|
-
import { Run } from '@/run';
|
|
22
|
-
import { createCodeExecutionTool } from '@/tools/CodeExecutor';
|
|
23
|
-
const conversationHistory = [];
|
|
24
|
-
/**
|
|
25
|
-
* Prints a formatted section header for test output
|
|
26
|
-
*/
|
|
27
|
-
function printSection(title) {
|
|
28
|
-
console.log('\n' + '='.repeat(60));
|
|
29
|
-
console.log(` ${title}`);
|
|
30
|
-
console.log('='.repeat(60) + '\n');
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* Prints session context from the graph for debugging
|
|
34
|
-
*/
|
|
35
|
-
function printSessionContext(run) {
|
|
36
|
-
const graph = run.Graph;
|
|
37
|
-
if (!graph) {
|
|
38
|
-
console.log('[Session] No graph available');
|
|
39
|
-
return;
|
|
40
|
-
}
|
|
41
|
-
const session = graph.sessions.get(Constants.EXECUTE_CODE);
|
|
42
|
-
if (!session) {
|
|
43
|
-
console.log('[Session] No session context stored yet');
|
|
44
|
-
return;
|
|
45
|
-
}
|
|
46
|
-
console.log('[Session] Current session context:');
|
|
47
|
-
console.log(` - session_id: ${session.session_id}`);
|
|
48
|
-
console.log(` - files: ${JSON.stringify(session.files, null, 2)}`);
|
|
49
|
-
console.log(` - lastUpdated: ${new Date(session.lastUpdated).toISOString()}`);
|
|
50
|
-
}
|
|
51
|
-
async function testAutomaticSessionTracking() {
|
|
52
|
-
const { userName, location, provider, currentDate } = await getArgs();
|
|
53
|
-
const { contentParts, aggregateContent } = createContentAggregator();
|
|
54
|
-
const customHandlers = {
|
|
55
|
-
[GraphEvents.TOOL_END]: new ToolEndHandler(),
|
|
56
|
-
[GraphEvents.CHAT_MODEL_END]: new ModelEndHandler(),
|
|
57
|
-
[GraphEvents.CHAT_MODEL_STREAM]: new ChatModelStreamHandler(),
|
|
58
|
-
[GraphEvents.ON_RUN_STEP_COMPLETED]: {
|
|
59
|
-
handle: (event, data) => {
|
|
60
|
-
console.log('====== ON_RUN_STEP_COMPLETED ======');
|
|
61
|
-
console.dir(data, { depth: null });
|
|
62
|
-
aggregateContent({
|
|
63
|
-
event,
|
|
64
|
-
data: data,
|
|
65
|
-
});
|
|
66
|
-
},
|
|
67
|
-
},
|
|
68
|
-
[GraphEvents.ON_RUN_STEP]: {
|
|
69
|
-
handle: (event, data) => {
|
|
70
|
-
console.log('====== ON_RUN_STEP ======');
|
|
71
|
-
console.dir(data, { depth: null });
|
|
72
|
-
aggregateContent({ event, data: data });
|
|
73
|
-
},
|
|
74
|
-
},
|
|
75
|
-
[GraphEvents.ON_RUN_STEP_DELTA]: {
|
|
76
|
-
handle: (event, data) => {
|
|
77
|
-
aggregateContent({ event, data: data });
|
|
78
|
-
},
|
|
79
|
-
},
|
|
80
|
-
[GraphEvents.ON_MESSAGE_DELTA]: {
|
|
81
|
-
handle: (event, data) => {
|
|
82
|
-
aggregateContent({ event, data: data });
|
|
83
|
-
},
|
|
84
|
-
},
|
|
85
|
-
[GraphEvents.TOOL_START]: {
|
|
86
|
-
handle: (_event, data, _metadata) => {
|
|
87
|
-
console.log('====== TOOL_START ======');
|
|
88
|
-
console.dir(data, { depth: null });
|
|
89
|
-
},
|
|
90
|
-
},
|
|
91
|
-
};
|
|
92
|
-
const llmConfig = getLLMConfig(provider);
|
|
93
|
-
const run = await Run.create({
|
|
94
|
-
runId: 'session-tracking-test-1',
|
|
95
|
-
graphConfig: {
|
|
96
|
-
type: 'standard',
|
|
97
|
-
llmConfig,
|
|
98
|
-
tools: [createCodeExecutionTool()],
|
|
99
|
-
instructions: `You are an AI assistant testing automatic file persistence.
|
|
100
|
-
When writing Python code:
|
|
101
|
-
- Use print() for all outputs
|
|
102
|
-
- Files from previous executions are automatically available in /mnt/data/
|
|
103
|
-
- Files are READ-ONLY; write modifications to NEW filenames
|
|
104
|
-
- IMPORTANT: Do NOT include session_id in your tool calls - it's handled automatically.`,
|
|
105
|
-
additional_instructions: `User: ${userName}, Location: ${location}, Date: ${currentDate}.`,
|
|
106
|
-
},
|
|
107
|
-
returnContent: true,
|
|
108
|
-
skipCleanup: true,
|
|
109
|
-
customHandlers,
|
|
110
|
-
});
|
|
111
|
-
const streamConfig = {
|
|
112
|
-
configurable: {
|
|
113
|
-
provider,
|
|
114
|
-
thread_id: 'session-tracking-test',
|
|
115
|
-
},
|
|
116
|
-
streamMode: 'values',
|
|
117
|
-
version: 'v2',
|
|
118
|
-
};
|
|
119
|
-
// =========================================================================
|
|
120
|
-
// Test 1: Create initial file (establishes session)
|
|
121
|
-
// =========================================================================
|
|
122
|
-
printSection('Test 1: Create Initial File');
|
|
123
|
-
console.log('This test creates a file, which should establish a session context.\n');
|
|
124
|
-
const userMessage1 = `
|
|
125
|
-
Create a Python file that writes a simple JSON config file named "app_config.json" with the following content:
|
|
126
|
-
{
|
|
127
|
-
"app_name": "TestApp",
|
|
128
|
-
"version": "1.0.0",
|
|
129
|
-
"debug": true
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
After writing, print the contents to confirm it was created correctly.
|
|
133
|
-
`;
|
|
134
|
-
conversationHistory.push(new HumanMessage(userMessage1));
|
|
135
|
-
await run.processStream({ messages: conversationHistory }, streamConfig);
|
|
136
|
-
const finalMessages1 = run.getRunMessages();
|
|
137
|
-
if (finalMessages1) {
|
|
138
|
-
conversationHistory.push(...finalMessages1);
|
|
139
|
-
}
|
|
140
|
-
printSection('Session Context After Test 1');
|
|
141
|
-
printSessionContext(run);
|
|
142
|
-
// =========================================================================
|
|
143
|
-
// Test 2: Access previously created file (uses automatic session injection)
|
|
144
|
-
// =========================================================================
|
|
145
|
-
printSection('Test 2: Access Previous File (Automatic Session)');
|
|
146
|
-
console.log('This test reads the file created in Test 1.');
|
|
147
|
-
console.log('The LLM does NOT need to provide session_id - it should be injected automatically.\n');
|
|
148
|
-
const userMessage2 = `
|
|
149
|
-
Now read the app_config.json file that was just created and:
|
|
150
|
-
1. Print its contents
|
|
151
|
-
2. Confirm the version is "1.0.0"
|
|
152
|
-
|
|
153
|
-
Note: You should be able to access this file from the previous execution automatically.
|
|
154
|
-
`;
|
|
155
|
-
conversationHistory.push(new HumanMessage(userMessage2));
|
|
156
|
-
await run.processStream({ messages: conversationHistory }, streamConfig);
|
|
157
|
-
const finalMessages2 = run.getRunMessages();
|
|
158
|
-
if (finalMessages2) {
|
|
159
|
-
conversationHistory.push(...finalMessages2);
|
|
160
|
-
}
|
|
161
|
-
printSection('Session Context After Test 2');
|
|
162
|
-
printSessionContext(run);
|
|
163
|
-
// =========================================================================
|
|
164
|
-
// Test 3: Modify file (write to new filename)
|
|
165
|
-
// =========================================================================
|
|
166
|
-
printSection('Test 3: Modify File (Write to New Filename)');
|
|
167
|
-
console.log('This test modifies the config by reading the old file and writing a new one.\n');
|
|
168
|
-
const userMessage3 = `
|
|
169
|
-
Read app_config.json, update the version to "2.0.0" and debug to false,
|
|
170
|
-
then save it as "app_config_v2.json". Print both the old and new contents.
|
|
171
|
-
`;
|
|
172
|
-
conversationHistory.push(new HumanMessage(userMessage3));
|
|
173
|
-
await run.processStream({ messages: conversationHistory }, streamConfig);
|
|
174
|
-
const finalMessages3 = run.getRunMessages();
|
|
175
|
-
if (finalMessages3) {
|
|
176
|
-
conversationHistory.push(...finalMessages3);
|
|
177
|
-
}
|
|
178
|
-
printSection('Session Context After Test 3');
|
|
179
|
-
printSessionContext(run);
|
|
180
|
-
// =========================================================================
|
|
181
|
-
// Summary
|
|
182
|
-
// =========================================================================
|
|
183
|
-
printSection('Test Summary');
|
|
184
|
-
console.log('The automatic session tracking feature should have:');
|
|
185
|
-
console.log('1. Stored the session_id after the first code execution');
|
|
186
|
-
console.log('2. Automatically injected it into subsequent executions');
|
|
187
|
-
console.log('3. Accumulated file references across all executions');
|
|
188
|
-
console.log('\nCheck the session context output above to verify.\n');
|
|
189
|
-
// Generate title
|
|
190
|
-
const { handleLLMEnd, collected } = createMetadataAggregator();
|
|
191
|
-
const titleResult = await run.generateTitle({
|
|
192
|
-
provider,
|
|
193
|
-
inputText: 'Testing automatic session tracking for code execution',
|
|
194
|
-
contentParts,
|
|
195
|
-
chainOptions: {
|
|
196
|
-
callbacks: [{ handleLLMEnd }],
|
|
197
|
-
},
|
|
198
|
-
});
|
|
199
|
-
console.log('Generated Title:', titleResult);
|
|
200
|
-
console.log('Collected metadata:', collected);
|
|
201
|
-
}
|
|
202
|
-
process.on('unhandledRejection', (reason, promise) => {
|
|
203
|
-
console.error('Unhandled Rejection at:', promise, 'reason:', reason);
|
|
204
|
-
console.log('Conversation history:');
|
|
205
|
-
console.dir(conversationHistory, { depth: null });
|
|
206
|
-
process.exit(1);
|
|
207
|
-
});
|
|
208
|
-
process.on('uncaughtException', (err) => {
|
|
209
|
-
console.error('Uncaught Exception:', err);
|
|
210
|
-
});
|
|
211
|
-
testAutomaticSessionTracking().catch((err) => {
|
|
212
|
-
console.error(err);
|
|
213
|
-
console.log('Conversation history:');
|
|
214
|
-
console.dir(conversationHistory, { depth: null });
|
|
215
|
-
process.exit(1);
|
|
216
|
-
});
|
|
217
|
-
//# sourceMappingURL=code_exec_session.js.map
|
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
// src/scripts/cli.ts
|
|
2
|
-
import { config } from 'dotenv';
|
|
3
|
-
config();
|
|
4
|
-
import { HumanMessage } from '@langchain/core/messages';
|
|
5
|
-
import { ChatModelStreamHandler, createContentAggregator } from '@/stream';
|
|
6
|
-
import { createCodeExecutionTool } from '@/tools/CodeExecutor';
|
|
7
|
-
import { ToolEndHandler, ModelEndHandler } from '@/events';
|
|
8
|
-
import { createTokenCounter } from '@/utils/tokens';
|
|
9
|
-
import { getLLMConfig } from '@/utils/llmConfig';
|
|
10
|
-
import { getArgs } from '@/scripts/args';
|
|
11
|
-
import { GraphEvents } from '@/common';
|
|
12
|
-
import { Run } from '@/run';
|
|
13
|
-
const conversationHistory = [];
|
|
14
|
-
async function testCodeExecution() {
|
|
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
|
-
console.log('====== ON_RUN_STEP ======');
|
|
34
|
-
console.dir(data, { depth: null });
|
|
35
|
-
aggregateContent({ event, data: data });
|
|
36
|
-
},
|
|
37
|
-
},
|
|
38
|
-
[GraphEvents.ON_RUN_STEP_DELTA]: {
|
|
39
|
-
handle: (event, data) => {
|
|
40
|
-
console.log('====== ON_RUN_STEP_DELTA ======');
|
|
41
|
-
console.dir(data, { depth: null });
|
|
42
|
-
aggregateContent({ event, data: data });
|
|
43
|
-
},
|
|
44
|
-
},
|
|
45
|
-
[GraphEvents.ON_MESSAGE_DELTA]: {
|
|
46
|
-
handle: (event, data) => {
|
|
47
|
-
console.log('====== ON_MESSAGE_DELTA ======');
|
|
48
|
-
console.dir(data, { depth: null });
|
|
49
|
-
aggregateContent({ event, data: data });
|
|
50
|
-
},
|
|
51
|
-
},
|
|
52
|
-
[GraphEvents.TOOL_START]: {
|
|
53
|
-
handle: (_event, data, metadata) => {
|
|
54
|
-
console.log('====== TOOL_START ======');
|
|
55
|
-
console.dir(data, { depth: null });
|
|
56
|
-
},
|
|
57
|
-
},
|
|
58
|
-
};
|
|
59
|
-
const llmConfig = getLLMConfig(provider);
|
|
60
|
-
const instructions = 'You are a friendly AI assistant with coding capabilities. Always address the user by their name.';
|
|
61
|
-
const additional_instructions = `The user's name is ${userName} and they are located in ${location}.`;
|
|
62
|
-
// const userMessage1 = `how much memory is this (its in bytes) in MB? 31192000`;
|
|
63
|
-
// const userMessage1 = `can you show me a good use case for rscript by running some code`;
|
|
64
|
-
const userMessage1 = `Run hello world in french and in english, using python. please run 2 parallel code executions.`;
|
|
65
|
-
const humanMessage = new HumanMessage(userMessage1);
|
|
66
|
-
const tokenCounter = await createTokenCounter();
|
|
67
|
-
const indexTokenCountMap = {
|
|
68
|
-
0: tokenCounter(humanMessage),
|
|
69
|
-
};
|
|
70
|
-
const runConfig = {
|
|
71
|
-
runId: 'message-num-1',
|
|
72
|
-
graphConfig: {
|
|
73
|
-
type: 'standard',
|
|
74
|
-
llmConfig,
|
|
75
|
-
tools: [createCodeExecutionTool()],
|
|
76
|
-
instructions,
|
|
77
|
-
additional_instructions,
|
|
78
|
-
maxContextTokens: 8000,
|
|
79
|
-
},
|
|
80
|
-
returnContent: true,
|
|
81
|
-
skipCleanup: true,
|
|
82
|
-
customHandlers,
|
|
83
|
-
indexTokenCountMap,
|
|
84
|
-
tokenCounter,
|
|
85
|
-
};
|
|
86
|
-
const run = await Run.create(runConfig);
|
|
87
|
-
const config = {
|
|
88
|
-
configurable: {
|
|
89
|
-
provider,
|
|
90
|
-
thread_id: 'conversation-num-1',
|
|
91
|
-
},
|
|
92
|
-
streamMode: 'values',
|
|
93
|
-
version: 'v2',
|
|
94
|
-
};
|
|
95
|
-
console.log('Test 1: Simple Code Execution');
|
|
96
|
-
conversationHistory.push(humanMessage);
|
|
97
|
-
let inputs = {
|
|
98
|
-
messages: conversationHistory,
|
|
99
|
-
};
|
|
100
|
-
const finalContentParts1 = await run.processStream(inputs, config);
|
|
101
|
-
const finalMessages1 = run.getRunMessages();
|
|
102
|
-
if (finalMessages1) {
|
|
103
|
-
conversationHistory.push(...finalMessages1);
|
|
104
|
-
}
|
|
105
|
-
console.log('\n\n====================\n\n');
|
|
106
|
-
console.dir(contentParts, { depth: null });
|
|
107
|
-
}
|
|
108
|
-
process.on('unhandledRejection', (reason, promise) => {
|
|
109
|
-
console.error('Unhandled Rejection at:', promise, 'reason:', reason);
|
|
110
|
-
console.log('Conversation history:');
|
|
111
|
-
console.dir(conversationHistory, { depth: null });
|
|
112
|
-
process.exit(1);
|
|
113
|
-
});
|
|
114
|
-
testCodeExecution().catch((err) => {
|
|
115
|
-
console.error(err);
|
|
116
|
-
console.log('Conversation history:');
|
|
117
|
-
console.dir(conversationHistory, { depth: null });
|
|
118
|
-
process.exit(1);
|
|
119
|
-
});
|
|
120
|
-
//# sourceMappingURL=code_exec_simple.js.map
|
package/src/scripts/content.js
DELETED
|
@@ -1,111 +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 } from '@/events';
|
|
8
|
-
import { getArgs } from '@/scripts/args';
|
|
9
|
-
import { Run } from '@/run';
|
|
10
|
-
import { GraphEvents } from '@/common';
|
|
11
|
-
import { getLLMConfig } from '@/utils/llmConfig';
|
|
12
|
-
const conversationHistory = [];
|
|
13
|
-
async function testStandardStreaming() {
|
|
14
|
-
const { userName, location, provider, currentDate } = await getArgs();
|
|
15
|
-
const { contentParts, aggregateContent } = createContentAggregator();
|
|
16
|
-
const customHandlers = {
|
|
17
|
-
[GraphEvents.TOOL_END]: new ToolEndHandler(),
|
|
18
|
-
// [GraphEvents.CHAT_MODEL_END]: new ModelEndHandler(),
|
|
19
|
-
[GraphEvents.CHAT_MODEL_STREAM]: new ChatModelStreamHandler(),
|
|
20
|
-
[GraphEvents.ON_RUN_STEP_COMPLETED]: {
|
|
21
|
-
handle: (event, data) => {
|
|
22
|
-
console.log('====== ON_RUN_STEP_COMPLETED ======');
|
|
23
|
-
// console.dir(data, { depth: null });
|
|
24
|
-
aggregateContent({
|
|
25
|
-
event,
|
|
26
|
-
data: data,
|
|
27
|
-
});
|
|
28
|
-
},
|
|
29
|
-
},
|
|
30
|
-
[GraphEvents.ON_RUN_STEP]: {
|
|
31
|
-
handle: (event, data) => {
|
|
32
|
-
console.log('====== ON_RUN_STEP ======');
|
|
33
|
-
console.dir(data, { depth: null });
|
|
34
|
-
aggregateContent({ event, data: data });
|
|
35
|
-
},
|
|
36
|
-
},
|
|
37
|
-
[GraphEvents.ON_RUN_STEP_DELTA]: {
|
|
38
|
-
handle: (event, data) => {
|
|
39
|
-
console.log('====== ON_RUN_STEP_DELTA ======');
|
|
40
|
-
console.dir(data, { depth: null });
|
|
41
|
-
aggregateContent({ event, data: data });
|
|
42
|
-
},
|
|
43
|
-
},
|
|
44
|
-
[GraphEvents.ON_MESSAGE_DELTA]: {
|
|
45
|
-
handle: (event, data) => {
|
|
46
|
-
console.log('====== ON_MESSAGE_DELTA ======');
|
|
47
|
-
console.dir(data, { depth: null });
|
|
48
|
-
aggregateContent({ event, data: data });
|
|
49
|
-
},
|
|
50
|
-
},
|
|
51
|
-
[GraphEvents.TOOL_START]: {
|
|
52
|
-
handle: (_event, data, metadata) => {
|
|
53
|
-
console.log('====== TOOL_START ======');
|
|
54
|
-
// console.dir(data, { depth: null });
|
|
55
|
-
},
|
|
56
|
-
},
|
|
57
|
-
};
|
|
58
|
-
const llmConfig = getLLMConfig(provider);
|
|
59
|
-
const run = await Run.create({
|
|
60
|
-
runId: 'test-run-id',
|
|
61
|
-
graphConfig: {
|
|
62
|
-
type: 'standard',
|
|
63
|
-
llmConfig,
|
|
64
|
-
tools: [],
|
|
65
|
-
instructions: 'You are a friendly AI assistant. Always address the user by their name.',
|
|
66
|
-
additional_instructions: `The user's name is ${userName} and they are located in ${location}.`,
|
|
67
|
-
},
|
|
68
|
-
returnContent: true,
|
|
69
|
-
skipCleanup: true,
|
|
70
|
-
customHandlers,
|
|
71
|
-
});
|
|
72
|
-
const config = {
|
|
73
|
-
configurable: {
|
|
74
|
-
provider,
|
|
75
|
-
thread_id: 'conversation-num-1',
|
|
76
|
-
},
|
|
77
|
-
streamMode: 'values',
|
|
78
|
-
version: 'v2',
|
|
79
|
-
};
|
|
80
|
-
console.log('Test 1: Weather query (content parts test)');
|
|
81
|
-
const userMessage = `
|
|
82
|
-
Make a search for the weather in ${location} today, which is ${currentDate}.
|
|
83
|
-
Make sure to always refer to me by name, which is ${userName}.
|
|
84
|
-
After giving me a thorough summary, tell me a joke about the weather forecast we went over.
|
|
85
|
-
`;
|
|
86
|
-
conversationHistory.push(new HumanMessage(userMessage));
|
|
87
|
-
const inputs = {
|
|
88
|
-
messages: conversationHistory,
|
|
89
|
-
};
|
|
90
|
-
const finalContentParts = await run.processStream(inputs, config);
|
|
91
|
-
const finalMessages = run.getRunMessages();
|
|
92
|
-
if (finalMessages) {
|
|
93
|
-
conversationHistory.push(...finalMessages);
|
|
94
|
-
console.dir(conversationHistory, { depth: null });
|
|
95
|
-
}
|
|
96
|
-
// console.dir(finalContentParts, { depth: null });
|
|
97
|
-
console.log('\n\n====================\n\n');
|
|
98
|
-
// console.dir(contentParts, { depth: null });
|
|
99
|
-
}
|
|
100
|
-
process.on('unhandledRejection', (reason, promise) => {
|
|
101
|
-
console.error('Unhandled Rejection at:', promise, 'reason:', reason);
|
|
102
|
-
console.log('Conversation history:');
|
|
103
|
-
process.exit(1);
|
|
104
|
-
});
|
|
105
|
-
testStandardStreaming().catch((err) => {
|
|
106
|
-
console.error(err);
|
|
107
|
-
console.log('Conversation history:');
|
|
108
|
-
console.dir(conversationHistory, { depth: null });
|
|
109
|
-
process.exit(1);
|
|
110
|
-
});
|
|
111
|
-
//# sourceMappingURL=content.js.map
|
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
import { z } from 'zod';
|
|
2
|
-
import { config } from 'dotenv';
|
|
3
|
-
config();
|
|
4
|
-
import { HumanMessage } from '@langchain/core/messages';
|
|
5
|
-
import { tool } from "@langchain/core/tools";
|
|
6
|
-
import { getArgs } from '@/scripts/args';
|
|
7
|
-
import { Run } from '@/run';
|
|
8
|
-
import { getLLMConfig } from '@/utils/llmConfig';
|
|
9
|
-
import { ChatModelStreamHandler } from '@/stream';
|
|
10
|
-
import { ToolEndHandler, ModelEndHandler } from '@/events';
|
|
11
|
-
import { GraphEvents } from '@/common';
|
|
12
|
-
const pingServerTool = tool(() => {
|
|
13
|
-
return 'server has been pinged';
|
|
14
|
-
}, {
|
|
15
|
-
name: 'pingServer',
|
|
16
|
-
description: 'Ping server',
|
|
17
|
-
schema: z.object({}),
|
|
18
|
-
});
|
|
19
|
-
async function testPingServer() {
|
|
20
|
-
const { provider } = await getArgs();
|
|
21
|
-
const customHandlers = {
|
|
22
|
-
[GraphEvents.TOOL_END]: new ToolEndHandler(),
|
|
23
|
-
[GraphEvents.CHAT_MODEL_END]: new ModelEndHandler(),
|
|
24
|
-
[GraphEvents.CHAT_MODEL_STREAM]: new ChatModelStreamHandler(),
|
|
25
|
-
[GraphEvents.ON_RUN_STEP_COMPLETED]: {
|
|
26
|
-
handle: (_event, data) => {
|
|
27
|
-
console.log('====== ON_RUN_STEP_COMPLETED ======');
|
|
28
|
-
console.dir(data, { depth: null });
|
|
29
|
-
}
|
|
30
|
-
},
|
|
31
|
-
[GraphEvents.ON_RUN_STEP]: {
|
|
32
|
-
handle: (_event, data) => {
|
|
33
|
-
console.log('====== ON_RUN_STEP ======');
|
|
34
|
-
console.dir(data, { depth: null });
|
|
35
|
-
}
|
|
36
|
-
},
|
|
37
|
-
[GraphEvents.ON_RUN_STEP_DELTA]: {
|
|
38
|
-
handle: (_event, data) => {
|
|
39
|
-
console.log('====== ON_RUN_STEP_DELTA ======');
|
|
40
|
-
console.dir(data, { depth: null });
|
|
41
|
-
}
|
|
42
|
-
},
|
|
43
|
-
[GraphEvents.ON_MESSAGE_DELTA]: {
|
|
44
|
-
handle: (_event, data) => {
|
|
45
|
-
console.log('====== ON_MESSAGE_DELTA ======');
|
|
46
|
-
console.dir(data, { depth: null });
|
|
47
|
-
}
|
|
48
|
-
},
|
|
49
|
-
[GraphEvents.TOOL_START]: {
|
|
50
|
-
handle: (_event, data, metadata) => {
|
|
51
|
-
console.log('====== TOOL_START ======');
|
|
52
|
-
console.dir(data, { depth: null });
|
|
53
|
-
}
|
|
54
|
-
},
|
|
55
|
-
// [GraphEvents.LLM_STREAM]: new LLMStreamHandler(),
|
|
56
|
-
// [GraphEvents.LLM_START]: {
|
|
57
|
-
// handle: (_event: string, data: t.StreamEventData): void => {
|
|
58
|
-
// console.log('====== LLM_START ======');
|
|
59
|
-
// console.dir(data, { depth: null });
|
|
60
|
-
// }
|
|
61
|
-
// },
|
|
62
|
-
// [GraphEvents.LLM_END]: {
|
|
63
|
-
// handle: (_event: string, data: t.StreamEventData): void => {
|
|
64
|
-
// console.log('====== LLM_END ======');
|
|
65
|
-
// console.dir(data, { depth: null });
|
|
66
|
-
// }
|
|
67
|
-
// },
|
|
68
|
-
/*
|
|
69
|
-
[GraphEvents.CHAIN_START]: {
|
|
70
|
-
handle: (_event: string, data: t.StreamEventData): void => {
|
|
71
|
-
console.log('====== CHAIN_START ======');
|
|
72
|
-
// console.dir(data, { depth: null });
|
|
73
|
-
}
|
|
74
|
-
},
|
|
75
|
-
[GraphEvents.CHAIN_END]: {
|
|
76
|
-
handle: (_event: string, data: t.StreamEventData): void => {
|
|
77
|
-
console.log('====== CHAIN_END ======');
|
|
78
|
-
// console.dir(data, { depth: null });
|
|
79
|
-
}
|
|
80
|
-
},
|
|
81
|
-
*/
|
|
82
|
-
// [GraphEvents.CHAT_MODEL_START]: {
|
|
83
|
-
// handle: (_event: string, _data: t.StreamEventData): void => {
|
|
84
|
-
// console.log('====== CHAT_MODEL_START ======');
|
|
85
|
-
// console.dir(_data, { depth: null });
|
|
86
|
-
// // Intentionally left empty
|
|
87
|
-
// }
|
|
88
|
-
// },
|
|
89
|
-
};
|
|
90
|
-
const llmConfig = getLLMConfig(provider);
|
|
91
|
-
const run = await Run.create({
|
|
92
|
-
runId: 'test-run-id',
|
|
93
|
-
graphConfig: {
|
|
94
|
-
type: 'standard',
|
|
95
|
-
llmConfig,
|
|
96
|
-
tools: [pingServerTool],
|
|
97
|
-
instructions: 'You are a helpful AI assistant.',
|
|
98
|
-
},
|
|
99
|
-
customHandlers,
|
|
100
|
-
});
|
|
101
|
-
const config = {
|
|
102
|
-
configurable: {
|
|
103
|
-
provider,
|
|
104
|
-
thread_id: 'ping-server-test',
|
|
105
|
-
},
|
|
106
|
-
streamMode: 'values',
|
|
107
|
-
version: 'v2',
|
|
108
|
-
};
|
|
109
|
-
console.log('Pinging server test:');
|
|
110
|
-
const userMessage = "Please ping the server.";
|
|
111
|
-
const inputs = {
|
|
112
|
-
messages: [new HumanMessage(userMessage)],
|
|
113
|
-
};
|
|
114
|
-
const contentParts = await run.processStream(inputs, config);
|
|
115
|
-
const finalMessages = run.getRunMessages();
|
|
116
|
-
if (finalMessages) {
|
|
117
|
-
console.log('\nFinal messages:');
|
|
118
|
-
console.dir(finalMessages, { depth: null });
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
testPingServer().catch((err) => {
|
|
122
|
-
console.error(err);
|
|
123
|
-
process.exit(1);
|
|
124
|
-
});
|
|
125
|
-
//# sourceMappingURL=empty_input.js.map
|
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
import { config } from 'dotenv';
|
|
2
|
-
config();
|
|
3
|
-
import { z } from 'zod';
|
|
4
|
-
import { tool } from '@langchain/core/tools';
|
|
5
|
-
import { ChatAnthropic } from '@langchain/anthropic';
|
|
6
|
-
import { createReactAgent } from '@langchain/langgraph/prebuilt';
|
|
7
|
-
import { StateGraph, MessagesAnnotation, Command, START, getCurrentTaskInput, END, } from '@langchain/langgraph';
|
|
8
|
-
import { ToolMessage } from '@langchain/core/messages';
|
|
9
|
-
const createHandoffTool = ({ agentName, description, }) => {
|
|
10
|
-
const toolName = `transfer_to_${agentName}`;
|
|
11
|
-
const toolDescription = description || `Ask agent '${agentName}' for help`;
|
|
12
|
-
const handoffTool = tool(async (_, config) => {
|
|
13
|
-
const toolMessage = new ToolMessage({
|
|
14
|
-
content: `Successfully transferred to ${agentName}`,
|
|
15
|
-
name: toolName,
|
|
16
|
-
tool_call_id: config.toolCall.id,
|
|
17
|
-
});
|
|
18
|
-
// inject the current agent state
|
|
19
|
-
const state = getCurrentTaskInput();
|
|
20
|
-
return new Command({
|
|
21
|
-
goto: agentName,
|
|
22
|
-
update: { messages: state.messages.concat(toolMessage) },
|
|
23
|
-
graph: Command.PARENT,
|
|
24
|
-
});
|
|
25
|
-
}, {
|
|
26
|
-
name: toolName,
|
|
27
|
-
schema: z.object({}),
|
|
28
|
-
description: toolDescription,
|
|
29
|
-
});
|
|
30
|
-
return handoffTool;
|
|
31
|
-
};
|
|
32
|
-
const bookHotel = tool(async (input) => {
|
|
33
|
-
return `Successfully booked a stay at ${input.hotel_name}.`;
|
|
34
|
-
}, {
|
|
35
|
-
name: 'book_hotel',
|
|
36
|
-
description: 'Book a hotel',
|
|
37
|
-
schema: z.object({
|
|
38
|
-
hotel_name: z.string().describe('The name of the hotel to book'),
|
|
39
|
-
}),
|
|
40
|
-
});
|
|
41
|
-
const bookFlight = tool(async (input) => {
|
|
42
|
-
return `Successfully booked a flight from ${input.from_airport} to ${input.to_airport}.`;
|
|
43
|
-
}, {
|
|
44
|
-
name: 'book_flight',
|
|
45
|
-
description: 'Book a flight',
|
|
46
|
-
schema: z.object({
|
|
47
|
-
from_airport: z.string().describe('The departure airport code'),
|
|
48
|
-
to_airport: z.string().describe('The arrival airport code'),
|
|
49
|
-
}),
|
|
50
|
-
});
|
|
51
|
-
const transferToHotelAssistant = createHandoffTool({
|
|
52
|
-
agentName: 'hotel_assistant',
|
|
53
|
-
description: 'Transfer user to the hotel-booking assistant.',
|
|
54
|
-
});
|
|
55
|
-
const transferToFlightAssistant = createHandoffTool({
|
|
56
|
-
agentName: 'flight_assistant',
|
|
57
|
-
description: 'Transfer user to the flight-booking assistant.',
|
|
58
|
-
});
|
|
59
|
-
const llm = new ChatAnthropic({
|
|
60
|
-
modelName: 'claude-haiku-4-5',
|
|
61
|
-
apiKey: process.env.ANTHROPIC_API_KEY,
|
|
62
|
-
});
|
|
63
|
-
const flightAssistant = createReactAgent({
|
|
64
|
-
llm,
|
|
65
|
-
tools: [bookFlight, transferToHotelAssistant],
|
|
66
|
-
prompt: 'You are a flight booking assistant',
|
|
67
|
-
name: 'flight_assistant',
|
|
68
|
-
});
|
|
69
|
-
const hotelAssistant = createReactAgent({
|
|
70
|
-
llm,
|
|
71
|
-
tools: [bookHotel, transferToFlightAssistant],
|
|
72
|
-
prompt: 'You are a hotel booking assistant',
|
|
73
|
-
name: 'hotel_assistant',
|
|
74
|
-
});
|
|
75
|
-
const multiAgentGraph = new StateGraph(MessagesAnnotation)
|
|
76
|
-
.addNode('flight_assistant', flightAssistant, {
|
|
77
|
-
ends: ['hotel_assistant', END],
|
|
78
|
-
})
|
|
79
|
-
.addNode('hotel_assistant', hotelAssistant, {
|
|
80
|
-
ends: ['flight_assistant', END],
|
|
81
|
-
})
|
|
82
|
-
.addEdge(START, 'flight_assistant')
|
|
83
|
-
.compile();
|
|
84
|
-
const stream = await multiAgentGraph.stream({
|
|
85
|
-
messages: [
|
|
86
|
-
{
|
|
87
|
-
role: 'user',
|
|
88
|
-
content: 'book a flight from BOS to JFK and a stay at McKittrick Hotel',
|
|
89
|
-
},
|
|
90
|
-
],
|
|
91
|
-
});
|
|
92
|
-
for await (const chunk of stream) {
|
|
93
|
-
console.log(chunk);
|
|
94
|
-
console.log('\n');
|
|
95
|
-
}
|
|
96
|
-
//# sourceMappingURL=handoff-test.js.map
|