@librechat/agents 4.2.9 → 4.2.10

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.
Files changed (84) hide show
  1. package/dist/cjs/agents/AgentContext.cjs +32 -2
  2. package/dist/cjs/agents/AgentContext.cjs.map +1 -1
  3. package/dist/cjs/harness/fileBindings.cjs +93 -0
  4. package/dist/cjs/harness/fileBindings.cjs.map +1 -0
  5. package/dist/cjs/harness/fileService.cjs +141 -0
  6. package/dist/cjs/harness/fileService.cjs.map +1 -0
  7. package/dist/cjs/harness/fileStream.cjs +76 -0
  8. package/dist/cjs/harness/fileStream.cjs.map +1 -0
  9. package/dist/cjs/harness/files.cjs +106 -0
  10. package/dist/cjs/harness/files.cjs.map +1 -0
  11. package/dist/cjs/harness/index.cjs +3 -0
  12. package/dist/cjs/harness/index.cjs.map +1 -1
  13. package/dist/cjs/llm/google/utils/signatures.cjs +5 -3
  14. package/dist/cjs/llm/google/utils/signatures.cjs.map +1 -1
  15. package/dist/cjs/main.cjs +13 -0
  16. package/dist/cjs/tools/BashProgrammaticToolCalling.cjs +3 -2
  17. package/dist/cjs/tools/BashProgrammaticToolCalling.cjs.map +1 -1
  18. package/dist/cjs/tools/ProgrammaticCallerPolicy.cjs +24 -1
  19. package/dist/cjs/tools/ProgrammaticCallerPolicy.cjs.map +1 -1
  20. package/dist/cjs/tools/ProgrammaticToolCalling.cjs +3 -2
  21. package/dist/cjs/tools/ProgrammaticToolCalling.cjs.map +1 -1
  22. package/dist/cjs/tools/local/LocalProgrammaticToolCalling.cjs +2 -1
  23. package/dist/cjs/tools/local/LocalProgrammaticToolCalling.cjs.map +1 -1
  24. package/dist/cjs/tools/subagent/SubagentExecutor.cjs +15 -3
  25. package/dist/cjs/tools/subagent/SubagentExecutor.cjs.map +1 -1
  26. package/dist/cjs/tools/subagent/childGraphConfig.cjs +13 -1
  27. package/dist/cjs/tools/subagent/childGraphConfig.cjs.map +1 -1
  28. package/dist/cjs/tools/subagent/hostArgs.cjs +2 -0
  29. package/dist/cjs/tools/subagent/hostArgs.cjs.map +1 -1
  30. package/dist/esm/agents/AgentContext.mjs +32 -2
  31. package/dist/esm/agents/AgentContext.mjs.map +1 -1
  32. package/dist/esm/harness/fileBindings.mjs +93 -0
  33. package/dist/esm/harness/fileBindings.mjs.map +1 -0
  34. package/dist/esm/harness/fileService.mjs +140 -0
  35. package/dist/esm/harness/fileService.mjs.map +1 -0
  36. package/dist/esm/harness/fileStream.mjs +76 -0
  37. package/dist/esm/harness/fileStream.mjs.map +1 -0
  38. package/dist/esm/harness/files.mjs +97 -0
  39. package/dist/esm/harness/files.mjs.map +1 -0
  40. package/dist/esm/harness/index.mjs +3 -0
  41. package/dist/esm/harness/index.mjs.map +1 -1
  42. package/dist/esm/llm/google/utils/signatures.mjs +5 -3
  43. package/dist/esm/llm/google/utils/signatures.mjs.map +1 -1
  44. package/dist/esm/main.mjs +5 -2
  45. package/dist/esm/tools/BashProgrammaticToolCalling.mjs +3 -2
  46. package/dist/esm/tools/BashProgrammaticToolCalling.mjs.map +1 -1
  47. package/dist/esm/tools/ProgrammaticCallerPolicy.mjs +24 -1
  48. package/dist/esm/tools/ProgrammaticCallerPolicy.mjs.map +1 -1
  49. package/dist/esm/tools/ProgrammaticToolCalling.mjs +3 -2
  50. package/dist/esm/tools/ProgrammaticToolCalling.mjs.map +1 -1
  51. package/dist/esm/tools/local/LocalProgrammaticToolCalling.mjs +2 -1
  52. package/dist/esm/tools/local/LocalProgrammaticToolCalling.mjs.map +1 -1
  53. package/dist/esm/tools/subagent/SubagentExecutor.mjs +15 -3
  54. package/dist/esm/tools/subagent/SubagentExecutor.mjs.map +1 -1
  55. package/dist/esm/tools/subagent/childGraphConfig.mjs +13 -1
  56. package/dist/esm/tools/subagent/childGraphConfig.mjs.map +1 -1
  57. package/dist/esm/tools/subagent/hostArgs.mjs +2 -1
  58. package/dist/esm/tools/subagent/hostArgs.mjs.map +1 -1
  59. package/dist/types/harness/fileBindings.d.ts +13 -0
  60. package/dist/types/harness/fileService.d.ts +37 -0
  61. package/dist/types/harness/fileStream.d.ts +7 -0
  62. package/dist/types/harness/files.d.ts +108 -0
  63. package/dist/types/harness/index.d.ts +6 -0
  64. package/dist/types/tools/ProgrammaticCallerPolicy.d.ts +1 -0
  65. package/dist/types/tools/subagent/hostArgs.d.ts +6 -0
  66. package/dist/types/tools/subagent/index.d.ts +1 -1
  67. package/dist/types/types/graph.d.ts +6 -3
  68. package/package.json +1 -1
  69. package/src/agents/AgentContext.ts +68 -2
  70. package/src/harness/fileBindings.ts +156 -0
  71. package/src/harness/fileService.ts +217 -0
  72. package/src/harness/fileStream.ts +99 -0
  73. package/src/harness/files.ts +185 -0
  74. package/src/harness/index.ts +24 -0
  75. package/src/llm/google/utils/signatures.ts +10 -3
  76. package/src/tools/BashProgrammaticToolCalling.ts +5 -2
  77. package/src/tools/ProgrammaticCallerPolicy.ts +42 -3
  78. package/src/tools/ProgrammaticToolCalling.ts +4 -1
  79. package/src/tools/local/LocalProgrammaticToolCalling.ts +4 -0
  80. package/src/tools/subagent/SubagentExecutor.ts +98 -32
  81. package/src/tools/subagent/childGraphConfig.ts +33 -1
  82. package/src/tools/subagent/hostArgs.ts +7 -0
  83. package/src/tools/subagent/index.ts +1 -0
  84. package/src/types/graph.ts +6 -3
