@librechat/agents 3.4.1 → 3.4.2

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 (128) hide show
  1. package/dist/cjs/agents/AgentContext.cjs.map +1 -1
  2. package/dist/cjs/graphs/Graph.cjs +57 -33
  3. package/dist/cjs/graphs/Graph.cjs.map +1 -1
  4. package/dist/cjs/graphs/MultiAgentGraph.cjs +81 -33
  5. package/dist/cjs/graphs/MultiAgentGraph.cjs.map +1 -1
  6. package/dist/cjs/graphs/applyGraphRuntimeConfig.cjs +14 -0
  7. package/dist/cjs/graphs/applyGraphRuntimeConfig.cjs.map +1 -0
  8. package/dist/cjs/graphs/createGraph.cjs +15 -0
  9. package/dist/cjs/graphs/createGraph.cjs.map +1 -0
  10. package/dist/cjs/graphs/index.cjs +1 -0
  11. package/dist/cjs/hooks/createWorkspacePolicyHook.cjs +1 -1
  12. package/dist/cjs/main.cjs +20 -11
  13. package/dist/cjs/run.cjs +48 -38
  14. package/dist/cjs/run.cjs.map +1 -1
  15. package/dist/cjs/session/JsonlSessionStore.cjs +2 -2
  16. package/dist/cjs/tools/SubagentTool.cjs +4 -4
  17. package/dist/cjs/tools/SubagentTool.cjs.map +1 -1
  18. package/dist/cjs/tools/ToolNode.cjs +13 -9
  19. package/dist/cjs/tools/ToolNode.cjs.map +1 -1
  20. package/dist/cjs/tools/eagerEventExecution.cjs +1 -0
  21. package/dist/cjs/tools/local/LocalExecutionEngine.cjs +3 -3
  22. package/dist/cjs/tools/local/LocalProgrammaticToolCalling.cjs +2 -2
  23. package/dist/cjs/tools/search/rerankers.cjs +154 -1
  24. package/dist/cjs/tools/search/rerankers.cjs.map +1 -1
  25. package/dist/cjs/tools/search/tool.cjs +4 -1
  26. package/dist/cjs/tools/search/tool.cjs.map +1 -1
  27. package/dist/cjs/tools/subagent/SubagentExecutionRegistry.cjs +601 -0
  28. package/dist/cjs/tools/subagent/SubagentExecutionRegistry.cjs.map +1 -0
  29. package/dist/cjs/tools/subagent/SubagentExecutor.cjs +672 -343
  30. package/dist/cjs/tools/subagent/SubagentExecutor.cjs.map +1 -1
  31. package/dist/cjs/tools/subagent/SubagentReplay.cjs +3 -1
  32. package/dist/cjs/tools/subagent/SubagentReplay.cjs.map +1 -1
  33. package/dist/cjs/tools/subagent/childGraphConfig.cjs +278 -0
  34. package/dist/cjs/tools/subagent/childGraphConfig.cjs.map +1 -0
  35. package/dist/cjs/tools/subagent/index.cjs +1 -0
  36. package/dist/cjs/tools/subagent/runtimeLimits.cjs +5 -0
  37. package/dist/cjs/tools/subagent/runtimeLimits.cjs.map +1 -0
  38. package/dist/esm/agents/AgentContext.mjs.map +1 -1
  39. package/dist/esm/graphs/Graph.mjs +57 -33
  40. package/dist/esm/graphs/Graph.mjs.map +1 -1
  41. package/dist/esm/graphs/MultiAgentGraph.mjs +81 -33
  42. package/dist/esm/graphs/MultiAgentGraph.mjs.map +1 -1
  43. package/dist/esm/graphs/applyGraphRuntimeConfig.mjs +14 -0
  44. package/dist/esm/graphs/applyGraphRuntimeConfig.mjs.map +1 -0
  45. package/dist/esm/graphs/createGraph.mjs +15 -0
  46. package/dist/esm/graphs/createGraph.mjs.map +1 -0
  47. package/dist/esm/graphs/index.mjs +1 -0
  48. package/dist/esm/hooks/createWorkspacePolicyHook.mjs +1 -1
  49. package/dist/esm/main.mjs +12 -10
  50. package/dist/esm/run.mjs +48 -38
  51. package/dist/esm/run.mjs.map +1 -1
  52. package/dist/esm/session/JsonlSessionStore.mjs +2 -2
  53. package/dist/esm/tools/SubagentTool.mjs +4 -4
  54. package/dist/esm/tools/SubagentTool.mjs.map +1 -1
  55. package/dist/esm/tools/ToolNode.mjs +13 -9
  56. package/dist/esm/tools/ToolNode.mjs.map +1 -1
  57. package/dist/esm/tools/eagerEventExecution.mjs +1 -1
  58. package/dist/esm/tools/local/LocalExecutionEngine.mjs +3 -3
  59. package/dist/esm/tools/local/LocalProgrammaticToolCalling.mjs +2 -2
  60. package/dist/esm/tools/search/rerankers.mjs +154 -1
  61. package/dist/esm/tools/search/rerankers.mjs.map +1 -1
  62. package/dist/esm/tools/search/tool.mjs +4 -1
  63. package/dist/esm/tools/search/tool.mjs.map +1 -1
  64. package/dist/esm/tools/subagent/SubagentExecutionRegistry.mjs +597 -0
  65. package/dist/esm/tools/subagent/SubagentExecutionRegistry.mjs.map +1 -0
  66. package/dist/esm/tools/subagent/SubagentExecutor.mjs +672 -343
  67. package/dist/esm/tools/subagent/SubagentExecutor.mjs.map +1 -1
  68. package/dist/esm/tools/subagent/SubagentReplay.mjs +3 -1
  69. package/dist/esm/tools/subagent/SubagentReplay.mjs.map +1 -1
  70. package/dist/esm/tools/subagent/childGraphConfig.mjs +272 -0
  71. package/dist/esm/tools/subagent/childGraphConfig.mjs.map +1 -0
  72. package/dist/esm/tools/subagent/index.mjs +1 -0
  73. package/dist/esm/tools/subagent/runtimeLimits.mjs +5 -0
  74. package/dist/esm/tools/subagent/runtimeLimits.mjs.map +1 -0
  75. package/dist/types/agents/AgentContext.d.ts +1 -1
  76. package/dist/types/graphs/Graph.d.ts +7 -2
  77. package/dist/types/graphs/MultiAgentGraph.d.ts +7 -1
  78. package/dist/types/graphs/applyGraphRuntimeConfig.d.ts +3 -0
  79. package/dist/types/graphs/createGraph.d.ts +13 -0
  80. package/dist/types/graphs/graphFactory.d.ts +13 -0
  81. package/dist/types/graphs/index.d.ts +2 -0
  82. package/dist/types/run.d.ts +2 -2
  83. package/dist/types/tools/SubagentTool.d.ts +1 -1
  84. package/dist/types/tools/search/rerankers.d.ts +28 -0
  85. package/dist/types/tools/search/types.d.ts +38 -1
  86. package/dist/types/tools/subagent/SubagentExecutionRegistry.d.ts +171 -0
  87. package/dist/types/tools/subagent/SubagentExecutor.d.ts +32 -37
  88. package/dist/types/tools/subagent/SubagentReplay.d.ts +5 -1
  89. package/dist/types/tools/subagent/childGraphConfig.d.ts +37 -0
  90. package/dist/types/tools/subagent/index.d.ts +1 -1
  91. package/dist/types/tools/subagent/runtimeLimits.d.ts +4 -0
  92. package/dist/types/types/graph.d.ts +184 -19
  93. package/package.json +3 -1
  94. package/src/agents/AgentContext.ts +1 -1
  95. package/src/graphs/Graph.ts +111 -60
  96. package/src/graphs/MultiAgentGraph.ts +149 -47
  97. package/src/graphs/__tests__/MultiAgentGraph.test.ts +86 -0
  98. package/src/graphs/__tests__/composition.smoke.test.ts +152 -0
  99. package/src/graphs/__tests__/createGraph.test.ts +206 -0
  100. package/src/graphs/applyGraphRuntimeConfig.ts +25 -0
  101. package/src/graphs/createGraph.ts +32 -0
  102. package/src/graphs/graphFactory.ts +12 -0
  103. package/src/graphs/index.ts +2 -0
  104. package/src/run.ts +50 -38
  105. package/src/specs/graph-subagent.live.test.ts +242 -0
  106. package/src/specs/graph-subagent.test.ts +322 -0
  107. package/src/specs/langfuse-routing.integration.test.ts +120 -1
  108. package/src/specs/subagent.test.ts +130 -4
  109. package/src/tools/SubagentTool.ts +4 -4
  110. package/src/tools/ToolNode.ts +22 -10
  111. package/src/tools/__tests__/SubagentExecutor.test.ts +198 -9
  112. package/src/tools/__tests__/SubagentReplay.test.ts +29 -0
  113. package/src/tools/__tests__/directToolHITLResumeScope.test.ts +28 -2
  114. package/src/tools/__tests__/subagentHooks.test.ts +90 -3
  115. package/src/tools/search/rag-api-reranker.test.ts +891 -0
  116. package/src/tools/search/rerankers.ts +260 -0
  117. package/src/tools/search/tool.ts +6 -0
  118. package/src/tools/search/types.ts +45 -1
  119. package/src/tools/subagent/SubagentExecutionRegistry.ts +1159 -0
  120. package/src/tools/subagent/SubagentExecutor.ts +1245 -563
  121. package/src/tools/subagent/SubagentReplay.ts +10 -1
  122. package/src/tools/subagent/__tests__/SubagentExecutionRegistry.test.ts +637 -0
  123. package/src/tools/subagent/__tests__/SubagentExecutor.lazy.test.ts +3054 -0
  124. package/src/tools/subagent/__tests__/childGraphConfig.test.ts +521 -0
  125. package/src/tools/subagent/childGraphConfig.ts +694 -0
  126. package/src/tools/subagent/index.ts +6 -0
  127. package/src/tools/subagent/runtimeLimits.ts +7 -0
  128. package/src/types/graph.ts +217 -19
