@librechat/agents 3.1.96 → 3.1.97
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 +54 -21
- package/dist/cjs/graphs/Graph.cjs.map +1 -1
- package/dist/cjs/instrumentation.cjs +120 -9
- package/dist/cjs/instrumentation.cjs.map +1 -1
- package/dist/cjs/langfuse.cjs +30 -226
- package/dist/cjs/langfuse.cjs.map +1 -1
- package/dist/cjs/langfuseToolOutputTracing.cjs +465 -0
- package/dist/cjs/langfuseToolOutputTracing.cjs.map +1 -0
- package/dist/cjs/run.cjs +142 -69
- package/dist/cjs/run.cjs.map +1 -1
- package/dist/cjs/tools/ToolNode.cjs +20 -8
- package/dist/cjs/tools/ToolNode.cjs.map +1 -1
- package/dist/cjs/tools/subagent/SubagentExecutor.cjs +10 -6
- package/dist/cjs/tools/subagent/SubagentExecutor.cjs.map +1 -1
- package/dist/esm/graphs/Graph.mjs +56 -23
- package/dist/esm/graphs/Graph.mjs.map +1 -1
- package/dist/esm/instrumentation.mjs +118 -9
- package/dist/esm/instrumentation.mjs.map +1 -1
- package/dist/esm/langfuse.mjs +28 -224
- package/dist/esm/langfuse.mjs.map +1 -1
- package/dist/esm/langfuseToolOutputTracing.mjs +457 -0
- package/dist/esm/langfuseToolOutputTracing.mjs.map +1 -0
- package/dist/esm/run.mjs +144 -71
- package/dist/esm/run.mjs.map +1 -1
- package/dist/esm/tools/ToolNode.mjs +20 -8
- package/dist/esm/tools/ToolNode.mjs.map +1 -1
- package/dist/esm/tools/subagent/SubagentExecutor.mjs +10 -6
- package/dist/esm/tools/subagent/SubagentExecutor.mjs.map +1 -1
- package/dist/types/graphs/Graph.d.ts +5 -1
- package/dist/types/instrumentation.d.ts +5 -1
- package/dist/types/langfuse.d.ts +6 -28
- package/dist/types/langfuseToolOutputTracing.d.ts +20 -0
- package/dist/types/run.d.ts +5 -1
- package/dist/types/tools/ToolNode.d.ts +4 -1
- package/dist/types/tools/subagent/SubagentExecutor.d.ts +2 -0
- package/dist/types/types/graph.d.ts +30 -0
- package/dist/types/types/run.d.ts +6 -0
- package/dist/types/types/tools.d.ts +7 -0
- package/package.json +2 -1
- package/src/graphs/Graph.ts +90 -34
- package/src/instrumentation.ts +172 -11
- package/src/langfuse.ts +59 -324
- package/src/langfuseToolOutputTracing.ts +683 -0
- package/src/run.ts +190 -87
- package/src/specs/langfuse-callbacks.test.ts +178 -1
- package/src/specs/langfuse-config.test.ts +112 -76
- package/src/specs/langfuse-instrumentation.test.ts +283 -0
- package/src/specs/langfuse-metadata.test.ts +54 -1
- package/src/specs/langfuse-tool-output-tracing.test.ts +588 -0
- package/src/tools/ToolNode.ts +28 -7
- package/src/tools/__tests__/SubagentExecutor.test.ts +32 -0
- package/src/tools/__tests__/ToolNode.langfuse.test.ts +41 -0
- package/src/tools/subagent/SubagentExecutor.ts +11 -6
- package/src/types/graph.ts +32 -0
- package/src/types/run.ts +6 -0
- package/src/types/tools.ts +7 -0
|
@@ -54,6 +54,8 @@ var CloudflareSandboxTools = require('../tools/cloudflare/CloudflareSandboxTools
|
|
|
54
54
|
var request = require('../llm/request.cjs');
|
|
55
55
|
var init = require('../llm/init.cjs');
|
|
56
56
|
var langfuse = require('../langfuse.cjs');
|
|
57
|
+
var instrumentation = require('../instrumentation.cjs');
|
|
58
|
+
var langfuseToolOutputTracing = require('../langfuseToolOutputTracing.cjs');
|
|
57
59
|
var toolCache = require('../llm/openrouter/toolCache.cjs');
|
|
58
60
|
|
|
59
61
|
/* eslint-disable no-console */
|
|
@@ -105,6 +107,10 @@ class Graph {
|
|
|
105
107
|
* graph compiles.
|
|
106
108
|
*/
|
|
107
109
|
toolOutputReferences;
|
|
110
|
+
/**
|
|
111
|
+
* Run-scoped Langfuse defaults. Per-agent config wins when present.
|
|
112
|
+
*/
|
|
113
|
+
langfuse;
|
|
108
114
|
/**
|
|
109
115
|
* Run-scoped opt-in for eager event-driven tool execution. The stream
|
|
110
116
|
* handler may prestart eligible event-driven tools; ToolNode later
|
|
@@ -325,10 +331,11 @@ class StandardGraph extends Graph {
|
|
|
325
331
|
agentContexts = new Map();
|
|
326
332
|
/** Default agent ID to use */
|
|
327
333
|
defaultAgentId;
|
|
328
|
-
constructor({ runId, signal, agents, tokenCounter, indexTokenCountMap, calibrationRatio, }) {
|
|
334
|
+
constructor({ runId, signal, agents, langfuse, tokenCounter, indexTokenCountMap, calibrationRatio, }) {
|
|
329
335
|
super();
|
|
330
336
|
this.runId = runId;
|
|
331
337
|
this.signal = signal;
|
|
338
|
+
this.langfuse = langfuse;
|
|
332
339
|
if (agents.length === 0) {
|
|
333
340
|
throw new Error('At least one agent configuration is required');
|
|
334
341
|
}
|
|
@@ -559,6 +566,10 @@ class StandardGraph extends Graph {
|
|
|
559
566
|
initializeTools({ currentTools, currentToolMap, agentContext, }) {
|
|
560
567
|
const toolDefinitions = agentContext?.toolDefinitions;
|
|
561
568
|
const eventDrivenMode = toolDefinitions != null && toolDefinitions.length > 0;
|
|
569
|
+
const traceToolNode = langfuseToolOutputTracing.shouldTraceToolNodeForLangfuse({
|
|
570
|
+
runLangfuse: this.langfuse,
|
|
571
|
+
agentLangfuse: agentContext?.langfuse,
|
|
572
|
+
});
|
|
562
573
|
if (eventDrivenMode) {
|
|
563
574
|
const schemaTools = schema.createSchemaOnlyTools(toolDefinitions);
|
|
564
575
|
const toolDefMap = new Map(toolDefinitions.map((def) => [def.name, def]));
|
|
@@ -578,6 +589,9 @@ class StandardGraph extends Graph {
|
|
|
578
589
|
const node = new ToolNode.ToolNode({
|
|
579
590
|
tools: allTools,
|
|
580
591
|
toolMap: allToolMap,
|
|
592
|
+
trace: traceToolNode,
|
|
593
|
+
runLangfuse: this.langfuse,
|
|
594
|
+
agentLangfuse: agentContext?.langfuse,
|
|
581
595
|
eventDrivenMode: true,
|
|
582
596
|
sessions: this.sessions,
|
|
583
597
|
toolDefinitions: toolDefMap,
|
|
@@ -616,6 +630,9 @@ class StandardGraph extends Graph {
|
|
|
616
630
|
const node = new ToolNode.ToolNode({
|
|
617
631
|
tools: allTraditionalTools,
|
|
618
632
|
toolMap: traditionalToolMap,
|
|
633
|
+
trace: traceToolNode,
|
|
634
|
+
runLangfuse: this.langfuse,
|
|
635
|
+
agentLangfuse: agentContext?.langfuse,
|
|
619
636
|
toolCallStepIds: this.toolCallStepIds,
|
|
620
637
|
errorHandler: (data, metadata) => StandardGraph.handleToolCallErrorStatic(this, data, metadata),
|
|
621
638
|
toolRegistry: agentContext?.toolRegistry,
|
|
@@ -975,41 +992,56 @@ class StandardGraph extends Graph {
|
|
|
975
992
|
messageCount: finalMessages.length,
|
|
976
993
|
provider: agentContext.provider,
|
|
977
994
|
}, invokeMeta, { force: true });
|
|
978
|
-
const
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
parentMessageId: config.configurable?.requestBody?.parentMessageId,
|
|
985
|
-
agentId,
|
|
986
|
-
agentName: agentContext.name,
|
|
987
|
-
}),
|
|
988
|
-
tags: ['librechat', 'agent'],
|
|
995
|
+
const langfuse$1 = langfuseToolOutputTracing.resolveLangfuseConfig(this.langfuse, agentContext.langfuse);
|
|
996
|
+
const traceMetadata = langfuse.createLangfuseTraceMetadata({
|
|
997
|
+
messageId: this.runId,
|
|
998
|
+
parentMessageId: config.configurable?.requestBody?.parentMessageId,
|
|
999
|
+
agentId,
|
|
1000
|
+
agentName: agentContext.name,
|
|
989
1001
|
});
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
1002
|
+
let langfuseHandler;
|
|
1003
|
+
let invokeConfig = {
|
|
1004
|
+
...config,
|
|
1005
|
+
metadata: {
|
|
1006
|
+
...(config.metadata ?? {}),
|
|
1007
|
+
...traceMetadata,
|
|
1008
|
+
},
|
|
1009
|
+
};
|
|
1010
|
+
instrumentation.initializeLangfuseTracing(langfuse$1);
|
|
1011
|
+
if (callbacks.findCallback(config.callbacks, langfuse.isLangfuseCallbackHandler) == null) {
|
|
1012
|
+
langfuseHandler = langfuse.createLangfuseHandler({
|
|
1013
|
+
langfuse: langfuse$1,
|
|
1014
|
+
userId: config.configurable?.user_id,
|
|
1015
|
+
sessionId: config.configurable?.thread_id,
|
|
1016
|
+
traceMetadata,
|
|
1017
|
+
tags: ['librechat', 'agent'],
|
|
1018
|
+
});
|
|
1019
|
+
if (langfuseHandler != null) {
|
|
1020
|
+
invokeConfig = {
|
|
1021
|
+
...invokeConfig,
|
|
1022
|
+
callbacks: callbacks.appendCallbacks(invokeConfig.callbacks, [
|
|
1023
|
+
langfuseHandler,
|
|
1024
|
+
]),
|
|
1025
|
+
};
|
|
994
1026
|
}
|
|
995
|
-
|
|
1027
|
+
}
|
|
996
1028
|
try {
|
|
997
|
-
result = await invoke.attemptInvoke({
|
|
1029
|
+
result = await langfuseToolOutputTracing.withLangfuseToolOutputTracingConfig(this.langfuse, () => invoke.attemptInvoke({
|
|
998
1030
|
model: (this.overrideModel ?? model),
|
|
999
1031
|
messages: finalMessages,
|
|
1000
1032
|
provider: agentContext.provider,
|
|
1001
1033
|
context: this,
|
|
1002
|
-
}, invokeConfig);
|
|
1034
|
+
}, invokeConfig), agentContext.langfuse);
|
|
1003
1035
|
}
|
|
1004
1036
|
catch (primaryError) {
|
|
1005
|
-
result = await invoke.tryFallbackProviders({
|
|
1037
|
+
result = await langfuseToolOutputTracing.withLangfuseToolOutputTracingConfig(this.langfuse, () => invoke.tryFallbackProviders({
|
|
1006
1038
|
fallbacks,
|
|
1007
1039
|
tools: agentContext.tools,
|
|
1008
1040
|
messages: finalMessages,
|
|
1009
1041
|
config: invokeConfig,
|
|
1010
1042
|
primaryError,
|
|
1011
1043
|
context: this,
|
|
1012
|
-
});
|
|
1044
|
+
}), agentContext.langfuse);
|
|
1013
1045
|
}
|
|
1014
1046
|
finally {
|
|
1015
1047
|
await langfuse.disposeLangfuseHandler(langfuseHandler);
|
|
@@ -1167,6 +1199,7 @@ class StandardGraph extends Graph {
|
|
|
1167
1199
|
parentHandlerRegistry: getParentHandlerRegistry,
|
|
1168
1200
|
parentRunId: this.runId ?? '',
|
|
1169
1201
|
parentAgentId: agentContext.agentId,
|
|
1202
|
+
langfuse: this.langfuse,
|
|
1170
1203
|
tokenCounter: agentContext.tokenCounter,
|
|
1171
1204
|
maxDepth: effectiveSubagentDepth,
|
|
1172
1205
|
createChildGraph: (input) => {
|