@librechat/agents 3.1.1 → 3.1.21

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 (43) hide show
  1. package/dist/cjs/agents/AgentContext.cjs +9 -2
  2. package/dist/cjs/agents/AgentContext.cjs.map +1 -1
  3. package/dist/cjs/common/enum.cjs +2 -0
  4. package/dist/cjs/common/enum.cjs.map +1 -1
  5. package/dist/cjs/graphs/Graph.cjs +17 -0
  6. package/dist/cjs/graphs/Graph.cjs.map +1 -1
  7. package/dist/cjs/main.cjs +6 -0
  8. package/dist/cjs/main.cjs.map +1 -1
  9. package/dist/cjs/tools/ToolNode.cjs +66 -5
  10. package/dist/cjs/tools/ToolNode.cjs.map +1 -1
  11. package/dist/cjs/tools/createSchemaOnlyTool.cjs +31 -0
  12. package/dist/cjs/tools/createSchemaOnlyTool.cjs.map +1 -0
  13. package/dist/esm/agents/AgentContext.mjs +9 -2
  14. package/dist/esm/agents/AgentContext.mjs.map +1 -1
  15. package/dist/esm/common/enum.mjs +2 -0
  16. package/dist/esm/common/enum.mjs.map +1 -1
  17. package/dist/esm/graphs/Graph.mjs +17 -0
  18. package/dist/esm/graphs/Graph.mjs.map +1 -1
  19. package/dist/esm/main.mjs +2 -0
  20. package/dist/esm/main.mjs.map +1 -1
  21. package/dist/esm/tools/ToolNode.mjs +67 -6
  22. package/dist/esm/tools/ToolNode.mjs.map +1 -1
  23. package/dist/esm/tools/createSchemaOnlyTool.mjs +28 -0
  24. package/dist/esm/tools/createSchemaOnlyTool.mjs.map +1 -0
  25. package/dist/types/agents/AgentContext.d.ts +7 -1
  26. package/dist/types/common/enum.d.ts +2 -0
  27. package/dist/types/index.d.ts +2 -0
  28. package/dist/types/tools/ToolNode.d.ts +10 -1
  29. package/dist/types/tools/createSchemaOnlyTool.d.ts +12 -0
  30. package/dist/types/types/graph.d.ts +6 -0
  31. package/dist/types/types/tools.d.ts +49 -0
  32. package/package.json +1 -1
  33. package/src/agents/AgentContext.ts +10 -0
  34. package/src/common/enum.ts +2 -0
  35. package/src/graphs/Graph.ts +22 -0
  36. package/src/index.ts +2 -0
  37. package/src/specs/azure.simple.test.ts +214 -175
  38. package/src/tools/ToolNode.ts +95 -15
  39. package/src/tools/__tests__/ProgrammaticToolCalling.integration.test.ts +10 -9
  40. package/src/tools/__tests__/ToolSearch.integration.test.ts +10 -9
  41. package/src/tools/createSchemaOnlyTool.ts +37 -0
  42. package/src/types/graph.ts +6 -0
  43. package/src/types/tools.ts +52 -0