@@ -2,13 +2,16 @@ import { nanoid } from 'nanoid';
2
2
  import { createHash } from 'crypto';
3
3
  import { BaseCallbackHandler } from '@langchain/core/callbacks/base';
4
4
  import { AsyncLocalStorageProviderSingleton } from '@langchain/core/singletons';
5
- import { convertToOpenAITool, isLangChainTool } from '@langchain/core/utils/function_calling';
6
5
  import {
7
6
  AIMessage,
8
7
  BaseMessage,
9
8
  HumanMessage,
10
9
  ToolMessage,
11
10
  } from '@langchain/core/messages';
11
+ import {
12
+ convertToOpenAITool,
13
+ isLangChainTool,
14
+ } from '@langchain/core/utils/function_calling';
12
15
  import {
13
16
  Command,
14
17
  END,
@@ -50,6 +53,7 @@ import type {
50
53
  RunStepClosedEvent,
51
54
  RunStepStatus,
52
55
  StandardGraphInput,
56
+ ExecutableSubagentConfig,
53
57
  ExecutableSubagentConfigEntry,
54
58
  ResolvedSubagentConfig,
55
59
  ResolvedSubagentConfigEntry,
@@ -62,6 +66,7 @@ import type {
62
66
  SubagentTaskRuntime,
63
67
  SubagentResolveConfigurable,
64
68
  SubagentHostArgs,
69
+ SubagentAgentInputsResolver,
65
70
  SubagentResolveRequestContext,
66
71
  SubagentResolveUserContext,
67
72
  StepCompleted,
@@ -435,9 +440,10 @@ type SubagentCheckpointMarker = {
435
440
  };
436
441
 
437
442
  /** Hash serializable options; executable or opaque inputs require a host revision. */
438
- function getRuntimeOptionsIdentity(
439
- options: unknown
440
- ): { digest: string; requiresRevision: boolean } {
443
+ function getRuntimeOptionsIdentity(options: unknown): {
444
+ digest: string;
445
+ requiresRevision: boolean;
446
+ } {
441
447
  const hash = createHash('sha256');
442
448
  const ancestors = new Set<object>();
443
449
  let requiresRevision = false;
@@ -451,7 +457,11 @@ function getRuntimeOptionsIdentity(
451
457
  return;
452
458
  }
453
459
  const kind = typeof value;
454
- if (kind === 'string' || kind === 'boolean' || (kind === 'number' && Number.isFinite(value))) {
460
+ if (
461
+ kind === 'string' ||
462
+ kind === 'boolean' ||
463
+ (kind === 'number' && Number.isFinite(value))
464
+ ) {
455
465
  hash.update(`${kind}:${JSON.stringify(value)};`);
456
466
  return;
457
467
  }
@@ -465,8 +475,11 @@ function getRuntimeOptionsIdentity(
465
475
  return;
466
476
  }
467
477
  const prototype = Object.getPrototypeOf(object);
468
- if (prototype !== Object.prototype && prototype !== null &&
469
- !(Array.isArray(value) && prototype === Array.prototype)) {
478
+ if (
479
+ prototype !== Object.prototype &&
480
+ prototype !== null &&
481
+ !(Array.isArray(value) && prototype === Array.prototype)
482
+ ) {
470
483
  opaque();
471
484
  return;
472
485
  }
@@ -500,9 +513,19 @@ function getRuntimeOptionsIdentity(
500
513
  }
501
514
 
502
515
  const MEMBER_IDENTITY_EXCLUSIONS = new Set([
503
- 'tools', 'toolMap', 'graphTools', 'toolRegistry', 'toolDefinitions',
504
- 'codeSessionKey', 'toolEnd', 'summarizeOnly', 'discoveredTools',
505
- 'initialSessions', 'initialSummary', 'subagentConfigs', 'maxSubagentDepth',
516
+ 'tools',
517
+ 'toolMap',
518
+ 'graphTools',
519
+ 'toolRegistry',
520
+ 'toolDefinitions',
521
+ 'codeSessionKey',
522
+ 'toolEnd',
523
+ 'summarizeOnly',
524
+ 'discoveredTools',
525
+ 'initialSessions',
526
+ 'initialSummary',
527
+ 'subagentConfigs',
528
+ 'maxSubagentDepth',
506
529
  'langfuse',
507
530
  ]);
508
531
 
@@ -519,9 +542,11 @@ function getMemberExecutionIdentity(
519
542
  }
520
543
 
521
544
  function hasExecutableMemberTools(agent: AgentInputs): boolean {
522
- return (agent.toolMap?.size ?? 0) > 0 ||
545
+ return (
546
+ (agent.toolMap?.size ?? 0) > 0 ||
523
547
  (agent.graphTools?.length ?? 0) > 0 ||
524
- agent.tools?.some(isLangChainTool) === true;
548
+ agent.tools?.some(isLangChainTool) === true
549
+ );
525
550
  }
526
551
 
527
552
  /** Declarative graph identity plus the host's revision for executable implementations. */
@@ -537,9 +562,10 @@ function getSubagentDefinitionId(
537
562
  result: config.resultAgentId,
538
563
  edges: config.edges.map((edge) => ({
539
564
  ...edge,
540
- prompt: typeof edge.prompt === 'function'
541
- ? { revision: config.configId }
542
- : edge.prompt,
565
+ prompt:
566
+ typeof edge.prompt === 'function'
567
+ ? { revision: config.configId }
568
+ : edge.prompt,
543
569
  })),
544
570
  members: config.agents.map((agent) => ({
545
571
  id: agent.agentId,
@@ -571,8 +597,8 @@ function getSubagentDefinitionId(
571
597
  convertToOpenAITool(tool),
572
598
  ])
573
599
  ),
574
- tools: agent.tools?.map(
575
- (tool) => (isLangChainTool(tool) ? convertToOpenAITool(tool) : tool)
600
+ tools: agent.tools?.map((tool) =>
601
+ isLangChainTool(tool) ? convertToOpenAITool(tool) : tool
576
602
  ),
577
603
  graphTools: agent.graphTools?.map((tool) => convertToOpenAITool(tool)),
578
604
  })),
@@ -1673,11 +1699,14 @@ export class SubagentExecutor {
1673
1699
  hostArgs?: SubagentHostArgs;
1674
1700
  }
1675
1701
  ): Promise<ResolvedSubagentConfigEntry> {
1676
- if (isGraphSubagentConfig(config) || config.agentInputs != null) {
1677
- return Promise.resolve(config as ResolvedSubagentConfigEntry);
1702
+ if (isGraphSubagentConfig(config)) {
1703
+ return Promise.resolve(config);
1704
+ }
1705
+ const lazy = getExecutionResolver(config, context.hostArgs);
1706
+ if (lazy == null) {
1707
+ return Promise.resolve(config as ResolvedSubagentConfig);
1678
1708
  }
1679
- const resolver = config.resolveAgentInputs;
1680
- const configId = config.configId;
1709
+ const { resolver, configId } = lazy;
1681
1710
  return execution.resolveConfig(
1682
1711
  (): Promise<ResolvedSubagentConfig> =>
1683
1712
  resolveAgentInputsWithSignal(
@@ -2204,14 +2233,25 @@ export class SubagentExecutor {
2204
2233
  ...(activeRun == null
2205
2234
  ? {}
2206
2235
  : {
2207
- pendingInterruptIds: [...new Set(activeRun.pendingInterrupts.flatMap(
2208
- (pending) => pending.id == null ? [] : [pending.id]
2209
- ))],
2210
- pendingInterrupts: activeRun.pendingInterrupts.flatMap((pending) =>
2211
- pending.id == null ? [] : [{
2212
- interruptId: pending.id,
2213
- payload: cloneToolApprovalInterruptPayload(getPublicToolInterruptPayload(pending.value)),
2214
- }]
2236
+ pendingInterruptIds: [
2237
+ ...new Set(
2238
+ activeRun.pendingInterrupts.flatMap((pending) =>
2239
+ pending.id == null ? [] : [pending.id]
2240
+ )
2241
+ ),
2242
+ ],
2243
+ pendingInterrupts: activeRun.pendingInterrupts.flatMap(
2244
+ (pending) =>
2245
+ pending.id == null
2246
+ ? []
2247
+ : [
2248
+ {
2249
+ interruptId: pending.id,
2250
+ payload: cloneToolApprovalInterruptPayload(
2251
+ getPublicToolInterruptPayload(pending.value)
2252
+ ),
2253
+ },
2254
+ ]
2215
2255
  ),
2216
2256
  }),
2217
2257
  ...(descendant == null ? {} : { descendant }),
@@ -3089,8 +3129,9 @@ export class SubagentExecutor {
3089
3129
  member.initialSessions = sessions.initialSessions;
3090
3130
  }
3091
3131
  for (const member of childPlan.agents) {
3092
- const activeMember =
3093
- execution.activeRun?.graph.agentContexts.get(member.agentId);
3132
+ const activeMember = execution.activeRun?.graph.agentContexts.get(
3133
+ member.agentId
3134
+ );
3094
3135
  if (
3095
3136
  activeMember != null &&
3096
3137
  (activeMember.codeSessionKey ?? Constants.EXECUTE_CODE) !==
@@ -3381,7 +3422,9 @@ export class SubagentExecutor {
3381
3422
  const values = persistedState.values as MultiAgentGraphState;
3382
3423
  result = {
3383
3424
  messages: persistedMessages,
3384
- ...(childPlan.kind === 'graph' ? { subagentResult: values.subagentResult } : {}),
3425
+ ...(childPlan.kind === 'graph'
3426
+ ? { subagentResult: values.subagentResult }
3427
+ : {}),
3385
3428
  };
3386
3429
  recoveredComplete = true;
3387
3430
  childAlreadyStarted = true;
@@ -4858,6 +4901,29 @@ function truncateErrorMessage(error: unknown): string {
4858
4901
  return `${message.slice(0, ERROR_MESSAGE_MAX_CHARS)}...`;
4859
4902
  }
4860
4903
 
4904
+ /**
4905
+ * The resolver one call runs through: always a lazy config's, and a `self`
4906
+ * config's only when the call passed host arguments. Every other call keeps
4907
+ * the config's eager or self inputs.
4908
+ */
4909
+ function getExecutionResolver(
4910
+ config: ExecutableSubagentConfig,
4911
+ hostArgs: SubagentHostArgs | undefined
4912
+ ): { resolver: SubagentAgentInputsResolver; configId: string } | undefined {
4913
+ if (config.agentInputs == null) {
4914
+ return { resolver: config.resolveAgentInputs, configId: config.configId };
4915
+ }
4916
+ if (
4917
+ config.self !== true ||
4918
+ hostArgs == null ||
4919
+ config.resolveAgentInputs == null ||
4920
+ config.configId == null
4921
+ ) {
4922
+ return undefined;
4923
+ }
4924
+ return { resolver: config.resolveAgentInputs, configId: config.configId };
4925
+ }
4926
+
4861
4927
  function resolveAgentInputsWithSignal(
4862
4928
  resolve: () => Promise<AgentInputs>,
4863
4929
  signal: AbortSignal
@@ -471,6 +471,34 @@ export function validateGraphSubagentConfig(config: unknown): void {
471
471
  }
472
472
  }
473
473
 
474
+ /**
475
+ * A `self` config that declares host arguments keeps its usual inputs (the
476
+ * provided copy, else the parent's) for calls that pass none; the executor
477
+ * sends calls that pass them through `resolveAgentInputs`.
478
+ */
479
+ function normalizeSelfHostArgConfig(
480
+ config: SubagentConfig,
481
+ parentContext: AgentContext
482
+ ): ResolvedSubagentConfig | null {
483
+ if (config.resolveAgentInputs == null) {
484
+ throw new Error(
485
+ `Self subagent "${config.type}" declares hostArgs, which requires resolveAgentInputs for the calls that pass them.`
486
+ );
487
+ }
488
+ if (!isNonEmptyString(config.configId)) {
489
+ throw new Error(
490
+ `Self subagent "${config.type}" declares hostArgs and requires a non-empty "configId".`
491
+ );
492
+ }
493
+ if (config.agentInputs != null) {
494
+ return config as ResolvedSubagentConfig;
495
+ }
496
+ if (parentContext._sourceInputs == null) {
497
+ return null;
498
+ }
499
+ return { ...config, agentInputs: { ...parentContext._sourceInputs } };
500
+ }
501
+
474
502
  function normalizeSingleAgentConfig(
475
503
  config: SubagentConfig,
476
504
  parentContext: AgentContext
@@ -487,13 +515,17 @@ function normalizeSingleAgentConfig(
487
515
  `Single-agent subagent "${config.type}" cannot define graph topology fields.`
488
516
  );
489
517
  }
518
+ const declaresHostArgs = getSubagentHostArgSpecs(config).length > 0;
519
+ if (config.self === true && declaresHostArgs) {
520
+ return normalizeSelfHostArgConfig(config, parentContext);
521
+ }
490
522
  if (config.self === true && config.resolveAgentInputs != null) {
491
523
  throw new Error(
492
524
  `Subagent "${config.type}" cannot combine self with resolveAgentInputs.`
493
525
  );
494
526
  }
495
527
  if (
496
- getSubagentHostArgSpecs(config).length > 0 &&
528
+ declaresHostArgs &&
497
529
  (config.resolveAgentInputs == null || config.agentInputs != null)
498
530
  ) {
499
531
  throw new Error(
@@ -6,6 +6,13 @@ import type {
6
6
  } from '@/types/graph';
7
7
  import type { JsonSchemaType } from '@/types/tools';
8
8
 
9
+ /**
10
+ * Feature probe: `self` subagent configs may declare `hostArgs` together with
11
+ * `resolveAgentInputs` and a `configId`. Calls that pass host arguments are
12
+ * resolved through the resolver; calls that pass none reuse the self inputs.
13
+ */
14
+ export const SELF_SUBAGENT_HOST_ARGS_SUPPORTED = true;
15
+
9
16
  /** Bounds on host-declared subagent call arguments and their values. */
10
17
  export const SUBAGENT_HOST_ARG_LIMITS = Object.freeze({
11
18
  argsPerSubagent: 8,
@@ -27,6 +27,7 @@ export {
27
27
  } from './diagnostics';
28
28
  export {
29
29
  SUBAGENT_HOST_ARG_LIMITS,
30
+ SELF_SUBAGENT_HOST_ARGS_SUPPORTED,
30
31
  buildSubagentHostArgProperties,
31
32
  resolveSubagentHostArgs,
32
33
  } from './hostArgs';
@@ -645,8 +645,10 @@ export interface SubagentConfig extends SubagentConfigBase {
645
645
  agentInputs?: AgentInputs;
646
646
  /**
647
647
  * Resolve the full child config only after this descriptor is selected.
648
- * Eager `agentInputs` take precedence when also supplied. `self` and a
649
- * resolver are mutually exclusive and normalization rejects that pairing.
648
+ * Eager `agentInputs` take precedence when also supplied. A `self` config
649
+ * may set a resolver only together with `hostArgs` and a `configId`; it then
650
+ * runs only for calls that pass host arguments, and every other call reuses
651
+ * the self inputs. Normalization rejects any other `self` + resolver pairing.
650
652
  *
651
653
  * Resolvers should rebuild inputs from the stable execution context instead
652
654
  * of retaining request-owned state. The SDK keeps resolved inputs in memory
@@ -660,7 +662,8 @@ export interface SubagentConfig extends SubagentConfigBase {
660
662
  /**
661
663
  * Optional per-call arguments the parent model may pass for this subagent,
662
664
  * delivered to `resolveAgentInputs` as `context.hostArgs`. Only lazy
663
- * configs accept them. Declaring none leaves the tool schema unchanged.
665
+ * configs and `self` configs with a resolver accept them. Declaring none
666
+ * leaves the tool schema unchanged.
664
667
  */
665
668
  hostArgs?: SubagentHostArgSpecs;
666
669
  /** When true, reuse the parent's AgentInputs (context isolation without separate config). */