@librechat/agents 3.1.25 → 3.1.27

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. package/dist/cjs/main.cjs +17 -0
  2. package/dist/cjs/main.cjs.map +1 -1
  3. package/dist/cjs/messages/format.cjs +134 -67
  4. package/dist/cjs/messages/format.cjs.map +1 -1
  5. package/dist/cjs/tools/Calculator.cjs +12 -3
  6. package/dist/cjs/tools/Calculator.cjs.map +1 -1
  7. package/dist/cjs/tools/CodeExecutor.cjs +19 -10
  8. package/dist/cjs/tools/CodeExecutor.cjs.map +1 -1
  9. package/dist/cjs/tools/ProgrammaticToolCalling.cjs +29 -0
  10. package/dist/cjs/tools/ProgrammaticToolCalling.cjs.map +1 -1
  11. package/dist/cjs/tools/ToolSearch.cjs +40 -0
  12. package/dist/cjs/tools/ToolSearch.cjs.map +1 -1
  13. package/dist/cjs/tools/search/schema.cjs +31 -0
  14. package/dist/cjs/tools/search/schema.cjs.map +1 -1
  15. package/dist/cjs/tools/search/tool.cjs +4 -26
  16. package/dist/cjs/tools/search/tool.cjs.map +1 -1
  17. package/dist/esm/main.mjs +5 -5
  18. package/dist/esm/messages/format.mjs +129 -62
  19. package/dist/esm/messages/format.mjs.map +1 -1
  20. package/dist/esm/tools/Calculator.mjs +10 -4
  21. package/dist/esm/tools/Calculator.mjs.map +1 -1
  22. package/dist/esm/tools/CodeExecutor.mjs +17 -11
  23. package/dist/esm/tools/CodeExecutor.mjs.map +1 -1
  24. package/dist/esm/tools/ProgrammaticToolCalling.mjs +26 -1
  25. package/dist/esm/tools/ProgrammaticToolCalling.mjs.map +1 -1
  26. package/dist/esm/tools/ToolSearch.mjs +38 -2
  27. package/dist/esm/tools/ToolSearch.mjs.map +1 -1
  28. package/dist/esm/tools/search/schema.mjs +29 -1
  29. package/dist/esm/tools/search/schema.mjs.map +1 -1
  30. package/dist/esm/tools/search/tool.mjs +3 -25
  31. package/dist/esm/tools/search/tool.mjs.map +1 -1
  32. package/dist/types/tools/Calculator.d.ts +16 -1
  33. package/dist/types/tools/CodeExecutor.d.ts +29 -0
  34. package/dist/types/tools/ProgrammaticToolCalling.d.ts +43 -0
  35. package/dist/types/tools/ToolSearch.d.ts +85 -0
  36. package/dist/types/tools/search/schema.d.ts +37 -0
  37. package/package.json +1 -1
  38. package/src/messages/format.ts +163 -70
  39. package/src/messages/formatAgentMessages.test.ts +369 -0
  40. package/src/messages/formatAgentMessages.tools.test.ts +68 -49
  41. package/src/tools/Calculator.ts +13 -4
  42. package/src/tools/CodeExecutor.ts +19 -11
  43. package/src/tools/ProgrammaticToolCalling.ts +29 -1
  44. package/src/tools/ToolSearch.ts +43 -0
  45. package/src/tools/search/schema.ts +31 -0
  46. package/src/tools/search/tool.ts +7 -27
@@ -32,7 +32,7 @@ const DEFAULT_TIMEOUT = 60000;
32
32
  // Schema
33
33
  // ============================================================================
34
34
 