@@ -0,0 +1,37 @@
1
+ import { tool, type StructuredToolInterface } from '@langchain/core/tools';
2
+ import type { LCTool } from '@/types';
3
+
4
+ /**
5
+ * Creates a schema-only tool for LLM binding in event-driven mode.
6
+ * These tools have valid schemas for the LLM to understand but should
7
+ * never be invoked directly - ToolNode handles execution via events.
8
+ */
9
+ export function createSchemaOnlyTool(
10
+ definition: LCTool
11
+ ): StructuredToolInterface {
12
+ const { name, description, parameters, responseFormat } = definition;
13
+
14
+ return tool(
15
+ async () => {
16
+ throw new Error(
17
+ `Tool "${name}" should not be invoked directly in event-driven mode. ` +
18
+ 'ToolNode should dispatch ON_TOOL_EXECUTE events instead.'
19
+ );
20
+ },
21
+ {
22
+ name,
23
+ description: description ?? '',
24
+ schema: parameters ?? { type: 'object', properties: {} },
25
+ responseFormat: responseFormat ?? 'content_and_artifact',
26
+ }
27
+ );
28
+ }
29
+
30
+ /**
31
+ * Creates schema-only tools for all definitions in an array.
32
+ */
33
+ export function createSchemaOnlyTools(
34
+ definitions: LCTool[]
35
+ ): StructuredToolInterface[] {
36
+ return definitions.map((def) => createSchemaOnlyTool(def));
37
+ }
@@ -377,4 +377,10 @@ export interface AgentInputs {
377
377
  * Maps tool name to LCTool definition.
378
378
  */
379
379
  toolRegistry?: Map<string, LCTool>;
380
+ /**
381
+ * Serializable tool definitions for event-driven execution.
382
+ * When provided, ToolNode operates in event-driven mode, dispatching
383
+ * ON_TOOL_EXECUTE events instead of invoking tools directly.
384
+ */
385
+ toolDefinitions?: LCTool[];
380
386
  }
@@ -41,6 +41,10 @@ export type ToolNodeOptions = {
41
41
  toolRegistry?: LCToolRegistry;
42
42
  /** Reference to Graph's sessions map for automatic session injection */
43
43
  sessions?: ToolSessionMap;
44
+ /** When true, dispatches ON_TOOL_EXECUTE events instead of invoking tools directly */
45
+ eventDrivenMode?: boolean;
46
+ /** Tool definitions for event-driven mode (used for context, not invocation) */
47
+ toolDefinitions?: Map<string, LCTool>;
44
48
  };
45
49
 
46
50
  export type ToolNodeConstructorParams = ToolRefs & ToolNodeOptions;
@@ -125,6 +129,54 @@ export type LCTool = {
125
129
  * Options: 'direct', 'code_execution'
126
130
  */
127
131
  allowed_callers?: AllowedCaller[];
132
+ /** Response format for the tool output */
133
+ responseFormat?: 'content' | 'content_and_artifact';
134
+ /** Server name for MCP tools */
135
+ serverName?: string;
136
+ /** Tool type classification */
137
+ toolType?: 'builtin' | 'mcp' | 'action';
138
+ };
139
+
140
+ /** Single tool call within a batch request for event-driven execution */
141
+ export type ToolCallRequest = {
142
+ /** Tool call ID from the LLM */
143
+ id: string;
144
+ /** Tool name */
145
+ name: string;
146
+ /** Tool arguments */
147
+ args: Record<string, unknown>;
148
+ /** Step ID for tracking */
149
+ stepId?: string;
150
+ /** Usage turn count for this tool */
151
+ turn?: number;
152
+ };
153
+
154
+ /** Batch request containing ALL tool calls for a graph step */
155
+ export type ToolExecuteBatchRequest = {
156
+ /** All tool calls from the AIMessage */
157
+ toolCalls: ToolCallRequest[];
158
+ /** User ID for context */
159
+ userId?: string;
160
+ /** Agent ID for context */
161
+ agentId?: string;
162
+ /** Promise resolver - handler calls this with ALL results */
163
+ resolve: (results: ToolExecuteResult[]) => void;
164
+ /** Promise rejector - handler calls this on fatal error */
165
+ reject: (error: Error) => void;
166
+ };
167
+
168
+ /** Result for a single tool call in event-driven execution */
169
+ export type ToolExecuteResult = {
170
+ /** Matches ToolCallRequest.id */
171
+ toolCallId: string;
172
+ /** Tool output content */
173
+ content: string | unknown[];
174
+ /** Optional artifact (for content_and_artifact format) */
175
+ artifact?: unknown;
176
+ /** Execution status */
177
+ status: 'success' | 'error';
178
+ /** Error message if status is 'error' */
179
+ errorMessage?: string;
128
180
  };
129
181
 
130
182
  /** Map of tool names to tool definitions */