illuma-agents 1.0.10 → 1.0.12
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/LICENSE +1 -1
- package/dist/cjs/agents/AgentContext.cjs +236 -27
- package/dist/cjs/agents/AgentContext.cjs.map +1 -1
- package/dist/cjs/common/enum.cjs +2 -0
- package/dist/cjs/common/enum.cjs.map +1 -1
- package/dist/cjs/events.cjs +3 -11
- package/dist/cjs/events.cjs.map +1 -1
- package/dist/cjs/graphs/Graph.cjs +44 -18
- package/dist/cjs/graphs/Graph.cjs.map +1 -1
- package/dist/cjs/instrumentation.cjs +1 -3
- package/dist/cjs/instrumentation.cjs.map +1 -1
- package/dist/cjs/llm/bedrock/index.cjs +121 -6
- package/dist/cjs/llm/bedrock/index.cjs.map +1 -1
- package/dist/cjs/main.cjs +18 -0
- package/dist/cjs/main.cjs.map +1 -1
- package/dist/cjs/messages/cache.cjs +149 -54
- package/dist/cjs/messages/cache.cjs.map +1 -1
- package/dist/cjs/messages/tools.cjs +85 -0
- package/dist/cjs/messages/tools.cjs.map +1 -0
- package/dist/cjs/run.cjs +0 -8
- package/dist/cjs/run.cjs.map +1 -1
- package/dist/cjs/tools/CodeExecutor.cjs +4 -0
- package/dist/cjs/tools/CodeExecutor.cjs.map +1 -1
- package/dist/cjs/tools/ProgrammaticToolCalling.cjs +438 -0
- package/dist/cjs/tools/ProgrammaticToolCalling.cjs.map +1 -0
- package/dist/cjs/tools/ToolNode.cjs +53 -15
- package/dist/cjs/tools/ToolNode.cjs.map +1 -1
- package/dist/cjs/tools/ToolSearchRegex.cjs +455 -0
- package/dist/cjs/tools/ToolSearchRegex.cjs.map +1 -0
- package/dist/cjs/tools/search/schema.cjs +7 -9
- package/dist/cjs/tools/search/schema.cjs.map +1 -1
- package/dist/cjs/utils/run.cjs +5 -1
- package/dist/cjs/utils/run.cjs.map +1 -1
- package/dist/esm/agents/AgentContext.mjs +236 -27
- package/dist/esm/agents/AgentContext.mjs.map +1 -1
- package/dist/esm/common/enum.mjs +2 -0
- package/dist/esm/common/enum.mjs.map +1 -1
- package/dist/esm/events.mjs +4 -12
- package/dist/esm/events.mjs.map +1 -1
- package/dist/esm/graphs/Graph.mjs +45 -19
- package/dist/esm/graphs/Graph.mjs.map +1 -1
- package/dist/esm/instrumentation.mjs +1 -3
- package/dist/esm/instrumentation.mjs.map +1 -1
- package/dist/esm/llm/bedrock/index.mjs +121 -6
- package/dist/esm/llm/bedrock/index.mjs.map +1 -1
- package/dist/esm/main.mjs +3 -0
- package/dist/esm/main.mjs.map +1 -1
- package/dist/esm/messages/cache.mjs +149 -54
- package/dist/esm/messages/cache.mjs.map +1 -1
- package/dist/esm/messages/tools.mjs +82 -0
- package/dist/esm/messages/tools.mjs.map +1 -0
- package/dist/esm/run.mjs +0 -8
- package/dist/esm/run.mjs.map +1 -1
- package/dist/esm/tools/CodeExecutor.mjs +4 -0
- package/dist/esm/tools/CodeExecutor.mjs.map +1 -1
- package/dist/esm/tools/ProgrammaticToolCalling.mjs +430 -0
- package/dist/esm/tools/ProgrammaticToolCalling.mjs.map +1 -0
- package/dist/esm/tools/ToolNode.mjs +53 -15
- package/dist/esm/tools/ToolNode.mjs.map +1 -1
- package/dist/esm/tools/ToolSearchRegex.mjs +448 -0
- package/dist/esm/tools/ToolSearchRegex.mjs.map +1 -0
- package/dist/esm/tools/search/schema.mjs +7 -9
- package/dist/esm/tools/search/schema.mjs.map +1 -1
- package/dist/esm/utils/run.mjs +5 -1
- package/dist/esm/utils/run.mjs.map +1 -1
- package/dist/types/agents/AgentContext.d.ts +72 -5
- package/dist/types/common/enum.d.ts +2 -0
- package/dist/types/graphs/Graph.d.ts +3 -2
- package/dist/types/index.d.ts +2 -0
- package/dist/types/llm/bedrock/index.d.ts +31 -4
- package/dist/types/messages/cache.d.ts +23 -8
- package/dist/types/messages/index.d.ts +1 -0
- package/dist/types/messages/tools.d.ts +17 -0
- package/dist/types/test/mockTools.d.ts +28 -0
- package/dist/types/tools/ProgrammaticToolCalling.d.ts +91 -0
- package/dist/types/tools/ToolNode.d.ts +10 -2
- package/dist/types/tools/ToolSearchRegex.d.ts +80 -0
- package/dist/types/types/graph.d.ts +14 -1
- package/dist/types/types/tools.d.ts +138 -0
- package/package.json +7 -8
- package/src/agents/AgentContext.ts +278 -27
- package/src/agents/__tests__/AgentContext.test.ts +805 -0
- package/src/common/enum.ts +2 -0
- package/src/events.ts +5 -12
- package/src/graphs/Graph.ts +57 -19
- package/src/index.ts +2 -0
- package/src/instrumentation.ts +1 -4
- package/src/llm/bedrock/__tests__/bedrock-caching.test.ts +473 -0
- package/src/llm/bedrock/index.ts +149 -12
- package/src/messages/__tests__/tools.test.ts +473 -0
- package/src/messages/cache.ts +163 -61
- package/src/messages/index.ts +1 -0
- package/src/messages/tools.ts +99 -0
- package/src/run.ts +0 -9
- package/src/scripts/code_exec_ptc.ts +334 -0
- package/src/scripts/image.ts +178 -0
- package/src/scripts/programmatic_exec.ts +396 -0
- package/src/scripts/programmatic_exec_agent.ts +231 -0
- package/src/scripts/test-tools-before-handoff.ts +5 -1
- package/src/scripts/tool_search_regex.ts +162 -0
- package/src/scripts/tools.ts +4 -1
- package/src/specs/thinking-prune.test.ts +52 -118
- package/src/test/mockTools.ts +366 -0
- package/src/tools/CodeExecutor.ts +4 -0
- package/src/tools/ProgrammaticToolCalling.ts +558 -0
- package/src/tools/ToolNode.ts +59 -18
- package/src/tools/ToolSearchRegex.ts +535 -0
- package/src/tools/__tests__/ProgrammaticToolCalling.integration.test.ts +318 -0
- package/src/tools/__tests__/ProgrammaticToolCalling.test.ts +853 -0
- package/src/tools/__tests__/ToolSearchRegex.integration.test.ts +161 -0
- package/src/tools/__tests__/ToolSearchRegex.test.ts +232 -0
- package/src/tools/search/jina-reranker.test.ts +16 -16
- package/src/tools/search/schema.ts +7 -9
- package/src/types/graph.ts +14 -1
- package/src/types/tools.ts +166 -0
- package/src/utils/run.ts +5 -1
- package/src/tools/search/direct-url.test.ts +0 -530
|
@@ -0,0 +1,853 @@
|
|
|
1
|
+
// src/tools/__tests__/ProgrammaticToolCalling.test.ts
|
|
2
|
+
/**
|
|
3
|
+
* Unit tests for Programmatic Tool Calling.
|
|
4
|
+
* Tests manual invocation with mock tools and Code API responses.
|
|
5
|
+
*/
|
|
6
|
+
import { describe, it, expect, beforeEach } from '@jest/globals';
|
|
7
|
+
import type * as t from '@/types';
|
|
8
|
+
import {
|
|
9
|
+
createProgrammaticToolCallingTool,
|
|
10
|
+
formatCompletedResponse,
|
|
11
|
+
extractUsedToolNames,
|
|
12
|
+
filterToolsByUsage,
|
|
13
|
+
executeTools,
|
|
14
|
+
normalizeToPythonIdentifier,
|
|
15
|
+
} from '../ProgrammaticToolCalling';
|
|
16
|
+
import {
|
|
17
|
+
createProgrammaticToolRegistry,
|
|
18
|
+
createGetTeamMembersTool,
|
|
19
|
+
createGetExpensesTool,
|
|
20
|
+
createGetWeatherTool,
|
|
21
|
+
createCalculatorTool,
|
|
22
|
+
} from '@/test/mockTools';
|
|
23
|
+
|
|
24
|
+
describe('ProgrammaticToolCalling', () => {
|
|
25
|
+
describe('executeTools', () => {
|
|
26
|
+
let toolMap: t.ToolMap;
|
|
27
|
+
|
|
28
|
+
beforeEach(() => {
|
|
29
|
+
const tools = [
|
|
30
|
+
createGetTeamMembersTool(),
|
|
31
|
+
createGetExpensesTool(),
|
|
32
|
+
createGetWeatherTool(),
|
|
33
|
+
createCalculatorTool(),
|
|
34
|
+
];
|
|
35
|
+
toolMap = new Map(tools.map((t) => [t.name, t]));
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it('executes a single tool successfully', async () => {
|
|
39
|
+
const toolCalls: t.PTCToolCall[] = [
|
|
40
|
+
{
|
|
41
|
+
id: 'call_001',
|
|
42
|
+
name: 'get_weather',
|
|
43
|
+
input: { city: 'San Francisco' },
|
|
44
|
+
},
|
|
45
|
+
];
|
|
46
|
+
|
|
47
|
+
const results = await executeTools(toolCalls, toolMap);
|
|
48
|
+
|
|
49
|
+
expect(results).toHaveLength(1);
|
|
50
|
+
expect(results[0].call_id).toBe('call_001');
|
|
51
|
+
expect(results[0].is_error).toBe(false);
|
|
52
|
+
expect(results[0].result).toEqual({
|
|
53
|
+
temperature: 65,
|
|
54
|
+
condition: 'Foggy',
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it('executes multiple tools in parallel', async () => {
|
|
59
|
+
const toolCalls: t.PTCToolCall[] = [
|
|
60
|
+
{
|
|
61
|
+
id: 'call_001',
|
|
62
|
+
name: 'get_weather',
|
|
63
|
+
input: { city: 'San Francisco' },
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
id: 'call_002',
|
|
67
|
+
name: 'get_weather',
|
|
68
|
+
input: { city: 'New York' },
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
id: 'call_003',
|
|
72
|
+
name: 'get_weather',
|
|
73
|
+
input: { city: 'London' },
|
|
74
|
+
},
|
|
75
|
+
];
|
|
76
|
+
|
|
77
|
+
const startTime = Date.now();
|
|
78
|
+
const results = await executeTools(toolCalls, toolMap);
|
|
79
|
+
const duration = Date.now() - startTime;
|
|
80
|
+
|
|
81
|
+
// Should execute in parallel (< 150ms total, not 120ms sequential)
|
|
82
|
+
expect(duration).toBeLessThan(150);
|
|
83
|
+
|
|
84
|
+
expect(results).toHaveLength(3);
|
|
85
|
+
expect(results[0].is_error).toBe(false);
|
|
86
|
+
expect(results[1].is_error).toBe(false);
|
|
87
|
+
expect(results[2].is_error).toBe(false);
|
|
88
|
+
|
|
89
|
+
expect(results[0].result.temperature).toBe(65);
|
|
90
|
+
expect(results[1].result.temperature).toBe(75);
|
|
91
|
+
expect(results[2].result.temperature).toBe(55);
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
it('handles tool not found error', async () => {
|
|
95
|
+
const toolCalls: t.PTCToolCall[] = [
|
|
96
|
+
{
|
|
97
|
+
id: 'call_001',
|
|
98
|
+
name: 'nonexistent_tool',
|
|
99
|
+
input: {},
|
|
100
|
+
},
|
|
101
|
+
];
|
|
102
|
+
|
|
103
|
+
const results = await executeTools(toolCalls, toolMap);
|
|
104
|
+
|
|
105
|
+
expect(results).toHaveLength(1);
|
|
106
|
+
expect(results[0].call_id).toBe('call_001');
|
|
107
|
+
expect(results[0].is_error).toBe(true);
|
|
108
|
+
expect(results[0].error_message).toContain('nonexistent_tool');
|
|
109
|
+
expect(results[0].error_message).toContain('Available tools:');
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
it('handles tool execution error', async () => {
|
|
113
|
+
const toolCalls: t.PTCToolCall[] = [
|
|
114
|
+
{
|
|
115
|
+
id: 'call_001',
|
|
116
|
+
name: 'get_weather',
|
|
117
|
+
input: { city: 'InvalidCity' },
|
|
118
|
+
},
|
|
119
|
+
];
|
|
120
|
+
|
|
121
|
+
const results = await executeTools(toolCalls, toolMap);
|
|
122
|
+
|
|
123
|
+
expect(results).toHaveLength(1);
|
|
124
|
+
expect(results[0].call_id).toBe('call_001');
|
|
125
|
+
expect(results[0].is_error).toBe(true);
|
|
126
|
+
expect(results[0].error_message).toContain('Weather data not available');
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
it('handles mix of successful and failed tool calls', async () => {
|
|
130
|
+
const toolCalls: t.PTCToolCall[] = [
|
|
131
|
+
{
|
|
132
|
+
id: 'call_001',
|
|
133
|
+
name: 'get_weather',
|
|
134
|
+
input: { city: 'San Francisco' },
|
|
135
|
+
},
|
|
136
|
+
{
|
|
137
|
+
id: 'call_002',
|
|
138
|
+
name: 'get_weather',
|
|
139
|
+
input: { city: 'InvalidCity' },
|
|
140
|
+
},
|
|
141
|
+
{
|
|
142
|
+
id: 'call_003',
|
|
143
|
+
name: 'get_weather',
|
|
144
|
+
input: { city: 'New York' },
|
|
145
|
+
},
|
|
146
|
+
];
|
|
147
|
+
|
|
148
|
+
const results = await executeTools(toolCalls, toolMap);
|
|
149
|
+
|
|
150
|
+
expect(results).toHaveLength(3);
|
|
151
|
+
expect(results[0].is_error).toBe(false);
|
|
152
|
+
expect(results[1].is_error).toBe(true);
|
|
153
|
+
expect(results[2].is_error).toBe(false);
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
it('executes tools with different parameters', async () => {
|
|
157
|
+
const toolCalls: t.PTCToolCall[] = [
|
|
158
|
+
{
|
|
159
|
+
id: 'call_001',
|
|
160
|
+
name: 'get_team_members',
|
|
161
|
+
input: {},
|
|
162
|
+
},
|
|
163
|
+
{
|
|
164
|
+
id: 'call_002',
|
|
165
|
+
name: 'get_expenses',
|
|
166
|
+
input: { user_id: 'u1' },
|
|
167
|
+
},
|
|
168
|
+
{
|
|
169
|
+
id: 'call_003',
|
|
170
|
+
name: 'calculator',
|
|
171
|
+
input: { expression: '2 + 2 * 3' },
|
|
172
|
+
},
|
|
173
|
+
];
|
|
174
|
+
|
|
175
|
+
const results = await executeTools(toolCalls, toolMap);
|
|
176
|
+
|
|
177
|
+
expect(results).toHaveLength(3);
|
|
178
|
+
expect(results[0].is_error).toBe(false);
|
|
179
|
+
expect(results[1].is_error).toBe(false);
|
|
180
|
+
expect(results[2].is_error).toBe(false);
|
|
181
|
+
|
|
182
|
+
expect(Array.isArray(results[0].result)).toBe(true);
|
|
183
|
+
expect(results[0].result).toHaveLength(3);
|
|
184
|
+
expect(Array.isArray(results[1].result)).toBe(true);
|
|
185
|
+
expect(results[2].result.result).toBe(8);
|
|
186
|
+
});
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
describe('normalizeToPythonIdentifier', () => {
|
|
190
|
+
it('converts hyphens to underscores', () => {
|
|
191
|
+
expect(normalizeToPythonIdentifier('my-tool-name')).toBe('my_tool_name');
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
it('converts spaces to underscores', () => {
|
|
195
|
+
expect(normalizeToPythonIdentifier('my tool name')).toBe('my_tool_name');
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
it('leaves underscores unchanged', () => {
|
|
199
|
+
expect(normalizeToPythonIdentifier('my_tool_name')).toBe('my_tool_name');
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
it('handles mixed hyphens and underscores', () => {
|
|
203
|
+
expect(normalizeToPythonIdentifier('my-tool_name-v2')).toBe(
|
|
204
|
+
'my_tool_name_v2'
|
|
205
|
+
);
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
it('handles MCP-style names with hyphens', () => {
|
|
209
|
+
expect(
|
|
210
|
+
normalizeToPythonIdentifier('create_spreadsheet_mcp_Google-Workspace')
|
|
211
|
+
).toBe('create_spreadsheet_mcp_Google_Workspace');
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
it('removes invalid characters', () => {
|
|
215
|
+
expect(normalizeToPythonIdentifier('tool@name!v2')).toBe('toolnamev2');
|
|
216
|
+
expect(normalizeToPythonIdentifier('get.data.v2')).toBe('getdatav2');
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
it('prefixes with underscore if starts with number', () => {
|
|
220
|
+
expect(normalizeToPythonIdentifier('123tool')).toBe('_123tool');
|
|
221
|
+
expect(normalizeToPythonIdentifier('1-tool')).toBe('_1_tool');
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
it('appends _tool suffix for Python keywords', () => {
|
|
225
|
+
expect(normalizeToPythonIdentifier('return')).toBe('return_tool');
|
|
226
|
+
expect(normalizeToPythonIdentifier('async')).toBe('async_tool');
|
|
227
|
+
expect(normalizeToPythonIdentifier('import')).toBe('import_tool');
|
|
228
|
+
});
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
describe('extractUsedToolNames', () => {
|
|
232
|
+
const createToolMap = (names: string[]): Map<string, string> => {
|
|
233
|
+
const map = new Map<string, string>();
|
|
234
|
+
for (const name of names) {
|
|
235
|
+
map.set(normalizeToPythonIdentifier(name), name);
|
|
236
|
+
}
|
|
237
|
+
return map;
|
|
238
|
+
};
|
|
239
|
+
|
|
240
|
+
const availableTools = createToolMap([
|
|
241
|
+
'get_weather',
|
|
242
|
+
'get_team_members',
|
|
243
|
+
'get_expenses',
|
|
244
|
+
'calculator',
|
|
245
|
+
'search_docs',
|
|
246
|
+
]);
|
|
247
|
+
|
|
248
|
+
it('extracts single tool name from simple code', () => {
|
|
249
|
+
const code = `result = await get_weather(city="SF")
|
|
250
|
+
print(result)`;
|
|
251
|
+
const used = extractUsedToolNames(code, availableTools);
|
|
252
|
+
|
|
253
|
+
expect(used.size).toBe(1);
|
|
254
|
+
expect(used.has('get_weather')).toBe(true);
|
|
255
|
+
});
|
|
256
|
+
|
|
257
|
+
it('extracts multiple tool names from code', () => {
|
|
258
|
+
const code = `team = await get_team_members()
|
|
259
|
+
for member in team:
|
|
260
|
+
expenses = await get_expenses(user_id=member['id'])
|
|
261
|
+
print(f"{member['name']}: {sum(e['amount'] for e in expenses)}")`;
|
|
262
|
+
|
|
263
|
+
const used = extractUsedToolNames(code, availableTools);
|
|
264
|
+
|
|
265
|
+
expect(used.size).toBe(2);
|
|
266
|
+
expect(used.has('get_team_members')).toBe(true);
|
|
267
|
+
expect(used.has('get_expenses')).toBe(true);
|
|
268
|
+
});
|
|
269
|
+
|
|
270
|
+
it('extracts tools from asyncio.gather calls', () => {
|
|
271
|
+
const code = `results = await asyncio.gather(
|
|
272
|
+
get_weather(city="SF"),
|
|
273
|
+
get_weather(city="NYC"),
|
|
274
|
+
get_expenses(user_id="u1")
|
|
275
|
+
)`;
|
|
276
|
+
const used = extractUsedToolNames(code, availableTools);
|
|
277
|
+
|
|
278
|
+
expect(used.size).toBe(2);
|
|
279
|
+
expect(used.has('get_weather')).toBe(true);
|
|
280
|
+
expect(used.has('get_expenses')).toBe(true);
|
|
281
|
+
});
|
|
282
|
+
|
|
283
|
+
it('does not match partial tool names', () => {
|
|
284
|
+
const code = `# Using get_weather_data instead
|
|
285
|
+
result = await get_weather_data(city="SF")`;
|
|
286
|
+
|
|
287
|
+
const used = extractUsedToolNames(code, availableTools);
|
|
288
|
+
expect(used.has('get_weather')).toBe(false);
|
|
289
|
+
});
|
|
290
|
+
|
|
291
|
+
it('matches tool names in different contexts', () => {
|
|
292
|
+
const code = `# direct call
|
|
293
|
+
x = await calculator(expression="1+1")
|
|
294
|
+
# in list comprehension
|
|
295
|
+
results = [await get_weather(city=c) for c in cities]
|
|
296
|
+
# conditional
|
|
297
|
+
if condition:
|
|
298
|
+
await get_team_members()`;
|
|
299
|
+
|
|
300
|
+
const used = extractUsedToolNames(code, availableTools);
|
|
301
|
+
|
|
302
|
+
expect(used.size).toBe(3);
|
|
303
|
+
expect(used.has('calculator')).toBe(true);
|
|
304
|
+
expect(used.has('get_weather')).toBe(true);
|
|
305
|
+
expect(used.has('get_team_members')).toBe(true);
|
|
306
|
+
});
|
|
307
|
+
|
|
308
|
+
it('returns empty set when no tools are used', () => {
|
|
309
|
+
const code = `print("Hello, World!")
|
|
310
|
+
x = 1 + 2`;
|
|
311
|
+
|
|
312
|
+
const used = extractUsedToolNames(code, availableTools);
|
|
313
|
+
expect(used.size).toBe(0);
|
|
314
|
+
});
|
|
315
|
+
|
|
316
|
+
it('handles tool names with special characters via normalization', () => {
|
|
317
|
+
const specialTools = createToolMap(['get_data.v2', 'calc+plus']);
|
|
318
|
+
const code = `await get_datav2()
|
|
319
|
+
await calcplus()`;
|
|
320
|
+
|
|
321
|
+
const used = extractUsedToolNames(code, specialTools);
|
|
322
|
+
|
|
323
|
+
expect(used.has('get_data.v2')).toBe(true);
|
|
324
|
+
expect(used.has('calc+plus')).toBe(true);
|
|
325
|
+
});
|
|
326
|
+
|
|
327
|
+
it('matches hyphenated tool names using underscore in code', () => {
|
|
328
|
+
const mcpTools = createToolMap([
|
|
329
|
+
'create_spreadsheet_mcp_Google-Workspace',
|
|
330
|
+
'search_gmail_mcp_Google-Workspace',
|
|
331
|
+
]);
|
|
332
|
+
const code = `result = await create_spreadsheet_mcp_Google_Workspace(title="Test")
|
|
333
|
+
print(result)`;
|
|
334
|
+
|
|
335
|
+
const used = extractUsedToolNames(code, mcpTools);
|
|
336
|
+
|
|
337
|
+
expect(used.size).toBe(1);
|
|
338
|
+
expect(used.has('create_spreadsheet_mcp_Google-Workspace')).toBe(true);
|
|
339
|
+
});
|
|
340
|
+
});
|
|
341
|
+
|
|
342
|
+
describe('filterToolsByUsage', () => {
|
|
343
|
+
const allToolDefs: t.LCTool[] = [
|
|
344
|
+
{
|
|
345
|
+
name: 'get_weather',
|
|
346
|
+
description: 'Get weather for a city',
|
|
347
|
+
parameters: {
|
|
348
|
+
type: 'object',
|
|
349
|
+
properties: { city: { type: 'string' } },
|
|
350
|
+
},
|
|
351
|
+
},
|
|
352
|
+
{
|
|
353
|
+
name: 'get_team_members',
|
|
354
|
+
description: 'Get team members',
|
|
355
|
+
parameters: { type: 'object', properties: {} },
|
|
356
|
+
},
|
|
357
|
+
{
|
|
358
|
+
name: 'get_expenses',
|
|
359
|
+
description: 'Get expenses for a user',
|
|
360
|
+
parameters: {
|
|
361
|
+
type: 'object',
|
|
362
|
+
properties: { user_id: { type: 'string' } },
|
|
363
|
+
},
|
|
364
|
+
},
|
|
365
|
+
{
|
|
366
|
+
name: 'calculator',
|
|
367
|
+
description: 'Evaluate an expression',
|
|
368
|
+
parameters: {
|
|
369
|
+
type: 'object',
|
|
370
|
+
properties: { expression: { type: 'string' } },
|
|
371
|
+
},
|
|
372
|
+
},
|
|
373
|
+
];
|
|
374
|
+
|
|
375
|
+
it('filters to only used tools', () => {
|
|
376
|
+
const code = `result = await get_weather(city="SF")
|
|
377
|
+
print(result)`;
|
|
378
|
+
|
|
379
|
+
const filtered = filterToolsByUsage(allToolDefs, code);
|
|
380
|
+
|
|
381
|
+
expect(filtered).toHaveLength(1);
|
|
382
|
+
expect(filtered[0].name).toBe('get_weather');
|
|
383
|
+
});
|
|
384
|
+
|
|
385
|
+
it('filters to multiple used tools', () => {
|
|
386
|
+
const code = `team = await get_team_members()
|
|
387
|
+
for member in team:
|
|
388
|
+
expenses = await get_expenses(user_id=member['id'])`;
|
|
389
|
+
|
|
390
|
+
const filtered = filterToolsByUsage(allToolDefs, code);
|
|
391
|
+
|
|
392
|
+
expect(filtered).toHaveLength(2);
|
|
393
|
+
expect(filtered.map((t) => t.name).sort()).toEqual([
|
|
394
|
+
'get_expenses',
|
|
395
|
+
'get_team_members',
|
|
396
|
+
]);
|
|
397
|
+
});
|
|
398
|
+
|
|
399
|
+
it('returns all tools when no tools are detected', () => {
|
|
400
|
+
const code = 'print("Hello, World!")';
|
|
401
|
+
|
|
402
|
+
const filtered = filterToolsByUsage(allToolDefs, code);
|
|
403
|
+
|
|
404
|
+
expect(filtered).toHaveLength(4);
|
|
405
|
+
});
|
|
406
|
+
|
|
407
|
+
it('preserves tool definition structure', () => {
|
|
408
|
+
const code = 'await calculator(expression="2+2")';
|
|
409
|
+
|
|
410
|
+
const filtered = filterToolsByUsage(allToolDefs, code);
|
|
411
|
+
|
|
412
|
+
expect(filtered).toHaveLength(1);
|
|
413
|
+
expect(filtered[0]).toEqual(allToolDefs[3]);
|
|
414
|
+
expect(filtered[0].parameters).toBeDefined();
|
|
415
|
+
expect(filtered[0].description).toBe('Evaluate an expression');
|
|
416
|
+
});
|
|
417
|
+
|
|
418
|
+
it('handles empty tool definitions', () => {
|
|
419
|
+
const code = 'await get_weather(city="SF")';
|
|
420
|
+
const filtered = filterToolsByUsage([], code);
|
|
421
|
+
|
|
422
|
+
expect(filtered).toHaveLength(0);
|
|
423
|
+
});
|
|
424
|
+
});
|
|
425
|
+
|
|
426
|
+
describe('formatCompletedResponse', () => {
|
|
427
|
+
it('formats response with stdout', () => {
|
|
428
|
+
const response: t.ProgrammaticExecutionResponse = {
|
|
429
|
+
status: 'completed',
|
|
430
|
+
stdout: 'Hello, World!\n',
|
|
431
|
+
stderr: '',
|
|
432
|
+
files: [],
|
|
433
|
+
session_id: 'sess_abc123',
|
|
434
|
+
};
|
|
435
|
+
|
|
436
|
+
const [output, artifact] = formatCompletedResponse(response);
|
|
437
|
+
|
|
438
|
+
expect(output).toContain('stdout:\nHello, World!');
|
|
439
|
+
expect(artifact.session_id).toBe('sess_abc123');
|
|
440
|
+
expect(artifact.files).toEqual([]);
|
|
441
|
+
});
|
|
442
|
+
|
|
443
|
+
it('shows empty output message when no stdout', () => {
|
|
444
|
+
const response: t.ProgrammaticExecutionResponse = {
|
|
445
|
+
status: 'completed',
|
|
446
|
+
stdout: '',
|
|
447
|
+
stderr: '',
|
|
448
|
+
files: [],
|
|
449
|
+
session_id: 'sess_abc123',
|
|
450
|
+
};
|
|
451
|
+
|
|
452
|
+
const [output] = formatCompletedResponse(response);
|
|
453
|
+
|
|
454
|
+
expect(output).toContain(
|
|
455
|
+
'stdout: Empty. Ensure you\'re writing output explicitly'
|
|
456
|
+
);
|
|
457
|
+
});
|
|
458
|
+
|
|
459
|
+
it('includes stderr when present', () => {
|
|
460
|
+
const response: t.ProgrammaticExecutionResponse = {
|
|
461
|
+
status: 'completed',
|
|
462
|
+
stdout: 'Output\n',
|
|
463
|
+
stderr: 'Warning: deprecated function\n',
|
|
464
|
+
files: [],
|
|
465
|
+
session_id: 'sess_abc123',
|
|
466
|
+
};
|
|
467
|
+
|
|
468
|
+
const [output] = formatCompletedResponse(response);
|
|
469
|
+
|
|
470
|
+
expect(output).toContain('stdout:\nOutput');
|
|
471
|
+
expect(output).toContain('stderr:\nWarning: deprecated function');
|
|
472
|
+
});
|
|
473
|
+
|
|
474
|
+
it('formats file information correctly', () => {
|
|
475
|
+
const response: t.ProgrammaticExecutionResponse = {
|
|
476
|
+
status: 'completed',
|
|
477
|
+
stdout: 'Generated report\n',
|
|
478
|
+
stderr: '',
|
|
479
|
+
files: [
|
|
480
|
+
{ id: '1', name: 'report.pdf' },
|
|
481
|
+
{ id: '2', name: 'data.csv' },
|
|
482
|
+
],
|
|
483
|
+
session_id: 'sess_abc123',
|
|
484
|
+
};
|
|
485
|
+
|
|
486
|
+
const [output, artifact] = formatCompletedResponse(response);
|
|
487
|
+
|
|
488
|
+
expect(output).toContain('Generated files:');
|
|
489
|
+
expect(output).toContain('report.pdf');
|
|
490
|
+
expect(output).toContain('data.csv');
|
|
491
|
+
expect(output).toContain('session_id: sess_abc123');
|
|
492
|
+
expect(artifact.files).toHaveLength(2);
|
|
493
|
+
expect(artifact.files).toEqual(response.files);
|
|
494
|
+
});
|
|
495
|
+
|
|
496
|
+
it('handles image files with special message', () => {
|
|
497
|
+
const response: t.ProgrammaticExecutionResponse = {
|
|
498
|
+
status: 'completed',
|
|
499
|
+
stdout: '',
|
|
500
|
+
stderr: '',
|
|
501
|
+
files: [
|
|
502
|
+
{ id: '1', name: 'chart.png' },
|
|
503
|
+
{ id: '2', name: 'photo.jpg' },
|
|
504
|
+
],
|
|
505
|
+
session_id: 'sess_abc123',
|
|
506
|
+
};
|
|
507
|
+
|
|
508
|
+
const [output] = formatCompletedResponse(response);
|
|
509
|
+
|
|
510
|
+
expect(output).toContain('chart.png');
|
|
511
|
+
expect(output).toContain('Image is already displayed to the user');
|
|
512
|
+
});
|
|
513
|
+
});
|
|
514
|
+
|
|
515
|
+
describe('createProgrammaticToolCallingTool - Manual Invocation', () => {
|
|
516
|
+
let ptcTool: ReturnType<typeof createProgrammaticToolCallingTool>;
|
|
517
|
+
let toolMap: t.ToolMap;
|
|
518
|
+
let toolDefinitions: t.LCTool[];
|
|
519
|
+
|
|
520
|
+
beforeEach(() => {
|
|
521
|
+
const tools = [
|
|
522
|
+
createGetTeamMembersTool(),
|
|
523
|
+
createGetExpensesTool(),
|
|
524
|
+
createGetWeatherTool(),
|
|
525
|
+
];
|
|
526
|
+
toolMap = new Map(tools.map((t) => [t.name, t]));
|
|
527
|
+
toolDefinitions = Array.from(
|
|
528
|
+
createProgrammaticToolRegistry().values()
|
|
529
|
+
).filter((t) =>
|
|
530
|
+
['get_team_members', 'get_expenses', 'get_weather'].includes(t.name)
|
|
531
|
+
);
|
|
532
|
+
|
|
533
|
+
ptcTool = createProgrammaticToolCallingTool({
|
|
534
|
+
apiKey: 'test-key',
|
|
535
|
+
baseUrl: 'http://mock-api',
|
|
536
|
+
});
|
|
537
|
+
});
|
|
538
|
+
|
|
539
|
+
it('throws error when no toolMap provided', async () => {
|
|
540
|
+
await expect(
|
|
541
|
+
ptcTool.invoke({
|
|
542
|
+
code: 'result = await get_weather(city="SF")\nprint(result)',
|
|
543
|
+
tools: toolDefinitions,
|
|
544
|
+
toolMap,
|
|
545
|
+
})
|
|
546
|
+
).rejects.toThrow('No toolMap provided');
|
|
547
|
+
});
|
|
548
|
+
|
|
549
|
+
it('throws error when toolMap is empty', async () => {
|
|
550
|
+
const args = {
|
|
551
|
+
code: 'result = await get_weather(city="SF")\nprint(result)',
|
|
552
|
+
tools: toolDefinitions,
|
|
553
|
+
toolMap: new Map(),
|
|
554
|
+
};
|
|
555
|
+
const toolCall = {
|
|
556
|
+
name: 'programmatic_tool_calling',
|
|
557
|
+
args,
|
|
558
|
+
};
|
|
559
|
+
await expect(
|
|
560
|
+
ptcTool.invoke(args, {
|
|
561
|
+
toolCall,
|
|
562
|
+
})
|
|
563
|
+
).rejects.toThrow('No toolMap provided');
|
|
564
|
+
});
|
|
565
|
+
|
|
566
|
+
it('throws error when no tool definitions provided', async () => {
|
|
567
|
+
const args = {
|
|
568
|
+
code: 'result = await get_weather(city="SF")\nprint(result)',
|
|
569
|
+
// No tools
|
|
570
|
+
};
|
|
571
|
+
const toolCall = {
|
|
572
|
+
name: 'programmatic_code_execution',
|
|
573
|
+
args,
|
|
574
|
+
toolMap,
|
|
575
|
+
// No `toolDefs`
|
|
576
|
+
};
|
|
577
|
+
|
|
578
|
+
await expect(ptcTool.invoke(args, { toolCall })).rejects.toThrow(
|
|
579
|
+
'No tool definitions provided'
|
|
580
|
+
);
|
|
581
|
+
});
|
|
582
|
+
|
|
583
|
+
it('uses toolDefs from config when tools not provided', async () => {
|
|
584
|
+
// Skip this test - requires mocking fetch which has complex typing
|
|
585
|
+
// This functionality is tested in the live script tests instead
|
|
586
|
+
});
|
|
587
|
+
});
|
|
588
|
+
|
|
589
|
+
describe('Tool Classification', () => {
|
|
590
|
+
it('filters tools by allowed_callers', () => {
|
|
591
|
+
const registry = createProgrammaticToolRegistry();
|
|
592
|
+
|
|
593
|
+
const codeExecutionTools = Array.from(registry.values()).filter((t) =>
|
|
594
|
+
(t.allowed_callers ?? ['direct']).includes('code_execution')
|
|
595
|
+
);
|
|
596
|
+
// get_team_members, get_expenses, calculator: code_execution only
|
|
597
|
+
const codeOnlyTools = codeExecutionTools.filter(
|
|
598
|
+
(t) => !(t.allowed_callers?.includes('direct') === true)
|
|
599
|
+
);
|
|
600
|
+
expect(codeOnlyTools.length).toBeGreaterThanOrEqual(3);
|
|
601
|
+
|
|
602
|
+
// get_weather: both direct and code_execution
|
|
603
|
+
const bothTools = Array.from(registry.values()).filter(
|
|
604
|
+
(t) =>
|
|
605
|
+
t.allowed_callers?.includes('direct') === true &&
|
|
606
|
+
t.allowed_callers.includes('code_execution')
|
|
607
|
+
);
|
|
608
|
+
expect(bothTools.length).toBeGreaterThanOrEqual(1);
|
|
609
|
+
expect(bothTools.some((t) => t.name === 'get_weather')).toBe(true);
|
|
610
|
+
});
|
|
611
|
+
});
|
|
612
|
+
|
|
613
|
+
describe('Error Handling', () => {
|
|
614
|
+
let toolMap: t.ToolMap;
|
|
615
|
+
|
|
616
|
+
beforeEach(() => {
|
|
617
|
+
const tools = [createGetWeatherTool()];
|
|
618
|
+
toolMap = new Map(tools.map((t) => [t.name, t]));
|
|
619
|
+
});
|
|
620
|
+
|
|
621
|
+
it('returns error for invalid city without throwing', async () => {
|
|
622
|
+
const toolCalls: t.PTCToolCall[] = [
|
|
623
|
+
{
|
|
624
|
+
id: 'call_001',
|
|
625
|
+
name: 'get_weather',
|
|
626
|
+
input: { city: 'InvalidCity' },
|
|
627
|
+
},
|
|
628
|
+
];
|
|
629
|
+
|
|
630
|
+
const results = await executeTools(toolCalls, toolMap);
|
|
631
|
+
|
|
632
|
+
expect(results).toHaveLength(1);
|
|
633
|
+
expect(results[0].is_error).toBe(true);
|
|
634
|
+
expect(results[0].result).toBeNull();
|
|
635
|
+
expect(results[0].error_message).toContain('Weather data not available');
|
|
636
|
+
});
|
|
637
|
+
|
|
638
|
+
it('continues execution when one tool fails', async () => {
|
|
639
|
+
const toolCalls: t.PTCToolCall[] = [
|
|
640
|
+
{
|
|
641
|
+
id: 'call_001',
|
|
642
|
+
name: 'get_weather',
|
|
643
|
+
input: { city: 'San Francisco' },
|
|
644
|
+
},
|
|
645
|
+
{
|
|
646
|
+
id: 'call_002',
|
|
647
|
+
name: 'get_weather',
|
|
648
|
+
input: { city: 'InvalidCity' },
|
|
649
|
+
},
|
|
650
|
+
{
|
|
651
|
+
id: 'call_003',
|
|
652
|
+
name: 'get_weather',
|
|
653
|
+
input: { city: 'London' },
|
|
654
|
+
},
|
|
655
|
+
];
|
|
656
|
+
|
|
657
|
+
const results = await executeTools(toolCalls, toolMap);
|
|
658
|
+
|
|
659
|
+
expect(results).toHaveLength(3);
|
|
660
|
+
expect(results[0].is_error).toBe(false);
|
|
661
|
+
expect(results[1].is_error).toBe(true);
|
|
662
|
+
expect(results[2].is_error).toBe(false);
|
|
663
|
+
});
|
|
664
|
+
});
|
|
665
|
+
|
|
666
|
+
describe('Parallel Execution Performance', () => {
|
|
667
|
+
let toolMap: t.ToolMap;
|
|
668
|
+
|
|
669
|
+
beforeEach(() => {
|
|
670
|
+
const tools = [createGetExpensesTool()];
|
|
671
|
+
toolMap = new Map(tools.map((t) => [t.name, t]));
|
|
672
|
+
});
|
|
673
|
+
|
|
674
|
+
it('executes tools in parallel, not sequentially', async () => {
|
|
675
|
+
const toolCalls: t.PTCToolCall[] = [
|
|
676
|
+
{ id: 'call_001', name: 'get_expenses', input: { user_id: 'u1' } },
|
|
677
|
+
{ id: 'call_002', name: 'get_expenses', input: { user_id: 'u2' } },
|
|
678
|
+
{ id: 'call_003', name: 'get_expenses', input: { user_id: 'u3' } },
|
|
679
|
+
];
|
|
680
|
+
|
|
681
|
+
const startTime = Date.now();
|
|
682
|
+
const results = await executeTools(toolCalls, toolMap);
|
|
683
|
+
const duration = Date.now() - startTime;
|
|
684
|
+
|
|
685
|
+
// Each tool has 30ms delay
|
|
686
|
+
// Sequential would be ~90ms, parallel should be ~30-50ms
|
|
687
|
+
expect(duration).toBeLessThan(80);
|
|
688
|
+
expect(results).toHaveLength(3);
|
|
689
|
+
expect(results.every((r) => r.is_error === false)).toBe(true);
|
|
690
|
+
});
|
|
691
|
+
});
|
|
692
|
+
|
|
693
|
+
describe('Response Formatting', () => {
|
|
694
|
+
it('formats stdout-only response', () => {
|
|
695
|
+
const response: t.ProgrammaticExecutionResponse = {
|
|
696
|
+
status: 'completed',
|
|
697
|
+
stdout: 'Team size: 3\n- Alice\n- Bob\n- Charlie\n',
|
|
698
|
+
stderr: '',
|
|
699
|
+
files: [],
|
|
700
|
+
session_id: 'sess_xyz',
|
|
701
|
+
};
|
|
702
|
+
|
|
703
|
+
const [output, artifact] = formatCompletedResponse(response);
|
|
704
|
+
|
|
705
|
+
expect(output).toBe('stdout:\nTeam size: 3\n- Alice\n- Bob\n- Charlie');
|
|
706
|
+
expect(artifact).toEqual({
|
|
707
|
+
session_id: 'sess_xyz',
|
|
708
|
+
files: [],
|
|
709
|
+
});
|
|
710
|
+
});
|
|
711
|
+
|
|
712
|
+
it('formats response with files', () => {
|
|
713
|
+
const response: t.ProgrammaticExecutionResponse = {
|
|
714
|
+
status: 'completed',
|
|
715
|
+
stdout: 'Report generated\n',
|
|
716
|
+
stderr: '',
|
|
717
|
+
files: [
|
|
718
|
+
{ id: '1', name: 'report.csv' },
|
|
719
|
+
{ id: '2', name: 'chart.png' },
|
|
720
|
+
],
|
|
721
|
+
session_id: 'sess_xyz',
|
|
722
|
+
};
|
|
723
|
+
|
|
724
|
+
const [output, artifact] = formatCompletedResponse(response);
|
|
725
|
+
|
|
726
|
+
expect(output).toContain('Generated files:');
|
|
727
|
+
expect(output).toContain('report.csv');
|
|
728
|
+
expect(output).toContain('chart.png');
|
|
729
|
+
expect(output).toContain('session_id: sess_xyz');
|
|
730
|
+
expect(output).toContain('File is already downloaded');
|
|
731
|
+
expect(output).toContain('Image is already displayed');
|
|
732
|
+
expect(artifact.files).toHaveLength(2);
|
|
733
|
+
});
|
|
734
|
+
|
|
735
|
+
it('handles multiple files with correct separators', () => {
|
|
736
|
+
const response: t.ProgrammaticExecutionResponse = {
|
|
737
|
+
status: 'completed',
|
|
738
|
+
stdout: 'Done\n',
|
|
739
|
+
stderr: '',
|
|
740
|
+
files: [
|
|
741
|
+
{ id: '1', name: 'file1.txt' },
|
|
742
|
+
{ id: '2', name: 'file2.txt' },
|
|
743
|
+
],
|
|
744
|
+
session_id: 'sess_xyz',
|
|
745
|
+
};
|
|
746
|
+
|
|
747
|
+
const [output] = formatCompletedResponse(response);
|
|
748
|
+
|
|
749
|
+
// 2 files format: "- /mnt/data/file1.txt | ..., - /mnt/data/file2.txt | ..."
|
|
750
|
+
expect(output).toContain('file1.txt');
|
|
751
|
+
expect(output).toContain('file2.txt');
|
|
752
|
+
expect(output).toContain('- /mnt/data/file1.txt');
|
|
753
|
+
expect(output).toContain('- /mnt/data/file2.txt');
|
|
754
|
+
});
|
|
755
|
+
|
|
756
|
+
it('handles many files with newline separators', () => {
|
|
757
|
+
const response: t.ProgrammaticExecutionResponse = {
|
|
758
|
+
status: 'completed',
|
|
759
|
+
stdout: 'Done\n',
|
|
760
|
+
stderr: '',
|
|
761
|
+
files: [
|
|
762
|
+
{ id: '1', name: 'file1.txt' },
|
|
763
|
+
{ id: '2', name: 'file2.txt' },
|
|
764
|
+
{ id: '3', name: 'file3.txt' },
|
|
765
|
+
{ id: '4', name: 'file4.txt' },
|
|
766
|
+
],
|
|
767
|
+
session_id: 'sess_xyz',
|
|
768
|
+
};
|
|
769
|
+
|
|
770
|
+
const [output] = formatCompletedResponse(response);
|
|
771
|
+
|
|
772
|
+
// More than 3 files should use newline separators
|
|
773
|
+
expect(output).toContain('file1.txt');
|
|
774
|
+
expect(output).toContain('file4.txt');
|
|
775
|
+
expect(output.match(/,\n/g)?.length).toBeGreaterThanOrEqual(2);
|
|
776
|
+
});
|
|
777
|
+
});
|
|
778
|
+
|
|
779
|
+
describe('Tool Data Extraction', () => {
|
|
780
|
+
let toolMap: t.ToolMap;
|
|
781
|
+
|
|
782
|
+
beforeEach(() => {
|
|
783
|
+
const tools = [
|
|
784
|
+
createGetTeamMembersTool(),
|
|
785
|
+
createGetExpensesTool(),
|
|
786
|
+
createCalculatorTool(),
|
|
787
|
+
];
|
|
788
|
+
toolMap = new Map(tools.map((t) => [t.name, t]));
|
|
789
|
+
});
|
|
790
|
+
|
|
791
|
+
it('extracts correct data from team members tool', async () => {
|
|
792
|
+
const toolCalls: t.PTCToolCall[] = [
|
|
793
|
+
{ id: 'call_001', name: 'get_team_members', input: {} },
|
|
794
|
+
];
|
|
795
|
+
|
|
796
|
+
const results = await executeTools(toolCalls, toolMap);
|
|
797
|
+
|
|
798
|
+
expect(results[0].result).toEqual([
|
|
799
|
+
{ id: 'u1', name: 'Alice', department: 'Engineering' },
|
|
800
|
+
{ id: 'u2', name: 'Bob', department: 'Marketing' },
|
|
801
|
+
{ id: 'u3', name: 'Charlie', department: 'Engineering' },
|
|
802
|
+
]);
|
|
803
|
+
});
|
|
804
|
+
|
|
805
|
+
it('extracts correct data from expenses tool', async () => {
|
|
806
|
+
const toolCalls: t.PTCToolCall[] = [
|
|
807
|
+
{ id: 'call_001', name: 'get_expenses', input: { user_id: 'u1' } },
|
|
808
|
+
];
|
|
809
|
+
|
|
810
|
+
const results = await executeTools(toolCalls, toolMap);
|
|
811
|
+
|
|
812
|
+
expect(results[0].result).toEqual([
|
|
813
|
+
{ amount: 150.0, category: 'travel' },
|
|
814
|
+
{ amount: 75.5, category: 'meals' },
|
|
815
|
+
]);
|
|
816
|
+
});
|
|
817
|
+
|
|
818
|
+
it('handles empty expense data', async () => {
|
|
819
|
+
const toolCalls: t.PTCToolCall[] = [
|
|
820
|
+
{
|
|
821
|
+
id: 'call_001',
|
|
822
|
+
name: 'get_expenses',
|
|
823
|
+
input: { user_id: 'nonexistent' },
|
|
824
|
+
},
|
|
825
|
+
];
|
|
826
|
+
|
|
827
|
+
const results = await executeTools(toolCalls, toolMap);
|
|
828
|
+
|
|
829
|
+
expect(results[0].is_error).toBe(false);
|
|
830
|
+
expect(results[0].result).toEqual([]);
|
|
831
|
+
});
|
|
832
|
+
|
|
833
|
+
it('calculates correct result', async () => {
|
|
834
|
+
const toolCalls: t.PTCToolCall[] = [
|
|
835
|
+
{
|
|
836
|
+
id: 'call_001',
|
|
837
|
+
name: 'calculator',
|
|
838
|
+
input: { expression: '2 + 2 * 3' },
|
|
839
|
+
},
|
|
840
|
+
{
|
|
841
|
+
id: 'call_002',
|
|
842
|
+
name: 'calculator',
|
|
843
|
+
input: { expression: '(10 + 5) / 3' },
|
|
844
|
+
},
|
|
845
|
+
];
|
|
846
|
+
|
|
847
|
+
const results = await executeTools(toolCalls, toolMap);
|
|
848
|
+
|
|
849
|
+
expect(results[0].result.result).toBe(8);
|
|
850
|
+
expect(results[1].result.result).toBe(5);
|
|
851
|
+
});
|
|
852
|
+
});
|
|
853
|
+
});
|