@librechat/agents 3.1.78-dev.0 → 3.1.78
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 +7 -0
- package/dist/cjs/graphs/Graph.cjs.map +1 -1
- package/dist/cjs/tools/subagent/SubagentExecutor.cjs +30 -0
- package/dist/cjs/tools/subagent/SubagentExecutor.cjs.map +1 -1
- package/dist/esm/graphs/Graph.mjs +7 -0
- package/dist/esm/graphs/Graph.mjs.map +1 -1
- package/dist/esm/tools/subagent/SubagentExecutor.mjs +30 -0
- package/dist/esm/tools/subagent/SubagentExecutor.mjs.map +1 -1
- package/dist/types/tools/subagent/SubagentExecutor.d.ts +29 -0
- package/package.json +1 -1
- package/src/graphs/Graph.ts +9 -0
- package/src/scripts/subagent-configurable-inheritance.ts +252 -0
- package/src/tools/__tests__/SubagentExecutor.test.ts +148 -0
- package/src/tools/subagent/SubagentExecutor.ts +60 -0
|
@@ -40,6 +40,35 @@ export type SubagentExecuteParams = {
|
|
|
40
40
|
* without relying on event ordering heuristics.
|
|
41
41
|
*/
|
|
42
42
|
parentToolCallId?: string;
|
|
43
|
+
/**
|
|
44
|
+
* Snapshot of the parent invocation's `config.configurable` at the
|
|
45
|
+
* spawn-tool call site. Inherited verbatim into the child workflow's
|
|
46
|
+
* `configurable` so host-set fields (`requestBody`, `user`,
|
|
47
|
+
* `userMCPAuthMap`, etc.) propagate — fixing MCP body-placeholder
|
|
48
|
+
* substitution and per-user lookups for subagent tool calls.
|
|
49
|
+
*
|
|
50
|
+
* Inheritance details (verified empirically against LangGraph):
|
|
51
|
+
* - host-set keys propagate as-is into the child's tool dispatches;
|
|
52
|
+
* - `thread_id` propagates (with `childRunId` as a fallback when
|
|
53
|
+
* parent did not supply one) — matches the "subagent is part of
|
|
54
|
+
* the same conversation" mental model and aligns with the
|
|
55
|
+
* `sessionId: this.parentRunId` convention this executor already
|
|
56
|
+
* uses for `SubagentStart` / `SubagentStop` hooks;
|
|
57
|
+
* - `parent_run_id` propagates when the host put it on parent's
|
|
58
|
+
* configurable;
|
|
59
|
+
* - `run_id` is *overwritten by the LangGraph runtime* at child
|
|
60
|
+
* invoke time regardless of what we forward — child's tool
|
|
61
|
+
* dispatches see the child graph's runtime runId in
|
|
62
|
+
* `configurable.run_id`, not the parent's. Hosts that need
|
|
63
|
+
* parent-scoped run identity for downstream consumers should
|
|
64
|
+
* plumb it via a host-defined key (e.g. `requestBody.messageId`),
|
|
65
|
+
* not `run_id`.
|
|
66
|
+
*
|
|
67
|
+
* A future revision will likely make this inheritance configurable
|
|
68
|
+
* per spawn type — background / async subagents may want isolation
|
|
69
|
+
* rather than sharing parent's host context.
|
|
70
|
+
*/
|
|
71
|
+
parentConfigurable?: Record<string, unknown>;
|
|
43
72
|
};
|
|
44
73
|
|
|
45
74
|
export type SubagentExecuteResult = {
|
|
@@ -246,6 +275,36 @@ export class SubagentExecutor {
|
|
|
246
275
|
* nested trace pollution).
|
|
247
276
|
*/
|
|
248
277
|
const callbacks: Callbacks = forwarder ? [forwarder] : [];
|
|
278
|
+
/**
|
|
279
|
+
* Inherit the parent's `configurable` verbatim — host-set fields
|
|
280
|
+
* (`requestBody`, `user`, `userMCPAuthMap`, etc.) AND the run-
|
|
281
|
+
* identity fields (`run_id`, `parent_run_id`, `thread_id`) all
|
|
282
|
+
* propagate.
|
|
283
|
+
*
|
|
284
|
+
* Run-identity propagation is intentional and matches the
|
|
285
|
+
* convention this executor itself already uses for `SubagentStart`
|
|
286
|
+
* / `SubagentStop` hooks (`sessionId: this.parentRunId`): the
|
|
287
|
+
* subagent runs under the parent's session scope, not its own.
|
|
288
|
+
* Forwarding `run_id` / `parent_run_id` / `thread_id` makes
|
|
289
|
+
* `ToolNode`'s hook lookups (`hasHookFor(eventName, runId)`),
|
|
290
|
+
* `ToolOutputReferenceRegistry` keying, and trace lineage all
|
|
291
|
+
* resolve to the parent's session for tools dispatched from the
|
|
292
|
+
* subagent — so `PreToolUse` / `PostToolUse` hooks the host
|
|
293
|
+
* registered against the parent's run fire for subagent tool
|
|
294
|
+
* calls too. "Same run" matches the user-perceptual mental model.
|
|
295
|
+
*
|
|
296
|
+
* `thread_id` falls back to `childRunId` only when the parent
|
|
297
|
+
* didn't supply one (legacy behavior preserved for hosts that
|
|
298
|
+
* never set thread_id).
|
|
299
|
+
*
|
|
300
|
+
* NOTE: a future revision will likely make this configurable per
|
|
301
|
+
* spawn type — e.g. a background / async subagent that runs after
|
|
302
|
+
* the parent's run completes wants isolation, not inheritance.
|
|
303
|
+
* For now the inheritance path matches LibreChat's primary use
|
|
304
|
+
* case (synchronous subagents within a single user turn).
|
|
305
|
+
*/
|
|
306
|
+
const inheritedConfigurable: Record<string, unknown> =
|
|
307
|
+
params.parentConfigurable ?? {};
|
|
249
308
|
result = await workflow.invoke(
|
|
250
309
|
{ messages: [new HumanMessage(description)] },
|
|
251
310
|
{
|
|
@@ -255,6 +314,7 @@ export class SubagentExecutor {
|
|
|
255
314
|
runName: `subagent:${subagentType}`,
|
|
256
315
|
configurable: {
|
|
257
316
|
thread_id: childRunId,
|
|
317
|
+
...inheritedConfigurable,
|
|
258
318
|
},
|
|
259
319
|
}
|
|
260
320
|
);
|