@librechat/agents 3.4.3 → 3.4.4
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 +27 -14
- package/dist/cjs/graphs/Graph.cjs.map +1 -1
- package/dist/cjs/graphs/MultiAgentGraph.cjs +1 -1
- package/dist/cjs/instrumentation.cjs +3 -3
- package/dist/cjs/langfuse.cjs +3 -3
- package/dist/cjs/langfuseRuntimeScope.cjs +1 -1
- package/dist/cjs/langfuseToolOutputTracing.cjs +2 -2
- package/dist/cjs/main.cjs +5 -1
- package/dist/cjs/messages/assistantPhase.cjs +59 -0
- package/dist/cjs/messages/assistantPhase.cjs.map +1 -0
- package/dist/cjs/messages/index.cjs +1 -0
- package/dist/cjs/prompts/activityLabel.cjs +76 -0
- package/dist/cjs/prompts/activityLabel.cjs.map +1 -1
- package/dist/cjs/run.cjs +200 -10
- package/dist/cjs/run.cjs.map +1 -1
- package/dist/cjs/session/AgentSession.cjs +1 -1
- package/dist/cjs/stream.cjs +45 -8
- package/dist/cjs/stream.cjs.map +1 -1
- package/dist/cjs/tools/ToolNode.cjs +3 -3
- package/dist/cjs/tools/subagent/SubagentExecutor.cjs +81 -6
- package/dist/cjs/tools/subagent/SubagentExecutor.cjs.map +1 -1
- package/dist/cjs/utils/callbacks.cjs +8 -0
- package/dist/cjs/utils/callbacks.cjs.map +1 -1
- package/dist/esm/graphs/Graph.mjs +27 -14
- package/dist/esm/graphs/Graph.mjs.map +1 -1
- package/dist/esm/graphs/MultiAgentGraph.mjs +1 -1
- package/dist/esm/instrumentation.mjs +3 -3
- package/dist/esm/langfuse.mjs +3 -3
- package/dist/esm/langfuseRuntimeScope.mjs +1 -1
- package/dist/esm/langfuseToolOutputTracing.mjs +2 -2
- package/dist/esm/main.mjs +3 -2
- package/dist/esm/messages/assistantPhase.mjs +57 -0
- package/dist/esm/messages/assistantPhase.mjs.map +1 -0
- package/dist/esm/messages/index.mjs +1 -0
- package/dist/esm/prompts/activityLabel.mjs +74 -1
- package/dist/esm/prompts/activityLabel.mjs.map +1 -1
- package/dist/esm/run.mjs +202 -12
- package/dist/esm/run.mjs.map +1 -1
- package/dist/esm/session/AgentSession.mjs +1 -1
- package/dist/esm/stream.mjs +45 -8
- package/dist/esm/stream.mjs.map +1 -1
- package/dist/esm/tools/ToolNode.mjs +3 -3
- package/dist/esm/tools/subagent/SubagentExecutor.mjs +81 -6
- package/dist/esm/tools/subagent/SubagentExecutor.mjs.map +1 -1
- package/dist/esm/utils/callbacks.mjs +8 -1
- package/dist/esm/utils/callbacks.mjs.map +1 -1
- package/dist/types/messages/assistantPhase.d.ts +22 -0
- package/dist/types/messages/index.d.ts +1 -0
- package/dist/types/prompts/activityLabel.d.ts +21 -1
- package/dist/types/run.d.ts +15 -2
- package/dist/types/types/activityLabel.d.ts +63 -0
- package/dist/types/types/assistantPhase.d.ts +6 -0
- package/dist/types/types/graph.d.ts +8 -1
- package/dist/types/types/index.d.ts +1 -0
- package/dist/types/types/stream.d.ts +11 -0
- package/dist/types/utils/callbacks.d.ts +1 -0
- package/package.json +1 -1
- package/src/graphs/Graph.ts +33 -9
- package/src/graphs/__tests__/Graph.reasoning.test.ts +57 -0
- package/src/messages/assistantPhase.test.ts +75 -0
- package/src/messages/assistantPhase.ts +91 -0
- package/src/messages/index.ts +1 -0
- package/src/prompts/activityLabel.ts +177 -1
- package/src/run.ts +403 -21
- package/src/specs/activity-label-prompt.test.ts +123 -1
- package/src/specs/activity-phase-label.test.ts +306 -0
- package/src/stream.ts +69 -12
- package/src/tools/__tests__/SubagentExecutor.test.ts +436 -0
- package/src/tools/subagent/SubagentExecutor.ts +160 -8
- package/src/types/activityLabel.ts +65 -0
- package/src/types/assistantPhase.ts +6 -0
- package/src/types/graph.ts +8 -0
- package/src/types/index.ts +1 -0
- package/src/types/stream.ts +9 -0
- package/src/utils/callbacks.ts +21 -0
|
@@ -2,8 +2,8 @@ const require_SubagentReplay = require("./SubagentReplay.cjs");
|
|
|
2
2
|
const require_misc = require("../../utils/misc.cjs");
|
|
3
3
|
require("../../common/enum.cjs");
|
|
4
4
|
require("../../common/index.cjs");
|
|
5
|
-
const require_eagerEventExecution = require("../eagerEventExecution.cjs");
|
|
6
5
|
const require_streamLimits = require("../../llm/streamLimits.cjs");
|
|
6
|
+
const require_eagerEventExecution = require("../eagerEventExecution.cjs");
|
|
7
7
|
const require_SubagentExecutionRegistry = require("./SubagentExecutionRegistry.cjs");
|
|
8
8
|
require("./runtimeLimits.cjs");
|
|
9
9
|
const require_executeHooks = require("../../hooks/executeHooks.cjs");
|
|
@@ -12,8 +12,8 @@ require("../../hooks/index.cjs");
|
|
|
12
12
|
const require_childGraphConfig = require("./childGraphConfig.cjs");
|
|
13
13
|
let nanoid = require("nanoid");
|
|
14
14
|
let _langchain_core_callbacks_base = require("@langchain/core/callbacks/base");
|
|
15
|
-
let _langchain_core_messages = require("@langchain/core/messages");
|
|
16
15
|
let _langchain_langgraph = require("@langchain/langgraph");
|
|
16
|
+
let _langchain_core_messages = require("@langchain/core/messages");
|
|
17
17
|
let _langchain_core_singletons = require("@langchain/core/singletons");
|
|
18
18
|
let crypto = require("crypto");
|
|
19
19
|
//#region src/tools/subagent/SubagentExecutor.ts
|
|
@@ -24,6 +24,48 @@ const TEXT_DELTA_CONTENT_TYPE = `text_delta`;
|
|
|
24
24
|
const SUBAGENT_RESOLUTION_ERROR_MESSAGE = "Subagent error: Unable to initialize the selected subagent.";
|
|
25
25
|
const SUBAGENT_CONFIG_CHANGED_MESSAGE = "Subagent error: Subagent configuration changed since this execution was paused.";
|
|
26
26
|
const SUBAGENT_INVOCATION_CHANGED_MESSAGE = "Subagent error: Subagent invocation changed for this execution.";
|
|
27
|
+
function cloneToolSessionContext(context) {
|
|
28
|
+
return {
|
|
29
|
+
...context,
|
|
30
|
+
...context.files == null ? {} : { files: context.files.map((file) => ({
|
|
31
|
+
...file,
|
|
32
|
+
storage_session_id: file.storage_session_id ?? context.session_id
|
|
33
|
+
})) }
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
function seedChildGraphSessions(childGraph, agents) {
|
|
37
|
+
const seenFilesByTool = /* @__PURE__ */ new Map();
|
|
38
|
+
for (const agent of agents) {
|
|
39
|
+
if (agent.initialSessions == null) continue;
|
|
40
|
+
for (const [toolName, context] of agent.initialSessions) {
|
|
41
|
+
const existing = childGraph.sessions.get(toolName);
|
|
42
|
+
if (existing == null) {
|
|
43
|
+
const cloned = cloneToolSessionContext(context);
|
|
44
|
+
childGraph.sessions.set(toolName, cloned);
|
|
45
|
+
seenFilesByTool.set(toolName, new Set(cloned.files?.map((file) => `${file.storage_session_id ?? ""}\0${file.id}`) ?? []));
|
|
46
|
+
continue;
|
|
47
|
+
}
|
|
48
|
+
if (context.files == null || context.files.length === 0) continue;
|
|
49
|
+
const seenFiles = seenFilesByTool.get(toolName) ?? new Set(existing.files?.map((file) => `${file.storage_session_id ?? existing.session_id}\0${file.id}`) ?? []);
|
|
50
|
+
const files = existing.files == null ? [] : [...existing.files];
|
|
51
|
+
for (const file of context.files) {
|
|
52
|
+
const storageSessionId = file.storage_session_id ?? context.session_id;
|
|
53
|
+
const key = `${storageSessionId}\0${file.id}`;
|
|
54
|
+
if (seenFiles.has(key)) continue;
|
|
55
|
+
seenFiles.add(key);
|
|
56
|
+
files.push({
|
|
57
|
+
...file,
|
|
58
|
+
storage_session_id: storageSessionId
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
seenFilesByTool.set(toolName, seenFiles);
|
|
62
|
+
childGraph.sessions.set(toolName, {
|
|
63
|
+
...existing,
|
|
64
|
+
files
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
27
69
|
async function dispatchObservationalSubagentUpdate(handler, event) {
|
|
28
70
|
let timeout;
|
|
29
71
|
try {
|
|
@@ -916,12 +958,14 @@ var SubagentExecutor = class {
|
|
|
916
958
|
});
|
|
917
959
|
}
|
|
918
960
|
childGraph ??= this.createChildGraph(childGraphInput);
|
|
961
|
+
if (cachedChildRun == null) seedChildGraphSessions(childGraph, childPlan.agents);
|
|
919
962
|
let forwarding;
|
|
920
963
|
if (forwardingEnabled) forwarding = this.createForwarderCallback({
|
|
921
964
|
parentRegistry,
|
|
922
965
|
subagentType,
|
|
923
966
|
subagentKind: childPlan.kind,
|
|
924
967
|
subagentAgentId: childAgentId,
|
|
968
|
+
graphMemberInputs: childPlan.kind === "graph" ? childPlan.memberInputs : void 0,
|
|
925
969
|
childRunId,
|
|
926
970
|
parentToolCallId,
|
|
927
971
|
executionContext: childExecutionContext
|
|
@@ -1238,9 +1282,10 @@ var SubagentExecutor = class {
|
|
|
1238
1282
|
* cares about; host apps can extend by registering more phases).
|
|
1239
1283
|
*/
|
|
1240
1284
|
createForwarderCallback(args) {
|
|
1241
|
-
const { parentRegistry, subagentType, subagentKind, subagentAgentId, childRunId, parentToolCallId, executionContext } = args;
|
|
1285
|
+
const { parentRegistry, subagentType, subagentKind, subagentAgentId, graphMemberInputs, childRunId, parentToolCallId, executionContext } = args;
|
|
1242
1286
|
const immediateParentRunId = this.parentRunId;
|
|
1243
1287
|
const parentAgentId = this.parentAgentId;
|
|
1288
|
+
const memberAgentIdByStepId = /* @__PURE__ */ new Map();
|
|
1244
1289
|
const wrap = async (eventName, phase, data, memberAgentId) => {
|
|
1245
1290
|
const handler = parentRegistry.getHandler("on_subagent_update");
|
|
1246
1291
|
if (!handler) return true;
|
|
@@ -1307,7 +1352,12 @@ var SubagentExecutor = class {
|
|
|
1307
1352
|
drain();
|
|
1308
1353
|
};
|
|
1309
1354
|
const handler = _langchain_core_callbacks_base.BaseCallbackHandler.fromMethods({ ["handleCustomEvent"]: async (eventName, data, _runId, _tags, metadata) => {
|
|
1310
|
-
const memberAgentId = asNonEmptyString(metadata?.agentId) ?? getEventAgentId(data)
|
|
1355
|
+
const memberAgentId = graphMemberInputs == null ? asNonEmptyString(metadata?.agentId) ?? getEventAgentId(data) : getGraphEventMemberAgentId({
|
|
1356
|
+
data,
|
|
1357
|
+
metadata,
|
|
1358
|
+
memberInputs: graphMemberInputs,
|
|
1359
|
+
memberAgentIdByStepId
|
|
1360
|
+
});
|
|
1311
1361
|
if (eventName === "on_tool_execute") {
|
|
1312
1362
|
const toolHandler = parentRegistry.getHandler("on_tool_execute");
|
|
1313
1363
|
if (toolHandler) await toolHandler.handle("on_tool_execute", data);
|
|
@@ -1457,6 +1507,24 @@ function getEventAgentId(data) {
|
|
|
1457
1507
|
const event = data;
|
|
1458
1508
|
return asNonEmptyString(event.agentId) ?? asNonEmptyString(event.result?.agentId);
|
|
1459
1509
|
}
|
|
1510
|
+
function getEventStepId(data) {
|
|
1511
|
+
if (data == null || typeof data !== "object") return;
|
|
1512
|
+
const event = data;
|
|
1513
|
+
return asNonEmptyString(event.id) ?? asNonEmptyString(event.result?.id);
|
|
1514
|
+
}
|
|
1515
|
+
function getGraphEventMemberAgentId({ data, metadata, memberInputs, memberAgentIdByStepId }) {
|
|
1516
|
+
const eventAgentId = getEventAgentId(data);
|
|
1517
|
+
const stepId = getEventStepId(data);
|
|
1518
|
+
if (eventAgentId != null) {
|
|
1519
|
+
if (!memberInputs.has(eventAgentId)) return;
|
|
1520
|
+
if (stepId != null) memberAgentIdByStepId.set(stepId, eventAgentId);
|
|
1521
|
+
return eventAgentId;
|
|
1522
|
+
}
|
|
1523
|
+
const stepMemberAgentId = stepId == null ? void 0 : memberAgentIdByStepId.get(stepId);
|
|
1524
|
+
if (stepMemberAgentId != null) return stepMemberAgentId;
|
|
1525
|
+
const metadataAgentId = asNonEmptyString(metadata?.agentId);
|
|
1526
|
+
return metadataAgentId != null && memberInputs.has(metadataAgentId) ? metadataAgentId : void 0;
|
|
1527
|
+
}
|
|
1460
1528
|
/**
|
|
1461
1529
|
* Best-effort read of the configured model from a subagent's client
|
|
1462
1530
|
* options. Providers disagree on the key (`model` vs `modelName`), and the
|
|
@@ -1589,8 +1657,15 @@ function sanitizeStepDetails(stepDetails) {
|
|
|
1589
1657
|
const rawDetails = stepDetails;
|
|
1590
1658
|
if (rawDetails.type === "message_creation") {
|
|
1591
1659
|
const sanitized = { type: "message_creation" };
|
|
1592
|
-
const
|
|
1593
|
-
|
|
1660
|
+
const rawMessageCreation = rawDetails.message_creation;
|
|
1661
|
+
const messageId = rawMessageCreation?.message_id;
|
|
1662
|
+
const contentType = rawMessageCreation?.content_type;
|
|
1663
|
+
const phase = rawMessageCreation?.phase;
|
|
1664
|
+
if (typeof messageId === "string" || contentType === "text" || contentType === "think" || phase === "commentary" || phase === "final_answer") sanitized.message_creation = {
|
|
1665
|
+
...typeof messageId === "string" ? { message_id: messageId } : {},
|
|
1666
|
+
...contentType === "text" || contentType === "think" ? { content_type: contentType } : {},
|
|
1667
|
+
...phase === "commentary" || phase === "final_answer" ? { phase } : {}
|
|
1668
|
+
};
|
|
1594
1669
|
return sanitized;
|
|
1595
1670
|
}
|
|
1596
1671
|
if (rawDetails.type === "tool_calls") {
|