@librechat/agents 3.0.35 → 3.0.40
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/agents/AgentContext.cjs +71 -2
- 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 -0
- package/dist/cjs/events.cjs.map +1 -1
- package/dist/cjs/graphs/Graph.cjs +7 -2
- package/dist/cjs/graphs/Graph.cjs.map +1 -1
- package/dist/cjs/instrumentation.cjs +1 -1
- package/dist/cjs/instrumentation.cjs.map +1 -1
- package/dist/cjs/main.cjs +12 -0
- package/dist/cjs/main.cjs.map +1 -1
- package/dist/cjs/tools/ProgrammaticToolCalling.cjs +329 -0
- package/dist/cjs/tools/ProgrammaticToolCalling.cjs.map +1 -0
- package/dist/cjs/tools/ToolNode.cjs +34 -3
- 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/esm/agents/AgentContext.mjs +71 -2
- 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 -1
- package/dist/esm/events.mjs.map +1 -1
- package/dist/esm/graphs/Graph.mjs +7 -2
- package/dist/esm/graphs/Graph.mjs.map +1 -1
- package/dist/esm/instrumentation.mjs +1 -1
- package/dist/esm/instrumentation.mjs.map +1 -1
- package/dist/esm/main.mjs +2 -0
- package/dist/esm/main.mjs.map +1 -1
- package/dist/esm/tools/ProgrammaticToolCalling.mjs +324 -0
- package/dist/esm/tools/ProgrammaticToolCalling.mjs.map +1 -0
- package/dist/esm/tools/ToolNode.mjs +34 -3
- 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/types/agents/AgentContext.d.ts +25 -1
- package/dist/types/common/enum.d.ts +2 -0
- package/dist/types/graphs/Graph.d.ts +2 -1
- package/dist/types/index.d.ts +2 -0
- package/dist/types/test/mockTools.d.ts +28 -0
- package/dist/types/tools/ProgrammaticToolCalling.d.ts +86 -0
- package/dist/types/tools/ToolNode.d.ts +7 -1
- package/dist/types/tools/ToolSearchRegex.d.ts +80 -0
- package/dist/types/types/graph.d.ts +7 -1
- package/dist/types/types/tools.d.ts +136 -0
- package/package.json +5 -1
- package/src/agents/AgentContext.ts +86 -0
- package/src/common/enum.ts +2 -0
- package/src/events.ts +5 -1
- package/src/graphs/Graph.ts +8 -1
- package/src/index.ts +2 -0
- package/src/instrumentation.ts +1 -1
- package/src/llm/google/llm.spec.ts +3 -1
- package/src/scripts/code_exec_ptc.ts +277 -0
- package/src/scripts/programmatic_exec.ts +396 -0
- package/src/scripts/programmatic_exec_agent.ts +231 -0
- package/src/scripts/tool_search_regex.ts +162 -0
- package/src/test/mockTools.ts +366 -0
- package/src/tools/ProgrammaticToolCalling.ts +423 -0
- package/src/tools/ToolNode.ts +38 -4
- package/src/tools/ToolSearchRegex.ts +535 -0
- package/src/tools/__tests__/ProgrammaticToolCalling.integration.test.ts +318 -0
- package/src/tools/__tests__/ProgrammaticToolCalling.test.ts +613 -0
- package/src/tools/__tests__/ToolSearchRegex.integration.test.ts +161 -0
- package/src/tools/__tests__/ToolSearchRegex.test.ts +232 -0
- package/src/types/graph.ts +7 -1
- package/src/types/tools.ts +166 -0
|
@@ -0,0 +1,366 @@
|
|
|
1
|
+
// src/test/mockTools.ts
|
|
2
|
+
/**
|
|
3
|
+
* Shared mock tools for testing across all test scripts.
|
|
4
|
+
* Centralizes tool definitions to follow DRY principles.
|
|
5
|
+
*/
|
|
6
|
+
import { z } from 'zod';
|
|
7
|
+
import { tool } from '@langchain/core/tools';
|
|
8
|
+
import type { StructuredToolInterface } from '@langchain/core/tools';
|
|
9
|
+
import type { LCTool, LCToolRegistry } from '@/types';
|
|
10
|
+
|
|
11
|
+
// ============================================================================
|
|
12
|
+
// Mock Tool Implementations
|
|
13
|
+
// ============================================================================
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Mock get_team_members tool - returns list of team members
|
|
17
|
+
*/
|
|
18
|
+
export function createGetTeamMembersTool(): StructuredToolInterface {
|
|
19
|
+
return tool(
|
|
20
|
+
async () => {
|
|
21
|
+
await new Promise((resolve) => setTimeout(resolve, 50));
|
|
22
|
+
return [
|
|
23
|
+
{ id: 'u1', name: 'Alice', department: 'Engineering' },
|
|
24
|
+
{ id: 'u2', name: 'Bob', department: 'Marketing' },
|
|
25
|
+
{ id: 'u3', name: 'Charlie', department: 'Engineering' },
|
|
26
|
+
];
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
name: 'get_team_members',
|
|
30
|
+
description:
|
|
31
|
+
'Get list of team members. Returns array of objects with id, name, and department fields.',
|
|
32
|
+
schema: z.object({}),
|
|
33
|
+
}
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Mock get_expenses tool - returns expense records for a user
|
|
39
|
+
*/
|
|
40
|
+
export function createGetExpensesTool(): StructuredToolInterface {
|
|
41
|
+
const expenseData: Record<
|
|
42
|
+
string,
|
|
43
|
+
Array<{ amount: number; category: string }>
|
|
44
|
+
> = {
|
|
45
|
+
u1: [
|
|
46
|
+
{ amount: 150.0, category: 'travel' },
|
|
47
|
+
{ amount: 75.5, category: 'meals' },
|
|
48
|
+
],
|
|
49
|
+
u2: [
|
|
50
|
+
{ amount: 200.0, category: 'marketing' },
|
|
51
|
+
{ amount: 50.0, category: 'meals' },
|
|
52
|
+
{ amount: 300.0, category: 'events' },
|
|
53
|
+
],
|
|
54
|
+
u3: [
|
|
55
|
+
{ amount: 500.0, category: 'equipment' },
|
|
56
|
+
{ amount: 120.0, category: 'travel' },
|
|
57
|
+
{ amount: 80.0, category: 'meals' },
|
|
58
|
+
],
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
return tool(
|
|
62
|
+
async ({ user_id }: { user_id: string }) => {
|
|
63
|
+
await new Promise((resolve) => setTimeout(resolve, 30));
|
|
64
|
+
return expenseData[user_id] ?? [];
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
name: 'get_expenses',
|
|
68
|
+
description:
|
|
69
|
+
'Get expense records for a user. Returns array of objects with amount and category fields.',
|
|
70
|
+
schema: z.object({
|
|
71
|
+
user_id: z.string().describe('The user ID to fetch expenses for'),
|
|
72
|
+
}),
|
|
73
|
+
}
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Mock get_weather tool - returns weather data for a city
|
|
79
|
+
*/
|
|
80
|
+
export function createGetWeatherTool(): StructuredToolInterface {
|
|
81
|
+
const weatherData: Record<
|
|
82
|
+
string,
|
|
83
|
+
{ temperature: number; condition: string } | undefined
|
|
84
|
+
> = {
|
|
85
|
+
'San Francisco': { temperature: 65, condition: 'Foggy' },
|
|
86
|
+
'New York': { temperature: 75, condition: 'Sunny' },
|
|
87
|
+
London: { temperature: 55, condition: 'Rainy' },
|
|
88
|
+
Tokyo: { temperature: 80, condition: 'Humid' },
|
|
89
|
+
SF: { temperature: 65, condition: 'Foggy' },
|
|
90
|
+
NYC: { temperature: 75, condition: 'Sunny' },
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
return tool(
|
|
94
|
+
async ({ city }: { city: string }) => {
|
|
95
|
+
await new Promise((resolve) => setTimeout(resolve, 40));
|
|
96
|
+
const weather = weatherData[city];
|
|
97
|
+
if (!weather) {
|
|
98
|
+
throw new Error(`Weather data not available for city: ${city}`);
|
|
99
|
+
}
|
|
100
|
+
return weather;
|
|
101
|
+
},
|
|
102
|
+
{
|
|
103
|
+
name: 'get_weather',
|
|
104
|
+
description:
|
|
105
|
+
'Get current weather for a city. Returns object with temperature (number) and condition (string) fields.',
|
|
106
|
+
schema: z.object({
|
|
107
|
+
city: z.string().describe('City name'),
|
|
108
|
+
}),
|
|
109
|
+
}
|
|
110
|
+
);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Mock calculator tool - evaluates mathematical expressions
|
|
115
|
+
*/
|
|
116
|
+
export function createCalculatorTool(): StructuredToolInterface {
|
|
117
|
+
return tool(
|
|
118
|
+
async ({ expression }: { expression: string }) => {
|
|
119
|
+
await new Promise((resolve) => setTimeout(resolve, 10));
|
|
120
|
+
// Simple eval for demo (in production, use a proper math parser)
|
|
121
|
+
|
|
122
|
+
const result = eval(expression);
|
|
123
|
+
return { expression, result };
|
|
124
|
+
},
|
|
125
|
+
{
|
|
126
|
+
name: 'calculator',
|
|
127
|
+
description: 'Evaluate a mathematical expression',
|
|
128
|
+
schema: z.object({
|
|
129
|
+
expression: z.string().describe('Mathematical expression to evaluate'),
|
|
130
|
+
}),
|
|
131
|
+
}
|
|
132
|
+
);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
// ============================================================================
|
|
136
|
+
// Tool Registry Definitions
|
|
137
|
+
// ============================================================================
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Creates a tool registry for programmatic tool calling tests.
|
|
141
|
+
* Tools are configured with allowed_callers to demonstrate classification.
|
|
142
|
+
*/
|
|
143
|
+
export function createProgrammaticToolRegistry(): LCToolRegistry {
|
|
144
|
+
const toolDefs: LCTool[] = [
|
|
145
|
+
{
|
|
146
|
+
name: 'get_team_members',
|
|
147
|
+
description:
|
|
148
|
+
'Get list of team members. Returns array of objects with id, name, and department fields.',
|
|
149
|
+
parameters: {
|
|
150
|
+
type: 'object',
|
|
151
|
+
properties: {},
|
|
152
|
+
required: [],
|
|
153
|
+
},
|
|
154
|
+
allowed_callers: ['code_execution'], // Programmatic-only
|
|
155
|
+
defer_loading: false,
|
|
156
|
+
},
|
|
157
|
+
{
|
|
158
|
+
name: 'get_expenses',
|
|
159
|
+
description:
|
|
160
|
+
'Get expense records for a user. Returns array of objects with amount and category fields.',
|
|
161
|
+
parameters: {
|
|
162
|
+
type: 'object',
|
|
163
|
+
properties: {
|
|
164
|
+
user_id: {
|
|
165
|
+
type: 'string',
|
|
166
|
+
description: 'The user ID to fetch expenses for',
|
|
167
|
+
},
|
|
168
|
+
},
|
|
169
|
+
required: ['user_id'],
|
|
170
|
+
},
|
|
171
|
+
allowed_callers: ['code_execution'], // Programmatic-only
|
|
172
|
+
defer_loading: false,
|
|
173
|
+
},
|
|
174
|
+
{
|
|
175
|
+
name: 'get_weather',
|
|
176
|
+
description:
|
|
177
|
+
'Get current weather for a city. Returns object with temperature (number) and condition (string) fields.',
|
|
178
|
+
parameters: {
|
|
179
|
+
type: 'object',
|
|
180
|
+
properties: {
|
|
181
|
+
city: {
|
|
182
|
+
type: 'string',
|
|
183
|
+
description: 'City name',
|
|
184
|
+
},
|
|
185
|
+
},
|
|
186
|
+
required: ['city'],
|
|
187
|
+
},
|
|
188
|
+
allowed_callers: ['direct', 'code_execution'], // Both contexts
|
|
189
|
+
defer_loading: false,
|
|
190
|
+
},
|
|
191
|
+
{
|
|
192
|
+
name: 'calculator',
|
|
193
|
+
description: 'Evaluate a mathematical expression',
|
|
194
|
+
parameters: {
|
|
195
|
+
type: 'object',
|
|
196
|
+
properties: {
|
|
197
|
+
expression: {
|
|
198
|
+
type: 'string',
|
|
199
|
+
description: 'Mathematical expression to evaluate',
|
|
200
|
+
},
|
|
201
|
+
},
|
|
202
|
+
required: ['expression'],
|
|
203
|
+
},
|
|
204
|
+
allowed_callers: ['code_execution'], // Programmatic-only
|
|
205
|
+
defer_loading: false,
|
|
206
|
+
},
|
|
207
|
+
];
|
|
208
|
+
|
|
209
|
+
return new Map(toolDefs.map((t) => [t.name, t]));
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* Creates a sample tool registry for tool search tests.
|
|
214
|
+
* Includes mix of deferred and non-deferred tools.
|
|
215
|
+
*/
|
|
216
|
+
export function createToolSearchToolRegistry(): LCToolRegistry {
|
|
217
|
+
const tools: LCTool[] = [
|
|
218
|
+
{
|
|
219
|
+
name: 'get_expenses',
|
|
220
|
+
description:
|
|
221
|
+
'Retrieve expense records from the database. Supports filtering by date range, category, and amount.',
|
|
222
|
+
parameters: {
|
|
223
|
+
type: 'object',
|
|
224
|
+
properties: {
|
|
225
|
+
start_date: {
|
|
226
|
+
type: 'string',
|
|
227
|
+
description: 'Start date for filtering',
|
|
228
|
+
},
|
|
229
|
+
end_date: { type: 'string', description: 'End date for filtering' },
|
|
230
|
+
category: { type: 'string', description: 'Expense category' },
|
|
231
|
+
},
|
|
232
|
+
},
|
|
233
|
+
defer_loading: true,
|
|
234
|
+
},
|
|
235
|
+
{
|
|
236
|
+
name: 'calculate_expense_totals',
|
|
237
|
+
description:
|
|
238
|
+
'Calculate total expenses by category or time period. Returns aggregated financial data.',
|
|
239
|
+
parameters: {
|
|
240
|
+
type: 'object',
|
|
241
|
+
properties: {
|
|
242
|
+
group_by: {
|
|
243
|
+
type: 'string',
|
|
244
|
+
description: 'Group by category or month',
|
|
245
|
+
},
|
|
246
|
+
},
|
|
247
|
+
},
|
|
248
|
+
defer_loading: true,
|
|
249
|
+
},
|
|
250
|
+
{
|
|
251
|
+
name: 'create_budget',
|
|
252
|
+
description:
|
|
253
|
+
'Create a new budget plan with spending limits for different categories.',
|
|
254
|
+
parameters: {
|
|
255
|
+
type: 'object',
|
|
256
|
+
properties: {
|
|
257
|
+
name: { type: 'string', description: 'Budget name' },
|
|
258
|
+
limits: { type: 'object', description: 'Category spending limits' },
|
|
259
|
+
},
|
|
260
|
+
},
|
|
261
|
+
defer_loading: true,
|
|
262
|
+
},
|
|
263
|
+
{
|
|
264
|
+
name: 'get_weather',
|
|
265
|
+
description: 'Get current weather conditions for a specified location.',
|
|
266
|
+
parameters: {
|
|
267
|
+
type: 'object',
|
|
268
|
+
properties: {
|
|
269
|
+
location: { type: 'string', description: 'City or coordinates' },
|
|
270
|
+
},
|
|
271
|
+
},
|
|
272
|
+
defer_loading: true,
|
|
273
|
+
},
|
|
274
|
+
{
|
|
275
|
+
name: 'get_forecast',
|
|
276
|
+
description: 'Get weather forecast for the next 7 days for a location.',
|
|
277
|
+
parameters: {
|
|
278
|
+
type: 'object',
|
|
279
|
+
properties: {
|
|
280
|
+
location: { type: 'string', description: 'City or coordinates' },
|
|
281
|
+
days: { type: 'number', description: 'Number of days to forecast' },
|
|
282
|
+
},
|
|
283
|
+
},
|
|
284
|
+
defer_loading: true,
|
|
285
|
+
},
|
|
286
|
+
{
|
|
287
|
+
name: 'send_email',
|
|
288
|
+
description:
|
|
289
|
+
'Send an email to one or more recipients with attachments support.',
|
|
290
|
+
parameters: {
|
|
291
|
+
type: 'object',
|
|
292
|
+
properties: {
|
|
293
|
+
to: {
|
|
294
|
+
type: 'array',
|
|
295
|
+
items: { type: 'string' },
|
|
296
|
+
description: 'Recipients',
|
|
297
|
+
},
|
|
298
|
+
subject: { type: 'string', description: 'Email subject' },
|
|
299
|
+
body: { type: 'string', description: 'Email body' },
|
|
300
|
+
},
|
|
301
|
+
},
|
|
302
|
+
defer_loading: true,
|
|
303
|
+
},
|
|
304
|
+
{
|
|
305
|
+
name: 'search_files',
|
|
306
|
+
description: 'Search for files in the file system by name or content.',
|
|
307
|
+
parameters: {
|
|
308
|
+
type: 'object',
|
|
309
|
+
properties: {
|
|
310
|
+
query: { type: 'string', description: 'Search query' },
|
|
311
|
+
path: { type: 'string', description: 'Directory to search in' },
|
|
312
|
+
},
|
|
313
|
+
},
|
|
314
|
+
defer_loading: true,
|
|
315
|
+
},
|
|
316
|
+
{
|
|
317
|
+
name: 'run_database_query',
|
|
318
|
+
description:
|
|
319
|
+
'Execute a SQL query against the database and return results.',
|
|
320
|
+
parameters: {
|
|
321
|
+
type: 'object',
|
|
322
|
+
properties: {
|
|
323
|
+
query: { type: 'string', description: 'SQL query to execute' },
|
|
324
|
+
database: { type: 'string', description: 'Target database' },
|
|
325
|
+
},
|
|
326
|
+
},
|
|
327
|
+
defer_loading: true,
|
|
328
|
+
},
|
|
329
|
+
{
|
|
330
|
+
name: 'generate_report',
|
|
331
|
+
description:
|
|
332
|
+
'Generate a PDF or Excel report from data with customizable templates.',
|
|
333
|
+
parameters: {
|
|
334
|
+
type: 'object',
|
|
335
|
+
properties: {
|
|
336
|
+
template: { type: 'string', description: 'Report template name' },
|
|
337
|
+
format: { type: 'string', description: 'Output format: pdf or xlsx' },
|
|
338
|
+
data: { type: 'object', description: 'Data to include in report' },
|
|
339
|
+
},
|
|
340
|
+
},
|
|
341
|
+
defer_loading: true,
|
|
342
|
+
},
|
|
343
|
+
{
|
|
344
|
+
name: 'translate_text',
|
|
345
|
+
description:
|
|
346
|
+
'Translate text between languages using machine translation.',
|
|
347
|
+
parameters: {
|
|
348
|
+
type: 'object',
|
|
349
|
+
properties: {
|
|
350
|
+
text: { type: 'string', description: 'Text to translate' },
|
|
351
|
+
source_lang: { type: 'string', description: 'Source language code' },
|
|
352
|
+
target_lang: { type: 'string', description: 'Target language code' },
|
|
353
|
+
},
|
|
354
|
+
},
|
|
355
|
+
defer_loading: true,
|
|
356
|
+
},
|
|
357
|
+
{
|
|
358
|
+
name: 'calculator',
|
|
359
|
+
description:
|
|
360
|
+
'Perform mathematical calculations. Supports basic arithmetic and scientific functions.',
|
|
361
|
+
defer_loading: false, // Not deferred - should be excluded by default
|
|
362
|
+
},
|
|
363
|
+
];
|
|
364
|
+
|
|
365
|
+
return new Map(tools.map((t) => [t.name, t]));
|
|
366
|
+
}
|