@librechat/agents 3.1.66 → 3.1.67-dev.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.
Files changed (149) hide show
  1. package/dist/cjs/agents/AgentContext.cjs +23 -3
  2. package/dist/cjs/agents/AgentContext.cjs.map +1 -1
  3. package/dist/cjs/common/enum.cjs +16 -0
  4. package/dist/cjs/common/enum.cjs.map +1 -1
  5. package/dist/cjs/graphs/Graph.cjs +91 -0
  6. package/dist/cjs/graphs/Graph.cjs.map +1 -1
  7. package/dist/cjs/hooks/HookRegistry.cjs +162 -0
  8. package/dist/cjs/hooks/HookRegistry.cjs.map +1 -0
  9. package/dist/cjs/hooks/executeHooks.cjs +276 -0
  10. package/dist/cjs/hooks/executeHooks.cjs.map +1 -0
  11. package/dist/cjs/hooks/matchers.cjs +256 -0
  12. package/dist/cjs/hooks/matchers.cjs.map +1 -0
  13. package/dist/cjs/hooks/types.cjs +27 -0
  14. package/dist/cjs/hooks/types.cjs.map +1 -0
  15. package/dist/cjs/main.cjs +53 -0
  16. package/dist/cjs/main.cjs.map +1 -1
  17. package/dist/cjs/messages/format.cjs +74 -12
  18. package/dist/cjs/messages/format.cjs.map +1 -1
  19. package/dist/cjs/run.cjs +111 -0
  20. package/dist/cjs/run.cjs.map +1 -1
  21. package/dist/cjs/summarization/node.cjs +44 -0
  22. package/dist/cjs/summarization/node.cjs.map +1 -1
  23. package/dist/cjs/tools/BashExecutor.cjs +175 -0
  24. package/dist/cjs/tools/BashExecutor.cjs.map +1 -0
  25. package/dist/cjs/tools/BashProgrammaticToolCalling.cjs +296 -0
  26. package/dist/cjs/tools/BashProgrammaticToolCalling.cjs.map +1 -0
  27. package/dist/cjs/tools/ReadFile.cjs +43 -0
  28. package/dist/cjs/tools/ReadFile.cjs.map +1 -0
  29. package/dist/cjs/tools/SkillTool.cjs +50 -0
  30. package/dist/cjs/tools/SkillTool.cjs.map +1 -0
  31. package/dist/cjs/tools/SubagentTool.cjs +92 -0
  32. package/dist/cjs/tools/SubagentTool.cjs.map +1 -0
  33. package/dist/cjs/tools/ToolNode.cjs +304 -140
  34. package/dist/cjs/tools/ToolNode.cjs.map +1 -1
  35. package/dist/cjs/tools/skillCatalog.cjs +84 -0
  36. package/dist/cjs/tools/skillCatalog.cjs.map +1 -0
  37. package/dist/cjs/tools/subagent/SubagentExecutor.cjs +511 -0
  38. package/dist/cjs/tools/subagent/SubagentExecutor.cjs.map +1 -0
  39. package/dist/esm/agents/AgentContext.mjs +23 -3
  40. package/dist/esm/agents/AgentContext.mjs.map +1 -1
  41. package/dist/esm/common/enum.mjs +15 -1
  42. package/dist/esm/common/enum.mjs.map +1 -1
  43. package/dist/esm/graphs/Graph.mjs +91 -0
  44. package/dist/esm/graphs/Graph.mjs.map +1 -1
  45. package/dist/esm/hooks/HookRegistry.mjs +160 -0
  46. package/dist/esm/hooks/HookRegistry.mjs.map +1 -0
  47. package/dist/esm/hooks/executeHooks.mjs +273 -0
  48. package/dist/esm/hooks/executeHooks.mjs.map +1 -0
  49. package/dist/esm/hooks/matchers.mjs +251 -0
  50. package/dist/esm/hooks/matchers.mjs.map +1 -0
  51. package/dist/esm/hooks/types.mjs +25 -0
  52. package/dist/esm/hooks/types.mjs.map +1 -0
  53. package/dist/esm/main.mjs +12 -1
  54. package/dist/esm/main.mjs.map +1 -1
  55. package/dist/esm/messages/format.mjs +66 -4
  56. package/dist/esm/messages/format.mjs.map +1 -1
  57. package/dist/esm/run.mjs +111 -0
  58. package/dist/esm/run.mjs.map +1 -1
  59. package/dist/esm/summarization/node.mjs +44 -0
  60. package/dist/esm/summarization/node.mjs.map +1 -1
  61. package/dist/esm/tools/BashExecutor.mjs +169 -0
  62. package/dist/esm/tools/BashExecutor.mjs.map +1 -0
  63. package/dist/esm/tools/BashProgrammaticToolCalling.mjs +287 -0
  64. package/dist/esm/tools/BashProgrammaticToolCalling.mjs.map +1 -0
  65. package/dist/esm/tools/ReadFile.mjs +38 -0
  66. package/dist/esm/tools/ReadFile.mjs.map +1 -0
  67. package/dist/esm/tools/SkillTool.mjs +45 -0
  68. package/dist/esm/tools/SkillTool.mjs.map +1 -0
  69. package/dist/esm/tools/SubagentTool.mjs +85 -0
  70. package/dist/esm/tools/SubagentTool.mjs.map +1 -0
  71. package/dist/esm/tools/ToolNode.mjs +306 -142
  72. package/dist/esm/tools/ToolNode.mjs.map +1 -1
  73. package/dist/esm/tools/skillCatalog.mjs +82 -0
  74. package/dist/esm/tools/skillCatalog.mjs.map +1 -0
  75. package/dist/esm/tools/subagent/SubagentExecutor.mjs +505 -0
  76. package/dist/esm/tools/subagent/SubagentExecutor.mjs.map +1 -0
  77. package/dist/types/agents/AgentContext.d.ts +6 -0
  78. package/dist/types/common/enum.d.ts +10 -1
  79. package/dist/types/graphs/Graph.d.ts +2 -0
  80. package/dist/types/hooks/HookRegistry.d.ts +56 -0
  81. package/dist/types/hooks/executeHooks.d.ts +79 -0
  82. package/dist/types/hooks/index.d.ts +6 -0
  83. package/dist/types/hooks/matchers.d.ts +95 -0
  84. package/dist/types/hooks/types.d.ts +320 -0
  85. package/dist/types/index.d.ts +8 -0
  86. package/dist/types/messages/format.d.ts +2 -1
  87. package/dist/types/run.d.ts +1 -0
  88. package/dist/types/summarization/node.d.ts +2 -0
  89. package/dist/types/tools/BashExecutor.d.ts +45 -0
  90. package/dist/types/tools/BashProgrammaticToolCalling.d.ts +72 -0
  91. package/dist/types/tools/ReadFile.d.ts +28 -0
  92. package/dist/types/tools/SkillTool.d.ts +40 -0
  93. package/dist/types/tools/SubagentTool.d.ts +36 -0
  94. package/dist/types/tools/ToolNode.d.ts +24 -2
  95. package/dist/types/tools/skillCatalog.d.ts +19 -0
  96. package/dist/types/tools/subagent/SubagentExecutor.d.ts +137 -0
  97. package/dist/types/tools/subagent/index.d.ts +2 -0
  98. package/dist/types/types/graph.d.ts +61 -2
  99. package/dist/types/types/index.d.ts +1 -0
  100. package/dist/types/types/llm.d.ts +14 -2
  101. package/dist/types/types/run.d.ts +20 -0
  102. package/dist/types/types/skill.d.ts +9 -0
  103. package/dist/types/types/tools.d.ts +38 -1
  104. package/package.json +5 -1
  105. package/src/agents/AgentContext.ts +26 -2
  106. package/src/common/enum.ts +15 -0
  107. package/src/graphs/Graph.ts +113 -0
  108. package/src/hooks/HookRegistry.ts +208 -0
  109. package/src/hooks/__tests__/HookRegistry.test.ts +190 -0
  110. package/src/hooks/__tests__/compactHooks.test.ts +214 -0
  111. package/src/hooks/__tests__/executeHooks.test.ts +1013 -0
  112. package/src/hooks/__tests__/integration.test.ts +337 -0
  113. package/src/hooks/__tests__/matchers.test.ts +238 -0
  114. package/src/hooks/__tests__/toolHooks.test.ts +669 -0
  115. package/src/hooks/executeHooks.ts +375 -0
  116. package/src/hooks/index.ts +57 -0
  117. package/src/hooks/matchers.ts +280 -0
  118. package/src/hooks/types.ts +404 -0
  119. package/src/index.ts +10 -0
  120. package/src/messages/format.ts +74 -4
  121. package/src/messages/formatAgentMessages.skills.test.ts +334 -0
  122. package/src/run.ts +126 -0
  123. package/src/scripts/multi-agent-subagent.ts +246 -0
  124. package/src/scripts/subagent-event-driven-debug.ts +190 -0
  125. package/src/scripts/subagent-tools-debug.ts +160 -0
  126. package/src/specs/subagent.test.ts +305 -0
  127. package/src/summarization/node.ts +53 -0
  128. package/src/tools/BashExecutor.ts +205 -0
  129. package/src/tools/BashProgrammaticToolCalling.ts +397 -0
  130. package/src/tools/ReadFile.ts +39 -0
  131. package/src/tools/SkillTool.ts +46 -0
  132. package/src/tools/SubagentTool.ts +100 -0
  133. package/src/tools/ToolNode.ts +391 -169
  134. package/src/tools/__tests__/ReadFile.test.ts +44 -0
  135. package/src/tools/__tests__/SkillTool.test.ts +442 -0
  136. package/src/tools/__tests__/SubagentExecutor.test.ts +1148 -0
  137. package/src/tools/__tests__/SubagentTool.test.ts +149 -0
  138. package/src/tools/__tests__/ToolNode.session.test.ts +12 -12
  139. package/src/tools/__tests__/skillCatalog.test.ts +161 -0
  140. package/src/tools/__tests__/subagentHooks.test.ts +215 -0
  141. package/src/tools/skillCatalog.ts +126 -0
  142. package/src/tools/subagent/SubagentExecutor.ts +676 -0
  143. package/src/tools/subagent/index.ts +13 -0
  144. package/src/types/graph.ts +80 -1
  145. package/src/types/index.ts +1 -0
  146. package/src/types/llm.ts +16 -2
  147. package/src/types/run.ts +20 -0
  148. package/src/types/skill.ts +11 -0
  149. package/src/types/tools.ts +41 -1
