@librechat/agents 3.1.70 → 3.1.71-dev.0
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 +45 -0
- package/dist/cjs/graphs/Graph.cjs.map +1 -1
- package/dist/cjs/main.cjs +4 -0
- package/dist/cjs/main.cjs.map +1 -1
- package/dist/cjs/messages/prune.cjs +9 -2
- package/dist/cjs/messages/prune.cjs.map +1 -1
- package/dist/cjs/run.cjs +4 -0
- package/dist/cjs/run.cjs.map +1 -1
- package/dist/cjs/tools/BashExecutor.cjs +43 -0
- package/dist/cjs/tools/BashExecutor.cjs.map +1 -1
- package/dist/cjs/tools/ToolNode.cjs +453 -45
- package/dist/cjs/tools/ToolNode.cjs.map +1 -1
- package/dist/cjs/tools/toolOutputReferences.cjs +475 -0
- package/dist/cjs/tools/toolOutputReferences.cjs.map +1 -0
- package/dist/cjs/utils/truncation.cjs +28 -0
- package/dist/cjs/utils/truncation.cjs.map +1 -1
- package/dist/esm/graphs/Graph.mjs +45 -0
- package/dist/esm/graphs/Graph.mjs.map +1 -1
- package/dist/esm/main.mjs +2 -2
- package/dist/esm/messages/prune.mjs +9 -2
- package/dist/esm/messages/prune.mjs.map +1 -1
- package/dist/esm/run.mjs +4 -0
- package/dist/esm/run.mjs.map +1 -1
- package/dist/esm/tools/BashExecutor.mjs +42 -1
- package/dist/esm/tools/BashExecutor.mjs.map +1 -1
- package/dist/esm/tools/ToolNode.mjs +453 -45
- package/dist/esm/tools/ToolNode.mjs.map +1 -1
- package/dist/esm/tools/toolOutputReferences.mjs +468 -0
- package/dist/esm/tools/toolOutputReferences.mjs.map +1 -0
- package/dist/esm/utils/truncation.mjs +27 -1
- package/dist/esm/utils/truncation.mjs.map +1 -1
- package/dist/types/graphs/Graph.d.ts +21 -0
- package/dist/types/run.d.ts +1 -0
- package/dist/types/tools/BashExecutor.d.ts +31 -0
- package/dist/types/tools/ToolNode.d.ts +86 -3
- package/dist/types/tools/toolOutputReferences.d.ts +205 -0
- package/dist/types/types/run.d.ts +9 -1
- package/dist/types/types/tools.d.ts +70 -0
- package/dist/types/utils/truncation.d.ts +21 -0
- package/package.json +1 -1
- package/src/graphs/Graph.ts +48 -0
- package/src/messages/prune.ts +9 -2
- package/src/run.ts +4 -0
- package/src/specs/prune.test.ts +413 -0
- package/src/tools/BashExecutor.ts +45 -0
- package/src/tools/ToolNode.ts +618 -55
- package/src/tools/__tests__/BashExecutor.test.ts +36 -0
- package/src/tools/__tests__/ToolNode.outputReferences.test.ts +1395 -0
- package/src/tools/__tests__/toolOutputReferences.test.ts +415 -0
- package/src/tools/toolOutputReferences.ts +590 -0
- package/src/types/run.ts +9 -1
- package/src/types/tools.ts +71 -0
- package/src/utils/__tests__/truncation.test.ts +66 -0
- package/src/utils/truncation.ts +30 -0
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { describe, it, expect } from '@jest/globals';
|
|
2
|
+
import {
|
|
3
|
+
HARD_MAX_TOOL_RESULT_CHARS,
|
|
4
|
+
HARD_MAX_TOTAL_TOOL_OUTPUT_SIZE,
|
|
5
|
+
calculateMaxToolResultChars,
|
|
6
|
+
calculateMaxTotalToolOutputSize,
|
|
7
|
+
} from '@/utils/truncation';
|
|
8
|
+
|
|
9
|
+
describe('truncation helpers', () => {
|
|
10
|
+
describe('calculateMaxToolResultChars', () => {
|
|
11
|
+
it('returns the hard cap when context tokens are missing', () => {
|
|
12
|
+
expect(calculateMaxToolResultChars()).toBe(HARD_MAX_TOOL_RESULT_CHARS);
|
|
13
|
+
expect(calculateMaxToolResultChars(undefined)).toBe(
|
|
14
|
+
HARD_MAX_TOOL_RESULT_CHARS
|
|
15
|
+
);
|
|
16
|
+
expect(calculateMaxToolResultChars(0)).toBe(HARD_MAX_TOOL_RESULT_CHARS);
|
|
17
|
+
expect(calculateMaxToolResultChars(-100)).toBe(
|
|
18
|
+
HARD_MAX_TOOL_RESULT_CHARS
|
|
19
|
+
);
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it('computes 30% of context-window characters for normal inputs', () => {
|
|
23
|
+
// 100k tokens * 0.3 = 30k tokens * 4 chars/token = 120k chars
|
|
24
|
+
expect(calculateMaxToolResultChars(100_000)).toBe(120_000);
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it('clamps to the hard cap for large context windows', () => {
|
|
28
|
+
// 1M tokens * 0.3 * 4 = 1.2M chars, exceeds 400k cap
|
|
29
|
+
expect(calculateMaxToolResultChars(1_000_000)).toBe(
|
|
30
|
+
HARD_MAX_TOOL_RESULT_CHARS
|
|
31
|
+
);
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
describe('calculateMaxTotalToolOutputSize', () => {
|
|
36
|
+
it('returns the absolute hard cap when no per-output is provided', () => {
|
|
37
|
+
expect(calculateMaxTotalToolOutputSize()).toBe(
|
|
38
|
+
HARD_MAX_TOTAL_TOOL_OUTPUT_SIZE
|
|
39
|
+
);
|
|
40
|
+
expect(calculateMaxTotalToolOutputSize(0)).toBe(
|
|
41
|
+
HARD_MAX_TOTAL_TOOL_OUTPUT_SIZE
|
|
42
|
+
);
|
|
43
|
+
expect(calculateMaxTotalToolOutputSize(-1)).toBe(
|
|
44
|
+
HARD_MAX_TOTAL_TOOL_OUTPUT_SIZE
|
|
45
|
+
);
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it('doubles the per-output cap by default', () => {
|
|
49
|
+
expect(calculateMaxTotalToolOutputSize(100_000)).toBe(200_000);
|
|
50
|
+
expect(calculateMaxTotalToolOutputSize(1)).toBe(2);
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
it('clamps the doubled value to HARD_MAX_TOTAL_TOOL_OUTPUT_SIZE', () => {
|
|
54
|
+
// 4M * 2 = 8M, exceeds 5M
|
|
55
|
+
expect(calculateMaxTotalToolOutputSize(4_000_000)).toBe(
|
|
56
|
+
HARD_MAX_TOTAL_TOOL_OUTPUT_SIZE
|
|
57
|
+
);
|
|
58
|
+
// Right at the boundary: 2.5M * 2 = 5M (no clamp).
|
|
59
|
+
expect(calculateMaxTotalToolOutputSize(2_500_000)).toBe(5_000_000);
|
|
60
|
+
// Just past it: 2_500_001 * 2 = 5_000_002 -> clamped.
|
|
61
|
+
expect(calculateMaxTotalToolOutputSize(2_500_001)).toBe(
|
|
62
|
+
HARD_MAX_TOTAL_TOOL_OUTPUT_SIZE
|
|
63
|
+
);
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
});
|
package/src/utils/truncation.ts
CHANGED
|
@@ -12,6 +12,16 @@
|
|
|
12
12
|
*/
|
|
13
13
|
export const HARD_MAX_TOOL_RESULT_CHARS = 400_000;
|
|
14
14
|
|
|
15
|
+
/**
|
|
16
|
+
* Absolute hard cap on the aggregate size (characters) of all registered
|
|
17
|
+
* tool outputs kept for `{{tool<i>turn<n>}}` substitution. Set at 5 MB
|
|
18
|
+
* because the registry stores *raw, untruncated* tool output — full
|
|
19
|
+
* fidelity for piping into downstream bash/jq — so the budget needs
|
|
20
|
+
* enough headroom to keep a handful of large responses without
|
|
21
|
+
* ballooning unbounded.
|
|
22
|
+
*/
|
|
23
|
+
export const HARD_MAX_TOTAL_TOOL_OUTPUT_SIZE = 5_000_000;
|
|
24
|
+
|
|
15
25
|
/**
|
|
16
26
|
* Computes the dynamic max tool result size based on the model's context window.
|
|
17
27
|
* Uses 30% of the context window (in estimated characters, ~4 chars/token)
|
|
@@ -32,6 +42,26 @@ export function calculateMaxToolResultChars(
|
|
|
32
42
|
);
|
|
33
43
|
}
|
|
34
44
|
|
|
45
|
+
/**
|
|
46
|
+
* Computes the default aggregate size (characters) for the tool output
|
|
47
|
+
* reference registry based on the per-output budget. Mirrors
|
|
48
|
+
* `calculateMaxToolResultChars`'s shape: a multiple of the per-output
|
|
49
|
+
* cap, clamped to `HARD_MAX_TOTAL_TOOL_OUTPUT_SIZE`.
|
|
50
|
+
*
|
|
51
|
+
* @param maxOutputSize - Per-output maximum characters (e.g., the
|
|
52
|
+
* ToolNode's `maxToolResultChars`). When omitted or non-positive,
|
|
53
|
+
* falls back to the absolute total cap.
|
|
54
|
+
* @returns Maximum total characters retained across the registry.
|
|
55
|
+
*/
|
|
56
|
+
export function calculateMaxTotalToolOutputSize(
|
|
57
|
+
maxOutputSize?: number
|
|
58
|
+
): number {
|
|
59
|
+
if (maxOutputSize == null || maxOutputSize <= 0) {
|
|
60
|
+
return HARD_MAX_TOTAL_TOOL_OUTPUT_SIZE;
|
|
61
|
+
}
|
|
62
|
+
return Math.min(maxOutputSize * 2, HARD_MAX_TOTAL_TOOL_OUTPUT_SIZE);
|
|
63
|
+
}
|
|
64
|
+
|
|
35
65
|
/**
|
|
36
66
|
* Truncates a tool-call input (the arguments/payload of a tool_use block)
|
|
37
67
|
* using head+tail strategy. Returns an object with `_truncated` (the
|