@@ -1,9 +1,9 @@
1
1
  import { BaseMessage } from '@langchain/core/messages';
2
2
  import { Command } from '@langchain/langgraph';
3
3
  import type { MessageContentComplex } from '@langchain/core/messages';
4
+ import type { MultiAgentGraph } from '@/graphs/MultiAgentGraph';
5
+ import type { StandardGraph } from '@/graphs/Graph';
4
6
  import type * as t from '@/types';
5
- import { MultiAgentGraph } from '@/graphs/MultiAgentGraph';
6
- import { StandardGraph } from '@/graphs/Graph';
7
7
  export declare const defaultOmitOptions: Set<string>;
8
8
  export declare class Run<_T extends t.BaseGraphState> {
9
9
  id: string;
@@ -2,7 +2,7 @@ import type { JsonSchemaType, LCTool } from '@/types/tools';
2
2
  import type { SubagentConfig } from '@/types';
3
3
  import { Constants } from '@/common';
4
4
  export declare const SubagentToolName = Constants.SUBAGENT;
5
- export declare const SubagentToolDescription = "Delegate a task to a specialized subagent that runs in an isolated context window. The subagent executes independently and returns only its final text result \u2014 all intermediate tool calls, reasoning, and context stay isolated.\n\nWHEN TO USE:\n- The task is self-contained and can be described in a single prompt.\n- You want to offload verbose or exploratory work without bloating your own context.\n- A specialized subagent is available for the task domain.\n\nWHAT HAPPENS:\n- A fresh agent is created with the task description as its only input.\n- The subagent runs to completion using its own tools and context.\n- Only the final text response is returned to you.\n\nCONSTRAINTS:\n- subagent_type must match one of the available types listed below.\n- The subagent cannot see your conversation history.";
5
+ export declare const SubagentToolDescription = "Delegate a task to a specialized subagent or bounded agent team that runs in an isolated context window. The delegated execution returns only its designated final text result \u2014 all intermediate tool calls, reasoning, and context stay isolated.\n\nWHEN TO USE:\n- The task is self-contained and can be described in a single prompt.\n- You want to offload verbose or exploratory work without bloating your own context.\n- A specialized subagent is available for the task domain.\n\nWHAT HAPPENS:\n- A fresh agent or configured agent graph is created with the task description as its only input.\n- The delegated agent or team runs to completion using isolated tools and context.\n- Only the single agent's final response or the graph's designated result-agent response is returned to you.\n\nCONSTRAINTS:\n- subagent_type must match one of the available types listed below.\n- The subagent cannot see your conversation history.";
6
6
  export declare const SubagentToolSchema: {
7
7
  readonly type: "object";
8
8
  readonly properties: {
@@ -30,6 +30,31 @@ export declare class CohereReranker extends BaseReranker {
30
30
  } & t.HttpAgentConfig);
31
31
  rerank(query: string, documents: string[], topK?: number): Promise<t.Highlight[]>;
32
32
  }
33
+ /**
34
+ * Calls the public `danny-avila/rag_api` `/v1/rerank` endpoint (the
35
+ * `fast-v1` profile). Auth is supplied per call by a token supplier (a
36
+ * short-lived JWT minted by the host app) rather than a static key. A
37
+ * reranker failure must never throw into the search flow: on a missing
38
+ * base URL/token supplier, a timeout (covering token acquisition as well as
39
+ * the request), a non-2xx response, or any malformed payload, this falls back
40
+ * to the candidates' original order via {@link BaseReranker.getDefaultRanking}.
41
+ */
42
+ export declare class RagApiReranker extends BaseReranker {
43
+ private baseUrl?;
44
+ private tokenSupplier?;
45
+ private profile;
46
+ private timeout;
47
+ private httpAgent?;
48
+ private httpsAgent?;
49
+ constructor({ baseUrl, tokenSupplier, profile, timeout, logger, httpAgent, httpsAgent, }: {
50
+ baseUrl?: string;
51
+ tokenSupplier?: t.RagApiTokenSupplier;
52
+ profile?: string;
53
+ timeout?: number;
54
+ logger?: t.Logger;
55
+ } & t.HttpAgentConfig);
56
+ rerank(query: string, documents: string[], topK?: number): Promise<t.Highlight[]>;
57
+ }
33
58
  export declare class InfinityReranker extends BaseReranker {
34
59
  constructor(logger?: t.Logger);
35
60
  rerank(query: string, documents: string[], topK?: number): Promise<t.Highlight[]>;
@@ -42,6 +67,9 @@ export declare const createReranker: (config: {
42
67
  jinaApiKey?: string;
43
68
  jinaApiUrl?: string;
44
69
  cohereApiKey?: string;
70
+ ragApiUrl?: string;
71
+ ragApiTokenSupplier?: t.RagApiTokenSupplier;
72
+ ragApiProfile?: string;
45
73
  rerankerTimeout?: number;
46
74
  logger?: t.Logger;
47
75
  } & t.HttpAgentConfig) => BaseReranker | undefined;
@@ -18,7 +18,7 @@ export interface BaseSearchProviderConfig extends HttpAgentConfig {
18
18
  }
19
19
  export type SearchProvider = 'serper' | 'searxng' | 'tavily' | 'keenable' | 'crw';
20
20
  export type ScraperProvider = 'firecrawl' | 'serper' | 'tavily' | 'crw' | 'keenable';
21
- export type RerankerType = 'infinity' | 'jina' | 'cohere' | 'none';
21
+ export type RerankerType = 'infinity' | 'jina' | 'cohere' | 'rag-api' | 'none';
22
22
  export interface Highlight {
23
23
  score: number;
24
24
  text: string;
@@ -298,6 +298,34 @@ export interface CohereRerankerResponse {
298
298
  };
299
299
  };
300
300
  }
301
+ /** Mints a short-lived JWT per call; rag_api tokens are never cached or
302
+ * reused across requests by the reranker itself. Receives the rerank
303
+ * deadline's `AbortSignal` so a supplier minting its token over the network
304
+ * can cancel that request when the deadline fires instead of leaving it
305
+ * running past its caller. The argument is optional: zero-argument suppliers
306
+ * remain valid. */
307
+ export type RagApiTokenSupplier = (signal?: AbortSignal) => string | Promise<string>;
308
+ export interface RagApiRerankCandidate {
309
+ id: string;
310
+ text: string;
311
+ base_score: number;
312
+ }
313
+ export interface RagApiRerankRequestBody {
314
+ profile: string;
315
+ query: string;
316
+ candidates: RagApiRerankCandidate[];
317
+ top_n: number;
318
+ }
319
+ export interface RagApiRerankResult {
320
+ id: string;
321
+ index: number;
322
+ score: number;
323
+ }
324
+ export interface RagApiRerankResponse {
325
+ profile: string;
326
+ model: string;
327
+ results: RagApiRerankResult[];
328
+ }
301
329
  export type SafeSearchLevel = 0 | 1 | 2;
302
330
  export type Logger = WinstonLogger;
303
331
  export interface SearchToolConfig extends SearchConfig, ProcessSourcesConfig, FirecrawlConfig {
@@ -316,6 +344,15 @@ export interface SearchToolConfig extends SearchConfig, ProcessSourcesConfig, Fi
316
344
  jinaApiKey?: string;
317
345
  jinaApiUrl?: string;
318
346
  cohereApiKey?: string;
347
+ /** Base URL of the public `rag_api` service (`RAG_API_URL` env fallback).
348
+ * Requests post to `${ragApiUrl}/v1/rerank`. */
349
+ ragApiUrl?: string;
350
+ /** Resolves a short-lived rag_api JWT immediately before each rerank call.
351
+ * Required for the `'rag-api'` reranker type — without it, reranking falls
352
+ * back to default (unranked) ordering. */
353
+ ragApiTokenSupplier?: RagApiTokenSupplier;
354
+ /** rag_api rerank profile. Defaults to `'fast-v1'`. */
355
+ ragApiProfile?: string;
319
356
  rerankerType?: RerankerType;
320
357
  /** Timeout (ms) for rerank API requests. Defaults to 10,000. */
321
358
  rerankerTimeout?: number;
@@ -0,0 +1,171 @@
1
+ import type { RunnableConfig } from '@langchain/core/runnables';
2
+ import type { SubagentResumeExecution } from './SubagentReplay';
3
+ export type SubagentExecutionAddressInput = {
4
+ threadId?: string;
5
+ parentToolCallId: string;
6
+ parentConfigurable?: Record<string, unknown>;
7
+ };
8
+ export type SubagentExecutionAddress = Readonly<{
9
+ key: string;
10
+ baseChildThreadId: string;
11
+ branchChildThreadId: string;
12
+ currentChildRunId: string;
13
+ explicitResumeAttempt: boolean;
14
+ parentToolCallId: string;
15
+ resumeAttemptId: string;
16
+ }>;
17
+ export type SubagentExecutionIdentity = Readonly<{
18
+ childRunId: string;
19
+ childThreadId: string;
20
+ approvalExecutionScope: string;
21
+ }>;
22
+ export interface SubagentExecutionPreparationLease {
23
+ readonly ownsCheckpoint: boolean;
24
+ readonly ownsCreatedCheckpoint: boolean;
25
+ readonly ownsApprovalScope: boolean;
26
+ readonly ownsCreatedApprovalScope: boolean;
27
+ assertOwned(): void;
28
+ markCheckpointCreated(cleanup: () => Promise<void>): void;
29
+ markApprovalScopeCreated(cleanup: () => Promise<void>): void;
30
+ release(): void;
31
+ rollback(cause: unknown, cleanup?: (lease: SubagentExecutionPreparationLease) => Promise<void>): Promise<never>;
32
+ }
33
+ export type PreparedSubagentExecutionIdentity = Readonly<{
34
+ identity: SubagentExecutionIdentity;
35
+ lease: SubagentExecutionPreparationLease;
36
+ commit?: (lease: SubagentExecutionPreparationLease) => void;
37
+ rollback?: (lease: SubagentExecutionPreparationLease) => Promise<void>;
38
+ }>;
39
+ export type SubagentDefinitionBinding = Readonly<{
40
+ subagentType?: string;
41
+ configId?: string;
42
+ }>;
43
+ export type SubagentInvocationBinding = Readonly<{
44
+ description: string;
45
+ subagentType: string;
46
+ configId?: string;
47
+ }>;
48
+ export type SubagentSettlementBinding = Readonly<{
49
+ definitionAuthority: 'provisional' | 'effective';
50
+ fingerprint: string;
51
+ invocation: SubagentInvocationBinding;
52
+ subagentType?: string;
53
+ configId?: string;
54
+ }>;
55
+ export type SubagentExecutionPhase = 'registered' | 'active' | 'interrupted' | 'failed' | 'completed' | 'invalidated';
56
+ export interface ExecutionSnapshot<TResult, TResolvedConfig, TActiveRun> {
57
+ readonly address: SubagentExecutionAddress;
58
+ readonly phase: SubagentExecutionPhase;
59
+ readonly identity?: SubagentExecutionIdentity;
60
+ readonly binding?: SubagentDefinitionBinding;
61
+ readonly invocation?: SubagentInvocationBinding;
62
+ readonly settlement?: SubagentSettlementBinding;
63
+ readonly resumeExecution?: SubagentResumeExecution;
64
+ readonly activeRun?: TActiveRun;
65
+ readonly completedResult?: TResult;
66
+ readonly resolvedConfig?: TResolvedConfig;
67
+ readonly started: boolean;
68
+ readonly completed: boolean;
69
+ readonly resolvingIdentity: boolean;
70
+ readonly resolving: boolean;
71
+ readonly executing: boolean;
72
+ readonly settling: boolean;
73
+ readonly settled: boolean;
74
+ }
75
+ export type SubagentExecutionRegistryOptions = {
76
+ parentRunId: string;
77
+ parentAgentId?: string;
78
+ durable: boolean;
79
+ };
80
+ type ResumeSelection = {
81
+ parentToolCallIds?: ReadonlySet<string>;
82
+ config?: RunnableConfig;
83
+ };
84
+ export declare function getSubagentApprovalExecutionScope(childRunId: string, resumeAttemptId: string): string;
85
+ export declare class SubagentExecutionInvalidatedError extends Error {
86
+ constructor();
87
+ }
88
+ export declare class SubagentDefinitionBindingError extends Error {
89
+ constructor();
90
+ }
91
+ export declare class SubagentInvocationBindingError extends Error {
92
+ constructor();
93
+ }
94
+ export declare class SubagentSettlementBindingError extends Error {
95
+ constructor();
96
+ }
97
+ /** In-process source of truth for one Durable Subagent Execution. */
98
+ export declare class SubagentExecutionRecord<TResult, TResolvedConfig, TActiveRun, TSettledOutput = never> {
99
+ readonly address: SubagentExecutionAddress;
100
+ private identityValue?;
101
+ private bindingValue?;
102
+ private bindingAuthority?;
103
+ private invocationValue?;
104
+ private settlementValue?;
105
+ private settledOutputValue?;
106
+ private resumeExecutionValue?;
107
+ private activeRunValue?;
108
+ private completedResultValue?;
109
+ private resolvedConfigValue?;
110
+ private pendingIdentityResolution?;
111
+ private pendingConfigResolution?;
112
+ private pendingExecution?;
113
+ private pendingSettlement?;
114
+ private phaseValue;
115
+ private startedValue;
116
+ private completedValue;
117
+ private settledValue;
118
+ constructor(address: SubagentExecutionAddress, resumeExecution?: SubagentResumeExecution);
119
+ get snapshot(): ExecutionSnapshot<TResult, TResolvedConfig, TActiveRun>;
120
+ get identity(): SubagentExecutionIdentity | undefined;
121
+ get binding(): SubagentDefinitionBinding | undefined;
122
+ get resumeExecution(): SubagentResumeExecution | undefined;
123
+ get invocation(): SubagentInvocationBinding | undefined;
124
+ get activeRun(): TActiveRun | undefined;
125
+ get settlement(): SubagentSettlementBinding | undefined;
126
+ get settledOutput(): TSettledOutput | undefined;
127
+ get completedResult(): TResult | undefined;
128
+ get resolvedConfig(): TResolvedConfig | undefined;
129
+ get started(): boolean;
130
+ get completed(): boolean;
131
+ assertUsable(signal?: AbortSignal): void;
132
+ attachResumeExecution(resumeExecution?: SubagentResumeExecution): void;
133
+ bindIdentity(identity: SubagentExecutionIdentity): void;
134
+ resolveIdentity(resolve: () => Promise<PreparedSubagentExecutionIdentity>): Promise<SubagentExecutionIdentity>;
135
+ bindDefinition(binding: SubagentDefinitionBinding, authority: 'provisional' | 'effective'): void;
136
+ resolveConfig(resolve: () => Promise<TResolvedConfig>, signal: AbortSignal): Promise<TResolvedConfig>;
137
+ execute(invocation: SubagentInvocationBinding, execute: () => Promise<TResult>): Promise<TResult>;
138
+ settle(settlement: SubagentSettlementBinding, settledOutput: TSettledOutput, persist: () => Promise<void>): Promise<void>;
139
+ activate(activeRun: TActiveRun): TActiveRun;
140
+ markStarted(): void;
141
+ markInterrupted(): void;
142
+ markFailed(): void;
143
+ markCompleted(result: TResult): void;
144
+ releaseActiveRun(): TActiveRun | undefined;
145
+ releaseResolvedConfig(): void;
146
+ invalidate(): void;
147
+ private bindInvocation;
148
+ private assertCurrentIdentityResolution;
149
+ private transitionTo;
150
+ }
151
+ /** Owns canonical addressing, record selection, and invalidation. */
152
+ export declare class SubagentExecutionRegistry<TResult, TResolvedConfig, TActiveRun, TSettledOutput = never> {
153
+ private readonly options;
154
+ private readonly recordsByAddress;
155
+ private readonly checkpointThreadIds;
156
+ private readonly preparationResourceOwners;
157
+ private nextPreparationToken;
158
+ constructor(options: SubagentExecutionRegistryOptions);
159
+ open(input: SubagentExecutionAddressInput): SubagentExecutionRecord<TResult, TResolvedConfig, TActiveRun, TSettledOutput>;
160
+ remove(record: SubagentExecutionRecord<TResult, TResolvedConfig, TActiveRun, TSettledOutput>): void;
161
+ beginIdentityPreparation(record: SubagentExecutionRecord<TResult, TResolvedConfig, TActiveRun, TSettledOutput>, identity: SubagentExecutionIdentity): SubagentExecutionPreparationLease;
162
+ selectForResume(selection?: ResumeSelection): SubagentExecutionRecord<TResult, TResolvedConfig, TActiveRun, TSettledOutput>[];
163
+ rememberCheckpointThread(...threadIds: string[]): void;
164
+ getCheckpointThreadIds(getNestedThreadIds?: (activeRun: TActiveRun) => ReadonlyArray<string>): string[];
165
+ resetCheckpointThreadIds(): void;
166
+ retireResumeSources(current: SubagentExecutionRecord<TResult, TResolvedConfig, TActiveRun, TSettledOutput>, sourceThreadIds: ReadonlySet<string>, retire: (source: SubagentExecutionRecord<TResult, TResolvedConfig, TActiveRun, TSettledOutput>) => void): void;
167
+ clear(dispose?: (record: SubagentExecutionRecord<TResult, TResolvedConfig, TActiveRun, TSettledOutput>) => void): void;
168
+ private selectScopedRecords;
169
+ private createAddress;
170
+ }
171
+ export {};
@@ -1,16 +1,20 @@
1
1
  import { BaseMessage } from '@langchain/core/messages';
2
2
  import type { RunnableConfig } from '@langchain/core/runnables';
3
3
  import type { ToolCall } from '@langchain/core/messages/tool';
4
- import type { AgentInputs, HumanInTheLoopConfig, StandardGraphInput, ResolvedSubagentConfig, SubagentConfig, SubagentUsageSink, TokenCounter } from '@/types';
4
+ import type { MultiAgentGraphState, HumanInTheLoopConfig, StandardGraphInput, ExecutableSubagentConfigEntry, SubagentExecutionContext, SubagentUsageSink, TokenCounter } from '@/types';
5
5
  import type { SubagentResumeManifest, SettledSubagentToolOutput } from './SubagentReplay';
6
6
  import type { HookRegistry } from '@/hooks';
7
- import type { AgentContext } from '@/agents/AgentContext';
7
+ import type { GraphFactory } from '@/graphs/graphFactory';
8
8
  import type { StandardGraph } from '@/graphs/Graph';
9
9
  import type { HandlerRegistry } from '@/events';
10
+ export { buildChildInputs, isGraphSubagentConfig, normalizeSubagentConfigs, normalizeSubagentConfigEntries, resolveSubagentConfigs, resolveSubagentConfigEntries, } from './childGraphConfig';
11
+ export declare const DEFAULT_SUBAGENT_DESCRIPTION = "No task description provided";
10
12
  export type SubagentExecuteParams = {
11
13
  description: string;
12
14
  subagentType: string;
13
15
  threadId?: string;
16
+ /** Signal attached to this specific parent tool invocation. */
17
+ signal?: AbortSignal;
14
18
  /**
15
19
  * Breaker controller captured at the parent TOOL BATCH's entry, before
16
20
  * PreToolUse hooks. Preferred over the live scope accessor: a graph reset
@@ -72,7 +76,7 @@ export type SubagentExecuteResult = {
72
76
  */
73
77
  export type ChildGraphFactory = (input: StandardGraphInput) => StandardGraph;
74
78
  export type SubagentExecutorOptions = {
75
- configs: Map<string, ResolvedSubagentConfig>;
79
+ configs: ReadonlyMap<string, ExecutableSubagentConfigEntry>;
76
80
  parentSignal?: AbortSignal;
77
81
  /** Run-scoped breaker abort shared by every executor of one graph, so a
78
82
  * child tripping a stream limit stops subagents running under OTHER
@@ -88,6 +92,8 @@ export type SubagentExecutorOptions = {
88
92
  hookRegistry?: HookRegistry;
89
93
  parentRunId: string;
90
94
  parentAgentId?: string;
95
+ /** Root identity, policy session, and lineage inherited by a child graph. */
96
+ executionContext?: SubagentExecutionContext;
91
97
  langfuse?: StandardGraphInput['langfuse'];
92
98
  tokenCounter?: TokenCounter;
93
99
  /**
@@ -112,6 +118,9 @@ export type SubagentExecutorOptions = {
112
118
  * module dependency.
113
119
  */
114
120
  createChildGraph: ChildGraphFactory;
121
+ /** Preferred polymorphic child constructor. The legacy standard-only
122
+ * factory remains required for source compatibility. */
123
+ createChildGraphByKind?: GraphFactory;
115
124
  /**
116
125
  * Parent's event handler registry. When provided, child-graph events are
117
126
  * forwarded through this registry so hosts can:
@@ -149,6 +158,7 @@ export declare class SubagentExecutor {
149
158
  private readonly hookRegistry?;
150
159
  private readonly parentRunId;
151
160
  private readonly parentAgentId?;
161
+ private readonly executionContext;
152
162
  private readonly langfuse?;
153
163
  private readonly tokenCounter?;
154
164
  private readonly streamLimits?;
@@ -156,13 +166,9 @@ export declare class SubagentExecutor {
156
166
  private readonly checkpointer?;
157
167
  private readonly maxDepth;
158
168
  private readonly createChildGraph;
169
+ private readonly createChildGraphByKind?;
159
170
  private readonly usageSink?;
160
- private readonly checkpointThreadIds;
161
- private readonly startedChildRuns;
162
- private readonly completedChildRuns;
163
- private readonly completedChildResults;
164
- private readonly childExecutionIdentities;
165
- private readonly activeChildRuns;
171
+ private readonly executions;
166
172
  private replayCheckpointWorkflow?;
167
173
  private readonly resolveParentHandlerRegistry?;
168
174
  constructor(options: SubagentExecutorOptions);
@@ -175,6 +181,11 @@ export declare class SubagentExecutor {
175
181
  private composeChildSignal;
176
182
  /** Snapshot of the parent's registry at the moment a subagent is dispatched. */
177
183
  private getParentHandlerRegistry;
184
+ private bindExecutionDefinition;
185
+ /** Resolve one lazy descriptor per stable child execution. Concurrent
186
+ * duplicate dispatches share the same in-flight resolution; HITL re-entry
187
+ * on this executor reuses the resolved config until the child settles. */
188
+ private resolveExecutionConfig;
178
189
  /**
179
190
  * Keeps the original child thread as an immutable resume source once a
180
191
  * different parent Run reconstructs it. Each rebuilt parent gets a private
@@ -182,21 +193,27 @@ export declare class SubagentExecutor {
182
193
  * activity and usage correlation across the interrupt boundary.
183
194
  */
184
195
  private resolveChildExecutionIdentity;
196
+ private createChildExecutionIdentity;
197
+ private prepareIdentity;
198
+ private prepareCheckpointFork;
199
+ private checkpointThreadExists;
185
200
  /** Captures one exact checkpoint head per namespace for a child thread. */
186
201
  private getLatestCheckpointSnapshot;
187
202
  /** Copies exact checkpoint lineages, including pending task writes. */
188
203
  private forkCheckpointSnapshot;
189
204
  private createResumeManifest;
190
- getResumeManifest(parentToolCallIds?: ReadonlySet<string>): Promise<SubagentResumeManifest | undefined>;
205
+ getResumeManifest(parentToolCallIds?: ReadonlySet<string>, config?: RunnableConfig): Promise<SubagentResumeManifest | undefined>;
191
206
  getChildCheckpointThreadIds(): string[];
192
207
  resetCheckpointThreadIds(): void;
193
208
  private getGraphChildCheckpointThreadIds;
194
209
  private clearChildGraph;
195
210
  clearHeavyState(): void;
211
+ private getResumeCheckpointMarker;
196
212
  getSettledToolOutput(call: ToolCall, config: RunnableConfig): Promise<SettledSubagentToolOutput | undefined>;
197
213
  persistSettledToolOutput(call: ToolCall, config: RunnableConfig, settled: SettledSubagentToolOutput): Promise<void>;
198
214
  private persistChildCheckpointMarker;
199
215
  execute(params: SubagentExecuteParams): Promise<SubagentExecuteResult>;
216
+ private executeOnce;
200
217
  /**
201
218
  * Emits a single {@link GraphEvents.ON_SUBAGENT_UPDATE} envelope through the
202
219
  * parent's handler registry. Silent no-op when no parent registry is set.
@@ -224,6 +241,11 @@ export declare function sanitizeForwardedSubagentUpdateData(eventName: string, d
224
241
  * a compact status ticker without parsing the raw payload.
225
242
  */
226
243
  export declare function summarizeEvent(eventName: string, data: unknown): string;
244
+ /**
245
+ * Reads only the result member captured by MultiAgentGraph. Worker output is
246
+ * never used as a fallback when the designated result member is textless.
247
+ */
248
+ export declare function filterGraphSubagentResult(state: MultiAgentGraphState, resultAgentId: string): string;
227
249
  /**
228
250
  * Walk messages from last to first, returning the text content of the most
229
251
  * recent AIMessage that has any. Non-text blocks (tool_use, thinking,
@@ -238,30 +260,3 @@ export declare function summarizeEvent(eventName: string, data: unknown): string
238
260
  * any text.
239
261
  */
240
262
  export declare function filterSubagentResult(messages: BaseMessage[]): string;
241
- /**
242
- * Resolve self-spawn configs by filling in agentInputs from the parent context.
243
- * Returns configs with agentInputs guaranteed present. Throws on duplicate
244
- * `type` values to prevent silent config shadowing.
245
- */
246
- export declare function resolveSubagentConfigs(configs: SubagentConfig[], parentContext: AgentContext): ResolvedSubagentConfig[];
247
- /**
248
- * Build child AgentInputs from a resolved config, stripping nesting and
249
- * (optionally) event-driven fields. When `allowNested: true`, the child's
250
- * `maxSubagentDepth` is decremented so that depth is consumed as the call
251
- * chain deepens across graph boundaries — the parent's executor-level check
252
- * alone cannot see into the child graph's separate executor.
253
- *
254
- * When `keepToolDefinitions` is `true`, the child retains the parent's
255
- * `toolDefinitions` so event-driven tools remain usable. This is only safe
256
- * when the caller has wired a forwarder for `ON_TOOL_EXECUTE` to a
257
- * registered handler — otherwise the child will hang on tool dispatch.
258
- *
259
- * @remarks Advanced utility: exported primarily for testing and by
260
- * {@link SubagentExecutor}. Host applications configuring subagents should
261
- * not need to call this directly — it is invoked internally when a subagent
262
- * tool is dispatched. The depth-countdown contract (parent's `maxDepth` in,
263
- * child's decremented `maxSubagentDepth` on the returned inputs) is the
264
- * mechanism that bounds nesting across graph boundaries; callers must
265
- * respect it.
266
- */
267
- export declare function buildChildInputs(config: ResolvedSubagentConfig, childAgentId: string, parentMaxDepth: number, keepToolDefinitions?: boolean): AgentInputs;
@@ -49,6 +49,10 @@ export interface SubagentGraphResumeState {
49
49
  export interface SubagentResumeExecution {
50
50
  parentToolCallId: string;
51
51
  childRunId: string;
52
+ /** Effective child type bound when this execution first ran. */
53
+ subagentType?: string;
54
+ /** Lazy child revision bound when this execution first resolved. */
55
+ configId?: string;
52
56
  approvalExecutionScope: string;
53
57
  checkpoints: SubagentCheckpointReference[];
54
58
  graphState: SubagentGraphResumeState;
@@ -72,7 +76,7 @@ export type SettledSubagentToolOutput = {
72
76
  referenceContent?: string;
73
77
  };
74
78
  export interface SubagentReplayController {
75
- getResumeManifest?(parentToolCallIds?: ReadonlySet<string>): Promise<SubagentResumeManifest | undefined>;
79
+ getResumeManifest?(parentToolCallIds?: ReadonlySet<string>, config?: RunnableConfig): Promise<SubagentResumeManifest | undefined>;
76
80
  getSettledOutput(call: ToolCall, config: RunnableConfig): Promise<SettledSubagentToolOutput | undefined>;
77
81
  persistSettledOutput(call: ToolCall, config: RunnableConfig, settled: SettledSubagentToolOutput): Promise<void>;
78
82
  }
@@ -0,0 +1,37 @@
1
+ import type { AgentInputs, ExecutableSubagentConfig, ExecutableSubagentConfigEntry, GraphEdge, GraphSubagentConfig, ResolvedSubagentConfig, ResolvedSubagentConfigEntry, SubagentConfig, SubagentConfigEntry } from '@/types';
2
+ import type { AgentContext } from '@/agents/AgentContext';
3
+ type ChildGraphPlanBase = {
4
+ subjectAgentId: string;
5
+ checkpointNodeId: string;
6
+ agents: AgentInputs[];
7
+ memberInputs: ReadonlyMap<string, AgentInputs>;
8
+ };
9
+ export type ChildGraphPlan = (ChildGraphPlanBase & {
10
+ kind: 'agent';
11
+ }) | (ChildGraphPlanBase & {
12
+ kind: 'graph';
13
+ edges: GraphEdge[];
14
+ entryAgentId: string;
15
+ resultAgentId: string;
16
+ });
17
+ type CreateChildGraphPlanParams = {
18
+ config: ResolvedSubagentConfigEntry;
19
+ executionSuffix: string;
20
+ parentAgentId?: string;
21
+ parentMaxDepth: number;
22
+ keepToolDefinitions: boolean;
23
+ };
24
+ export declare function isGraphSubagentConfig(config: SubagentConfigEntry): config is GraphSubagentConfig;
25
+ export declare function validateGraphSubagentConfig(config: unknown): void;
26
+ /** Normalize eager, self, lazy, and graph subagent entries for advertisement. */
27
+ export declare function normalizeSubagentConfigEntries(configs: SubagentConfigEntry[], parentContext: AgentContext): ExecutableSubagentConfigEntry[];
28
+ /** Resolve self-spawn inputs and validate explicit graph configs. */
29
+ export declare function resolveSubagentConfigEntries(configs: SubagentConfigEntry[], parentContext: AgentContext): ResolvedSubagentConfigEntry[];
30
+ /** Resolve legacy single-agent configs with the original public signature. */
31
+ export declare function resolveSubagentConfigs(configs: SubagentConfig[], parentContext: AgentContext): ResolvedSubagentConfig[];
32
+ /** Normalize legacy single-agent configs while rejecting graph entries. */
33
+ export declare function normalizeSubagentConfigs(configs: SubagentConfig[], parentContext: AgentContext): ExecutableSubagentConfig[];
34
+ export declare function buildChildInputs(config: ResolvedSubagentConfig, childAgentId: string, parentMaxDepth: number, keepToolDefinitions?: boolean): AgentInputs;
35
+ export declare function buildGraphChildInputs(config: GraphSubagentConfig, parentMaxDepth: number, keepToolDefinitions?: boolean): AgentInputs[];
36
+ export declare function createChildGraphPlan({ config, executionSuffix, parentAgentId, parentMaxDepth, keepToolDefinitions, }: CreateChildGraphPlanParams): ChildGraphPlan;
37
+ export {};
@@ -1,2 +1,2 @@
1
- export { SubagentExecutor, filterSubagentResult, resolveSubagentConfigs, buildChildInputs, summarizeEvent, } from './SubagentExecutor';
1
+ export { DEFAULT_SUBAGENT_DESCRIPTION, SubagentExecutor, filterSubagentResult, filterGraphSubagentResult, isGraphSubagentConfig, normalizeSubagentConfigs, normalizeSubagentConfigEntries, resolveSubagentConfigs, resolveSubagentConfigEntries, buildChildInputs, summarizeEvent, } from './SubagentExecutor';
2
2
  export type { SubagentExecuteParams, SubagentExecuteResult, SubagentExecutorOptions, ChildGraphFactory, } from './SubagentExecutor';
@@ -0,0 +1,4 @@
1
+ export declare const DEFAULT_SUBAGENT_MAX_TURNS = 25;
2
+ export declare const SUBAGENT_RECURSION_MULTIPLIER = 3;
3
+ export declare const MAX_GRAPH_SUBAGENT_MEMBERS = 32;
4
+ export declare const MAX_GRAPH_SUBAGENT_TURNS: number;