@librechat/agents 3.3.7 → 3.3.9
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 +47 -13
- package/dist/cjs/graphs/Graph.cjs.map +1 -1
- package/dist/cjs/graphs/MultiAgentGraph.cjs +56 -6
- package/dist/cjs/graphs/MultiAgentGraph.cjs.map +1 -1
- package/dist/cjs/hitl/askUserQuestion.cjs +3 -2
- package/dist/cjs/hitl/askUserQuestion.cjs.map +1 -1
- package/dist/cjs/instrumentation.cjs +18 -48
- package/dist/cjs/instrumentation.cjs.map +1 -1
- package/dist/cjs/langfuse.cjs +174 -29
- package/dist/cjs/langfuse.cjs.map +1 -1
- package/dist/cjs/langfuseConfig.cjs +12 -0
- package/dist/cjs/langfuseConfig.cjs.map +1 -1
- package/dist/cjs/langfuseRuntimeContext.cjs +23 -2
- package/dist/cjs/langfuseRuntimeContext.cjs.map +1 -1
- package/dist/cjs/langfuseRuntimeScope.cjs +39 -8
- package/dist/cjs/langfuseRuntimeScope.cjs.map +1 -1
- package/dist/cjs/langfuseSpanRegistry.cjs +95 -0
- package/dist/cjs/langfuseSpanRegistry.cjs.map +1 -0
- package/dist/cjs/langfuseTraceShaping.cjs +121 -4
- package/dist/cjs/langfuseTraceShaping.cjs.map +1 -1
- package/dist/cjs/llm/anthropic/utils/message_inputs.cjs +39 -15
- package/dist/cjs/llm/anthropic/utils/message_inputs.cjs.map +1 -1
- package/dist/cjs/llm/bedrock/utils/message_inputs.cjs +25 -5
- package/dist/cjs/llm/bedrock/utils/message_inputs.cjs.map +1 -1
- package/dist/cjs/llm/init.cjs +3 -3
- package/dist/cjs/llm/invoke.cjs +5 -5
- package/dist/cjs/llm/openai/index.cjs +1 -1
- package/dist/cjs/main.cjs +10 -10
- package/dist/cjs/messages/format.cjs +124 -15
- package/dist/cjs/messages/format.cjs.map +1 -1
- package/dist/cjs/messages/injected.cjs +10 -1
- package/dist/cjs/messages/injected.cjs.map +1 -1
- package/dist/cjs/messages/prune.cjs +13 -1
- package/dist/cjs/messages/prune.cjs.map +1 -1
- package/dist/cjs/prompts/activityLabel.cjs +51 -11
- package/dist/cjs/prompts/activityLabel.cjs.map +1 -1
- package/dist/cjs/run.cjs +54 -24
- package/dist/cjs/run.cjs.map +1 -1
- package/dist/cjs/session/messageSerialization.cjs +6 -0
- package/dist/cjs/session/messageSerialization.cjs.map +1 -1
- package/dist/cjs/stream.cjs +21 -10
- package/dist/cjs/stream.cjs.map +1 -1
- package/dist/cjs/summarization/node.cjs +60 -0
- package/dist/cjs/summarization/node.cjs.map +1 -1
- package/dist/cjs/tools/ToolNode.cjs +253 -24
- package/dist/cjs/tools/ToolNode.cjs.map +1 -1
- package/dist/cjs/tools/handlers.cjs +1 -1
- package/dist/cjs/tools/search/tool.cjs +1 -1
- package/dist/cjs/tools/subagent/SubagentExecutor.cjs +1 -1
- package/dist/cjs/utils/index.cjs +2 -2
- package/dist/esm/graphs/Graph.mjs +48 -14
- package/dist/esm/graphs/Graph.mjs.map +1 -1
- package/dist/esm/graphs/MultiAgentGraph.mjs +56 -6
- package/dist/esm/graphs/MultiAgentGraph.mjs.map +1 -1
- package/dist/esm/hitl/askUserQuestion.mjs +3 -2
- package/dist/esm/hitl/askUserQuestion.mjs.map +1 -1
- package/dist/esm/instrumentation.mjs +18 -48
- package/dist/esm/instrumentation.mjs.map +1 -1
- package/dist/esm/langfuse.mjs +176 -28
- package/dist/esm/langfuse.mjs.map +1 -1
- package/dist/esm/langfuseConfig.mjs +10 -1
- package/dist/esm/langfuseConfig.mjs.map +1 -1
- package/dist/esm/langfuseRuntimeContext.mjs +21 -3
- package/dist/esm/langfuseRuntimeContext.mjs.map +1 -1
- package/dist/esm/langfuseRuntimeScope.mjs +39 -10
- package/dist/esm/langfuseRuntimeScope.mjs.map +1 -1
- package/dist/esm/langfuseSpanRegistry.mjs +91 -0
- package/dist/esm/langfuseSpanRegistry.mjs.map +1 -0
- package/dist/esm/langfuseTraceShaping.mjs +121 -4
- package/dist/esm/langfuseTraceShaping.mjs.map +1 -1
- package/dist/esm/llm/anthropic/utils/message_inputs.mjs +39 -15
- package/dist/esm/llm/anthropic/utils/message_inputs.mjs.map +1 -1
- package/dist/esm/llm/bedrock/utils/message_inputs.mjs +25 -5
- package/dist/esm/llm/bedrock/utils/message_inputs.mjs.map +1 -1
- package/dist/esm/llm/init.mjs +2 -2
- package/dist/esm/llm/invoke.mjs +5 -5
- package/dist/esm/llm/openai/index.mjs +1 -1
- package/dist/esm/main.mjs +8 -8
- package/dist/esm/messages/format.mjs +124 -15
- package/dist/esm/messages/format.mjs.map +1 -1
- package/dist/esm/messages/injected.mjs +10 -1
- package/dist/esm/messages/injected.mjs.map +1 -1
- package/dist/esm/messages/prune.mjs +13 -1
- package/dist/esm/messages/prune.mjs.map +1 -1
- package/dist/esm/prompts/activityLabel.mjs +51 -11
- package/dist/esm/prompts/activityLabel.mjs.map +1 -1
- package/dist/esm/run.mjs +54 -24
- package/dist/esm/run.mjs.map +1 -1
- package/dist/esm/session/messageSerialization.mjs +6 -0
- package/dist/esm/session/messageSerialization.mjs.map +1 -1
- package/dist/esm/stream.mjs +21 -10
- package/dist/esm/stream.mjs.map +1 -1
- package/dist/esm/summarization/node.mjs +60 -0
- package/dist/esm/summarization/node.mjs.map +1 -1
- package/dist/esm/tools/ToolNode.mjs +254 -25
- package/dist/esm/tools/ToolNode.mjs.map +1 -1
- package/dist/esm/tools/handlers.mjs +1 -1
- package/dist/esm/tools/search/tool.mjs +1 -1
- package/dist/esm/tools/subagent/SubagentExecutor.mjs +1 -1
- package/dist/esm/utils/index.mjs +2 -2
- package/dist/types/graphs/Graph.d.ts +19 -0
- package/dist/types/hitl/askUserQuestion.d.ts +11 -1
- package/dist/types/langfuse.d.ts +16 -8
- package/dist/types/langfuseConfig.d.ts +6 -0
- package/dist/types/langfuseRuntimeContext.d.ts +27 -1
- package/dist/types/langfuseRuntimeScope.d.ts +17 -2
- package/dist/types/langfuseSpanRegistry.d.ts +17 -0
- package/dist/types/langfuseTraceShaping.d.ts +2 -1
- package/dist/types/llm/anthropic/utils/message_inputs.d.ts +1 -0
- package/dist/types/messages/format.d.ts +9 -8
- package/dist/types/prompts/activityLabel.d.ts +8 -1
- package/dist/types/run.d.ts +1 -1
- package/dist/types/session/types.d.ts +1 -0
- package/dist/types/tools/ToolNode.d.ts +7 -1
- package/dist/types/types/activityLabel.d.ts +8 -0
- package/dist/types/types/hitl.d.ts +8 -0
- package/dist/types/types/stream.d.ts +19 -0
- package/dist/types/types/tools.d.ts +30 -0
- package/package.json +7 -4
- package/src/__tests__/stream.eagerArgsDivergence.test.ts +753 -0
- package/src/graphs/Graph.ts +69 -20
- package/src/graphs/MultiAgentGraph.ts +74 -6
- package/src/graphs/__tests__/composition.smoke.test.ts +4 -0
- package/src/hitl/askUserQuestion.ts +14 -1
- package/src/instrumentation.ts +35 -77
- package/src/langfuse.ts +320 -43
- package/src/langfuseConfig.ts +24 -0
- package/src/langfuseRuntimeContext.ts +43 -1
- package/src/langfuseRuntimeScope.ts +94 -21
- package/src/langfuseSpanRegistry.ts +131 -0
- package/src/langfuseTraceShaping.ts +194 -7
- package/src/llm/anthropic/utils/message_inputs.ts +70 -19
- package/src/llm/anthropic/utils/streaming-tool-input.test.ts +186 -11
- package/src/llm/bedrock/utils/message_inputs.test.ts +120 -4
- package/src/llm/bedrock/utils/message_inputs.ts +32 -7
- package/src/messages/format.ts +222 -50
- package/src/messages/formatAgentMessages.test.ts +308 -6
- package/src/messages/injected.test.ts +18 -1
- package/src/messages/injected.ts +8 -1
- package/src/messages/prune.ts +12 -1
- package/src/prompts/activityLabel.ts +67 -2
- package/src/run.ts +86 -46
- package/src/scripts/activity-labels/captured.json +56 -0
- package/src/scripts/activity-labels/checks.cjs +205 -0
- package/src/scripts/activity-labels/corpus.cjs +473 -0
- package/src/scripts/activity-labels/report.cjs +203 -0
- package/src/scripts/activity-labels/rescore.cjs +102 -0
- package/src/scripts/activity-labels/run.ts +705 -0
- package/src/scripts/activity-labels/variants.ts +71 -0
- package/src/session/messageSerialization.ts +12 -1
- package/src/session/types.ts +1 -0
- package/src/specs/activity-label-prompt.test.ts +109 -0
- package/src/specs/agent-handoffs.test.ts +306 -0
- package/src/specs/langfuse-callbacks.test.ts +456 -0
- package/src/specs/langfuse-routing.integration.test.ts +138 -1
- package/src/specs/langfuse-span-registry.test.ts +70 -0
- package/src/specs/langfuse-trace-shaping.test.ts +294 -0
- package/src/specs/prune.test.ts +38 -1
- package/src/stream.ts +70 -6
- package/src/summarization/__tests__/node.test.ts +188 -0
- package/src/summarization/node.ts +72 -0
- package/src/tools/ToolNode.ts +400 -9
- package/src/tools/__tests__/ToolNode.invalidToolCalls.test.ts +757 -0
- package/src/tools/__tests__/hitl.test.ts +58 -0
- package/src/types/activityLabel.ts +8 -0
- package/src/types/hitl.ts +8 -0
- package/src/types/stream.ts +20 -0
- package/src/types/tools.ts +35 -1
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Offline rescore: recompute checks over a stored results JSON after a
|
|
3
|
+
* metric change, without re-calling the API. Chains are rebuilt from the
|
|
4
|
+
* stored labels in push order (steps within a case ran serially).
|
|
5
|
+
*
|
|
6
|
+
* Usage: node src/scripts/activity-labels/rescore.cjs [results/<file>.json]
|
|
7
|
+
*/
|
|
8
|
+
const fs = require('fs');
|
|
9
|
+
const path = require('path');
|
|
10
|
+
const crypto = require('crypto');
|
|
11
|
+
|
|
12
|
+
const { cases, stepEntries } = require('./corpus.cjs');
|
|
13
|
+
const { checkLabel } = require('./checks.cjs');
|
|
14
|
+
const { aggregate, markdownReport } = require('./report.cjs');
|
|
15
|
+
|
|
16
|
+
const RESULTS_DIR = path.join(__dirname, 'results');
|
|
17
|
+
|
|
18
|
+
function newestResults() {
|
|
19
|
+
const files = fs
|
|
20
|
+
.readdirSync(RESULTS_DIR)
|
|
21
|
+
.filter((file) => file.endsWith('.json'))
|
|
22
|
+
.sort();
|
|
23
|
+
if (files.length === 0) {
|
|
24
|
+
throw new Error('no stored results to rescore');
|
|
25
|
+
}
|
|
26
|
+
return path.join(RESULTS_DIR, files[files.length - 1]);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const sourcePath = process.argv[2]
|
|
30
|
+
? path.resolve(process.argv[2])
|
|
31
|
+
: newestResults();
|
|
32
|
+
const { args, corpusFingerprint, records } = JSON.parse(
|
|
33
|
+
fs.readFileSync(sourcePath, 'utf8')
|
|
34
|
+
);
|
|
35
|
+
|
|
36
|
+
/** Rescoring replays stored labels against the CURRENT corpus. If the
|
|
37
|
+
* corpus drifted since the run (renamed steps, changed tool names), the
|
|
38
|
+
* recomputed flags would grade against the wrong entries — refuse rather
|
|
39
|
+
* than silently produce a plausible-looking report. */
|
|
40
|
+
const currentFingerprint = crypto
|
|
41
|
+
.createHash('sha256')
|
|
42
|
+
.update(JSON.stringify(cases))
|
|
43
|
+
.digest('hex');
|
|
44
|
+
if (corpusFingerprint == null) {
|
|
45
|
+
console.warn(
|
|
46
|
+
'WARN: stored results predate corpus fingerprinting — rescoring against the current corpus, which may have drifted'
|
|
47
|
+
);
|
|
48
|
+
} else if (corpusFingerprint !== currentFingerprint) {
|
|
49
|
+
throw new Error(
|
|
50
|
+
'stored results came from a different corpus revision — re-run the sweep instead of rescoring'
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const stepsByCase = new Map(
|
|
55
|
+
cases.map((testCase) => [
|
|
56
|
+
testCase.id,
|
|
57
|
+
new Map(testCase.steps.map((step) => [step.id ?? testCase.id, step])),
|
|
58
|
+
])
|
|
59
|
+
);
|
|
60
|
+
|
|
61
|
+
const chains = new Map();
|
|
62
|
+
for (const record of records) {
|
|
63
|
+
if (record.error || record.label == null) {
|
|
64
|
+
continue;
|
|
65
|
+
}
|
|
66
|
+
const key = `${record.variant}\0${record.sample}\0${record.caseId}`;
|
|
67
|
+
if (!chains.has(key)) {
|
|
68
|
+
chains.set(key, []);
|
|
69
|
+
}
|
|
70
|
+
const chain = chains.get(key);
|
|
71
|
+
const step = stepsByCase.get(record.caseId)?.get(record.stepId);
|
|
72
|
+
const { flags, wordCount, firstWord } = checkLabel(record.label, {
|
|
73
|
+
entries: step != null ? stepEntries(step) : [],
|
|
74
|
+
previousLabels: chain,
|
|
75
|
+
});
|
|
76
|
+
record.flags = flags;
|
|
77
|
+
record.wordCount = wordCount;
|
|
78
|
+
record.firstWord = firstWord;
|
|
79
|
+
chain.push(record.label);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const variantNames = [...new Set(records.map((record) => record.variant))];
|
|
83
|
+
const runCases = cases.filter((testCase) =>
|
|
84
|
+
records.some((r) => r.caseId === testCase.id)
|
|
85
|
+
);
|
|
86
|
+
const report = markdownReport({
|
|
87
|
+
records,
|
|
88
|
+
aggregates: aggregate(records, args.model),
|
|
89
|
+
runCases,
|
|
90
|
+
variantNames,
|
|
91
|
+
model: args.model,
|
|
92
|
+
samples: args.samples,
|
|
93
|
+
});
|
|
94
|
+
/** An archived JSON can be rescored by explicit path in a fresh checkout
|
|
95
|
+
* where the gitignored results/ directory does not exist yet. */
|
|
96
|
+
fs.mkdirSync(RESULTS_DIR, { recursive: true });
|
|
97
|
+
fs.writeFileSync(path.join(RESULTS_DIR, 'latest.md'), report);
|
|
98
|
+
console.log(`rescored ${path.basename(sourcePath)}`);
|
|
99
|
+
console.log(report.split('## Per-case')[0]);
|
|
100
|
+
console.log(
|
|
101
|
+
'full per-case tables: src/scripts/activity-labels/results/latest.md'
|
|
102
|
+
);
|