35
- const ProgrammaticToolCallingSchema = {
35
+ export const ProgrammaticToolCallingSchema = {
36
36
  type: 'object',
37
37
  properties: {
38
38
  code: {
@@ -80,6 +80,34 @@ Rules:
80
80
  required: ['code'],
81
81
  } as const;
82
82
 
83
+ export const ProgrammaticToolCallingName = Constants.PROGRAMMATIC_TOOL_CALLING;
84
+
85
+ export const ProgrammaticToolCallingDescription = `
86
+ Run tools via Python code. Auto-wrapped in async context—just use \`await\` directly.
87
+
88
+ CRITICAL - STATELESS: Each call is a fresh interpreter. Variables/imports do NOT persist.
89
+ Complete your ENTIRE workflow in ONE call: fetch → process → save. No splitting across calls.
90
+
91
+ Rules:
92
+ - Everything in ONE code block—no state carries over between executions
93
+ - Do NOT define \`async def main()\` or call \`asyncio.run()\`—just write code with await
94
+ - Tools are pre-defined—DO NOT write function definitions
95
+ - Only \`print()\` output returns; tool results are raw dicts/lists/strings
96
+ - Generated files are automatically available in /mnt/data/ for subsequent executions
97
+ - Tool names normalized: hyphens→underscores, keywords get \`_tool\` suffix
98
+
99
+ When to use: loops, conditionals, parallel (\`asyncio.gather\`), multi-step pipelines.
100
+
101
+ Example (complete pipeline):
102
+ data = await query_db(sql="..."); df = process(data); await save_to_sheet(data=df); print("Done")
103
+ `.trim();
104
+
105
+ export const ProgrammaticToolCallingDefinition = {
106
+ name: ProgrammaticToolCallingName,
107
+ description: ProgrammaticToolCallingDescription,
108
+ schema: ProgrammaticToolCallingSchema,
109
+ } as const;
110
+
83
111
  // ============================================================================
84
112
  // Helper Functions
85
113
  // ============================================================================
@@ -33,6 +33,49 @@ config();
33
33
  /** Maximum allowed regex pattern length */
34
34
  const MAX_PATTERN_LENGTH = 200;
35
35
 
36
+ export const ToolSearchToolName = Constants.TOOL_SEARCH;
37
+
38
+ export const ToolSearchToolDescription =
39
+ 'Searches deferred tools using BM25 ranking. Multi-word queries supported. Use mcp_server param to filter by server.';
40
+
41
+ export const ToolSearchToolSchema = {
42
+ type: 'object',
43
+ properties: {
44
+ query: {
45
+ type: 'string',
46
+ maxLength: MAX_PATTERN_LENGTH,
47
+ default: '',
48
+ description:
49
+ 'Search term to find in tool names and descriptions. Case-insensitive substring matching. Optional if mcp_server is provided.',
50
+ },
51
+ fields: {
52
+ type: 'array',
53
+ items: { type: 'string', enum: ['name', 'description', 'parameters'] },
54
+ default: ['name', 'description'],
55
+ description: 'Which fields to search. Default: name and description',
56
+ },
57
+ max_results: {
58
+ type: 'integer',
59
+ minimum: 1,
60
+ maximum: 50,
61
+ default: 10,
62
+ description: 'Maximum number of matching tools to return',
63
+ },
64
+ mcp_server: {
65
+ oneOf: [{ type: 'string' }, { type: 'array', items: { type: 'string' } }],
66
+ description:
67
+ 'Filter to tools from specific MCP server(s). Can be a single server name or array of names. If provided without a query, lists all tools from those servers.',
68
+ },
69
+ },
70
+ required: [],
71
+ } as const;
72
+
73
+ export const ToolSearchToolDefinition = {
74
+ name: ToolSearchToolName,
75
+ description: ToolSearchToolDescription,
76
+ schema: ToolSearchToolSchema,
77
+ } as const;
78
+
36
79
  /** Maximum allowed regex nesting depth */
37
80
  const MAX_REGEX_COMPLEXITY = 5;
38
81
 
@@ -80,3 +80,34 @@ export const WebSearchToolSchema = {
80
80
  },
81
81
  required: ['query'],
82
82
  } as const;
83
+
84
+ export const WebSearchToolName = 'web_search';
85
+
86
+ export const WebSearchToolDescription = `Real-time search. Results have required citation anchors.
87
+
88
+ Note: Use ONCE per reply unless instructed otherwise.
89
+
90
+ Anchors:
91
+ - \\ue202turnXtypeY
92
+ - X = turn idx, type = 'search' | 'news' | 'image' | 'ref', Y = item idx
93
+
94
+ Special Markers:
95
+ - \\ue203...\\ue204 — highlight start/end of cited text (for Standalone or Group citations)
96
+ - \\ue200...\\ue201 — group block (e.g. \\ue200\\ue202turn0search1\\ue202turn0news2\\ue201)
97
+
98
+ **CITE EVERY NON-OBVIOUS FACT/QUOTE:**
99
+ Use anchor marker(s) immediately after the statement:
100
+ - Standalone: "Pure functions produce same output. \\ue202turn0search0"
101
+ - Standalone (multiple): "Today's News \\ue202turn0search0\\ue202turn0news0"
102
+ - Highlight: "\\ue203Highlight text.\\ue204\\ue202turn0news1"
103
+ - Group: "Sources. \\ue200\\ue202turn0search0\\ue202turn0news1\\ue201"
104
+ - Group Highlight: "\\ue203Highlight for group.\\ue204 \\ue200\\ue202turn0search0\\ue202turn0news1\\ue201"
105
+ - Image: "See photo \\ue202turn0image0."
106
+
107
+ **NEVER use markdown links, [1], or footnotes. CITE ONLY with anchors provided.**`;
108
+
109
+ export const WebSearchToolDefinition = {
110
+ name: WebSearchToolName,
111
+ description: WebSearchToolDescription,
112
+ schema: WebSearchToolSchema,
113
+ } as const;
@@ -2,13 +2,15 @@ import { tool, DynamicStructuredTool } from '@langchain/core/tools';
2
2
  import type { RunnableConfig } from '@langchain/core/runnables';
3
3
  import type * as t from './types';
4
4
  import {
5
- DATE_RANGE,
6
- querySchema,
7
- dateSchema,
5
+ WebSearchToolDescription,
6
+ WebSearchToolName,
8
7
  countrySchema,
9
8
  imagesSchema,
10
9
  videosSchema,
10
+ querySchema,
11
+ dateSchema,
11
12
  newsSchema,
13
+ DATE_RANGE,
12
14
  } from './schema';
13
15
  import { createSearchAPI, createSourceProcessor } from './search';
14
16
  import { createSerperScraper } from './serper-scraper';
@@ -295,30 +297,8 @@ function createTool({
295
297
  return [output, { [Constants.WEB_SEARCH]: data }];
296
298
  },
297
299
  {
298
- name: Constants.WEB_SEARCH,
299
- description: `Real-time search. Results have required citation anchors.
300
-
301
- Note: Use ONCE per reply unless instructed otherwise.
302
-
303
- Anchors:
304
- - \\ue202turnXtypeY
305
- - X = turn idx, type = 'search' | 'news' | 'image' | 'ref', Y = item idx
306
-
307
- Special Markers:
308
- - \\ue203...\\ue204 — highlight start/end of cited text (for Standalone or Group citations)
309
- - \\ue200...\\ue201 — group block (e.g. \\ue200\\ue202turn0search1\\ue202turn0news2\\ue201)
310
-
311
- **CITE EVERY NON-OBVIOUS FACT/QUOTE:**
312
- Use anchor marker(s) immediately after the statement:
313
- - Standalone: "Pure functions produce same output. \\ue202turn0search0"
314
- - Standalone (multiple): "Today's News \\ue202turn0search0\\ue202turn0news0"
315
- - Highlight: "\\ue203Highlight text.\\ue204\\ue202turn0news1"
316
- - Group: "Sources. \\ue200\\ue202turn0search0\\ue202turn0news1\\ue201"
317
- - Group Highlight: "\\ue203Highlight for group.\\ue204 \\ue200\\ue202turn0search0\\ue202turn0news1\\ue201"
318
- - Image: "See photo \\ue202turn0image0."
319
-
320
- **NEVER use markdown links, [1], or footnotes. CITE ONLY with anchors provided.**
321
- `.trim(),
300
+ name: WebSearchToolName,
301
+ description: WebSearchToolDescription,
322
302
  schema: schema,
323
303
  responseFormat: Constants.CONTENT_AND_ARTIFACT,
324
304
  }