@@ -18,7 +18,13 @@ import type {
18
18
  import type { RunnableConfig, Runnable } from '@langchain/core/runnables';
19
19
  import type { ChatGenerationChunk } from '@langchain/core/outputs';
20
20
  import type { GoogleAIToolType } from '@langchain/google-common';
21
- import type { ToolMap, ToolEndEvent, GenericTool, LCTool } from '@/types/tools';
21
+ import type {
22
+ ToolMap,
23
+ ToolEndEvent,
24
+ GenericTool,
25
+ LCTool,
26
+ ToolExecuteBatchRequest,
27
+ } from '@/types/tools';
22
28
  import type { Providers, Callback, GraphNodeKeys } from '@/common';
23
29
  import type { StandardGraph, MultiAgentGraph } from '@/graphs';
24
30
  import type { ClientOptions } from '@/types/llm';
@@ -105,7 +111,9 @@ export interface EventHandler {
105
111
  | SummarizeStartEvent
106
112
  | SummarizeDeltaEvent
107
113
  | SummarizeCompleteEvent
114
+ | SubagentUpdateEvent
108
115
  | AgentLogEvent
116
+ | ToolExecuteBatchRequest
109
117
  | { result: ToolEndEvent },
110
118
  metadata?: Record<string, unknown>,
111
119
  graph?: StandardGraph | MultiAgentGraph
@@ -388,6 +396,73 @@ export type MultiAgentGraphInput = StandardGraphInput & {
388
396
  edges: GraphEdge[];
389
397
  };
390
398
 
399
+ /** Configuration for a subagent type that can be spawned by a parent agent. */
400
+ export type SubagentConfig = {
401
+ /** Identifier used in the tool's `subagent_type` enum (e.g. 'researcher', 'coder'). */
402
+ type: string;
403
+ /** Human-readable display name. */
404
+ name: string;
405
+ /** What this subagent specializes in — shown to the LLM. */
406
+ description: string;
407
+ /** Full agent config for the child graph. Omit when `self` is true. */
408
+ agentInputs?: AgentInputs;
409
+ /** When true, reuse the parent's AgentInputs (context isolation without separate config). */
410
+ self?: boolean;
411
+ /** Max AGENT→TOOLS cycles before forced stop (default: 25). */
412
+ maxTurns?: number;
413
+ /** Allow this subagent to spawn its own subagents (default: false). */
414
+ allowNested?: boolean;
415
+ };
416
+
417
+ /** SubagentConfig with agentInputs guaranteed present (self-spawn resolved). */
418
+ export type ResolvedSubagentConfig = SubagentConfig & {
419
+ agentInputs: AgentInputs;
420
+ };
421
+
422
+ /** Lifecycle phase carried on {@link SubagentUpdateEvent}. */
423
+ export type SubagentUpdatePhase =
424
+ | 'start'
425
+ | 'run_step'
426
+ | 'run_step_delta'
427
+ | 'run_step_completed'
428
+ | 'message_delta'
429
+ | 'reasoning_delta'
430
+ | 'stop'
431
+ | 'error';
432
+
433
+ /**
434
+ * Wrapper event emitted when a subagent's child graph dispatches activity.
435
+ * Lets hosts show subagent progress in a UI surface separate from the parent
436
+ * conversation without having to untangle events by agent ID.
437
+ */
438
+ export interface SubagentUpdateEvent {
439
+ /** Parent run ID. */
440
+ runId: string;
441
+ /** Child run ID (unique per subagent execution). */
442
+ subagentRunId: string;
443
+ /**
444
+ * Parent-side `tool_call_id` for the `subagent` tool invocation that
445
+ * triggered this run. Stable for the duration of the child; lets hosts
446
+ * correlate updates deterministically instead of inferring by ordering.
447
+ * Omitted when the executor was invoked outside of a tool-call context.
448
+ */
449
+ parentToolCallId?: string;
450
+ /** Subagent `type` identifier from the SubagentConfig. */
451
+ subagentType: string;
452
+ /** Child agent ID assigned to this subagent execution. */
453
+ subagentAgentId: string;
454
+ /** Parent agent ID that spawned this subagent. */
455
+ parentAgentId?: string;
456
+ /** Lifecycle phase carried by this update. */
457
+ phase: SubagentUpdatePhase;
458
+ /** Underlying event payload (shape depends on phase). */
459
+ data?: unknown;
460
+ /** Short human-readable description. Hosts can render this directly. */
461
+ label?: string;
462
+ /** ISO timestamp for ordering / display. */
463
+ timestamp: string;
464
+ }
465
+
391
466
  export interface AgentInputs {
392
467
  agentId: string;
393
468
  /** Human-readable name for the agent (used in handoff context). Defaults to agentId if not provided. */
@@ -431,6 +506,10 @@ export interface AgentInputs {
431
506
  maxToolResultChars?: number;
432
507
  /** Pre-computed tool schema token count (from cache). Skips recalculation when provided. */
433
508
  toolSchemaTokens?: number;
509
+ /** Subagent configurations for hierarchical delegation. Each defines a child agent type. */
510
+ subagentConfigs?: SubagentConfig[];
511
+ /** Maximum subagent nesting depth. Default 1 means top-level agents can spawn subagents but subagents cannot nest further. */
512
+ maxSubagentDepth?: number;
434
513
  }
435
514
 
436
515
  export interface ContextPruningConfig {
@@ -2,6 +2,7 @@
2
2
  export * from './graph';
3
3
  export * from './llm';
4
4
  export * from './run';
5
+ export * from './skill';
5
6
  export * from './stream';
6
7
  export * from './tools';
7
8
  export * from './summarize';
package/src/types/llm.ts CHANGED
@@ -45,7 +45,20 @@ export type AzureClientOptions = Partial<OpenAIChatInput> &
45
45
  } & BaseChatModelParams & {
46
46
  configuration?: OAIClientOptions;
47
47
  };
48
- export type ThinkingConfig = AnthropicInput['thinking'];
48
+ /**
49
+ * Controls whether Claude's reasoning content is returned in adaptive
50
+ * thinking responses. Added for Claude Opus 4.7, which omits thinking by
51
+ * default unless the caller opts in with `'summarized'`.
52
+ * @see https://platform.claude.com/docs/en/about-claude/models/whats-new-claude-4-7#thinking-content-omitted-by-default
53
+ */
54
+ export type ThinkingDisplay = 'summarized' | 'omitted';
55
+ export type ThinkingConfigAdaptive = {
56
+ type: 'adaptive';
57
+ display?: ThinkingDisplay;
58
+ };
59
+ export type ThinkingConfig =
60
+ | NonNullable<AnthropicInput['thinking']>
61
+ | ThinkingConfigAdaptive;
49
62
  export type ChatOpenAIToolType =
50
63
  | BindToolsInput
51
64
  | OpenAIClient.ChatCompletionTool;
@@ -60,7 +73,8 @@ export type GoogleThinkingConfig = {
60
73
  thinkingLevel?: string;
61
74
  };
62
75
  export type OpenAIClientOptions = ChatOpenAIFields;
63
- export type AnthropicClientOptions = AnthropicInput & {
76
+ export type AnthropicClientOptions = Omit<AnthropicInput, 'thinking'> & {
77
+ thinking?: ThinkingConfig;
64
78
  promptCache?: boolean;
65
79
  };
66
80
  export type MistralAIClientOptions = ChatMistralAIInput;
package/src/types/run.ts CHANGED
@@ -11,6 +11,8 @@ import type * as s from '@/types/stream';
11
11
  import type * as e from '@/common/enum';
12
12
  import type * as g from '@/types/graph';
13
13
  import type * as l from '@/types/llm';
14
+ import type { ToolSessionMap } from '@/types/tools';
15
+ import type { HookRegistry } from '@/hooks';
14
16
 
15
17
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
16
18
  export type ZodObjectAny = z.ZodObject<any, any, any, any>;
@@ -112,6 +114,18 @@ export type RunConfig = {
112
114
  runId: string;
113
115
  graphConfig: LegacyGraphConfig | StandardGraphConfig | MultiAgentGraphConfig;
114
116
  customHandlers?: Record<string, g.EventHandler>;
117
+ /**
118
+ * Pre-constructed hook registry for this run. Hooks fire at lifecycle
119
+ * points in `processStream` (RunStart, UserPromptSubmit, Stop,
120
+ * StopFailure) and around tool calls (PreToolUse, PostToolUse,
121
+ * PostToolUseFailure, PermissionDenied).
122
+ *
123
+ * Pass `undefined` (the default) to skip all hook dispatch. When a
124
+ * registry is provided, the run attaches it to the `Graph` so internal
125
+ * nodes can fire hooks too, and clears the session in the `finally`
126
+ * block to prevent leaks.
127
+ */
128
+ hooks?: HookRegistry;
115
129
  returnContent?: boolean;
116
130
  tokenCounter?: TokenCounter;
117
131
  indexTokenCountMap?: Record<string, number>;
@@ -126,6 +140,12 @@ export type RunConfig = {
126
140
  calibrationRatio?: number;
127
141
  /** Skip post-stream cleanup (clearHeavyState) — useful for tests that inspect graph state after processStream */
128
142
  skipCleanup?: boolean;
143
+ /**
144
+ * Initial session state to seed the Graph's ToolSessionMap.
145
+ * Used to carry over code environment sessions from skill file priming
146
+ * at run start, so ToolNode can inject session_id + files into tool calls.
147
+ */
148
+ initialSessions?: ToolSessionMap;
129
149
  };
130
150
 
131
151
  export type ProvidedCallbacks =
@@ -0,0 +1,11 @@
1
+ // src/types/skill.ts
2
+
3
+ /** Minimal skill metadata for catalog assembly. The host provides these from its own data layer. */
4
+ export type SkillCatalogEntry = {
5
+ /** Kebab-case identifier (what the model passes to SkillTool) */
6
+ name: string;
7
+ /** One-line description for the catalog listing */
8
+ description: string;
9
+ /** Optional human-readable label (UI only, not shown to model) */
10
+ displayTitle?: string;
11
+ };
@@ -2,7 +2,8 @@
2
2
  import type { StructuredToolInterface } from '@langchain/core/tools';
3
3
  import type { RunnableToolLike } from '@langchain/core/runnables';
4
4
  import type { ToolCall } from '@langchain/core/messages/tool';
5
- import type { ToolErrorData } from './stream';
5
+ import type { HookRegistry } from '@/hooks';
6
+ import type { MessageContentComplex, ToolErrorData } from './stream';
6
7
  import { EnvVar } from '@/common';
7
8
 
8
9
  /** Replacement type for `import type { ToolCall } from '@langchain/core/messages/tool'` in order to have stringified args typed */
@@ -49,6 +50,12 @@ export type ToolNodeOptions = {
49
50
  agentId?: string;
50
51
  /** Tool names that must be executed directly (via runTool) even in event-driven mode (e.g., graph-managed handoff tools) */
51
52
  directToolNames?: Set<string>;
53
+ /**
54
+ * Hook registry for PreToolUse/PostToolUse lifecycle hooks.
55
+ * Only fires for event-driven tool calls (`dispatchToolEvents`). Tools
56
+ * routed through `directToolNames` bypass hook dispatch entirely.
57
+ */
58
+ hookRegistry?: HookRegistry;
52
59
  /** Max context tokens for the agent — used to compute tool result truncation limits. */
53
60
  maxContextTokens?: number;
54
61
  /**
@@ -186,6 +193,26 @@ export type ToolExecuteBatchRequest = {
186
193
  reject: (error: Error) => void;
187
194
  };
188
195
 
196
+ /**
197
+ * A message injected into graph state by any tool execution handler.
198
+ * Generic mechanism: any tool returning `injectedMessages` in its `ToolExecuteResult`
199
+ * will have these appended to state after the ToolMessage for this call.
200
+ */
201
+ export type InjectedMessage = {
202
+ /** 'user' for skill body injection, 'system' for context hints.
203
+ * Both are converted to HumanMessage at runtime; the original role
204
+ * is preserved in additional_kwargs.role. */
205
+ role: 'user' | 'system';
206
+ /** Message content: string for simple text, array for complex multi-part content */
207
+ content: string | MessageContentComplex[];
208
+ /** When true, the message is framework-internal: not shown in UI, not counted as a user turn */
209
+ isMeta?: boolean;
210
+ /** Origin tag for downstream consumers (UI, pruner, compaction) */
211
+ source?: 'skill' | 'hook' | 'system';
212
+ /** Only set when source is 'skill', for compaction preservation */
213
+ skillName?: string;
214
+ };
215
+
189
216
  /** Result for a single tool call in event-driven execution */
190
217
  export type ToolExecuteResult = {
191
218
  /** Matches ToolCallRequest.id */
@@ -198,6 +225,13 @@ export type ToolExecuteResult = {
198
225
  status: 'success' | 'error';
199
226
  /** Error message if status is 'error' */
200
227
  errorMessage?: string;
228
+ /**
229
+ * Messages to inject into graph state after the ToolMessage for this call.
230
+ * Placed after tool results to respect provider message ordering (tool_call -> tool_result adjacency).
231
+ * The host's message formatter may merge injected user messages with the preceding tool_result turn.
232
+ * Generic mechanism: any tool execution handler can use this.
233
+ */
234
+ injectedMessages?: InjectedMessage[];
201
235
  };
202
236
 
203
237
  /** Map of tool names to tool definitions */
@@ -318,6 +352,12 @@ export type ProgrammaticExecutionArtifact = {
318
352
  files?: FileRefs;
319
353
  };
320
354
 
355
+ /** Parameters for creating a bash execution tool (same API as CodeExecutor, bash-only) */
356
+ export type BashExecutionToolParams = CodeExecutionToolParams;
357
+
358
+ /** Parameters for creating a bash programmatic tool calling tool (same API as PTC, bash-only) */
359
+ export type BashProgrammaticToolCallingParams = ProgrammaticToolCallingParams;
360
+
321
361
  /**
322
362
  * Initialization parameters for the PTC tool
323
363
  */