@librechat/agents 3.1.22 → 3.1.23
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 +1 -0
- package/dist/cjs/graphs/Graph.cjs.map +1 -1
- package/dist/cjs/tools/ToolNode.cjs +45 -12
- package/dist/cjs/tools/ToolNode.cjs.map +1 -1
- package/dist/esm/graphs/Graph.mjs +1 -0
- package/dist/esm/graphs/Graph.mjs.map +1 -1
- package/dist/esm/tools/ToolNode.mjs +45 -12
- package/dist/esm/tools/ToolNode.mjs.map +1 -1
- package/dist/types/tools/ToolNode.d.ts +3 -1
- package/dist/types/types/tools.d.ts +6 -0
- package/package.json +1 -1
- package/src/graphs/Graph.ts +1 -0
- package/src/tools/ToolNode.ts +55 -13
- package/src/types/tools.ts +6 -0
package/src/tools/ToolNode.ts
CHANGED
|
@@ -49,6 +49,8 @@ export class ToolNode<T = any> extends RunnableCallable<T, T> {
|
|
|
49
49
|
private eventDrivenMode: boolean = false;
|
|
50
50
|
/** Tool definitions for event-driven mode */
|
|
51
51
|
private toolDefinitions?: Map<string, t.LCTool>;
|
|
52
|
+
/** Agent ID for event-driven mode */
|
|
53
|
+
private agentId?: string;
|
|
52
54
|
|
|
53
55
|
constructor({
|
|
54
56
|
tools,
|
|
@@ -63,6 +65,7 @@ export class ToolNode<T = any> extends RunnableCallable<T, T> {
|
|
|
63
65
|
sessions,
|
|
64
66
|
eventDrivenMode,
|
|
65
67
|
toolDefinitions,
|
|
68
|
+
agentId,
|
|
66
69
|
}: t.ToolNodeConstructorParams) {
|
|
67
70
|
super({ name, tags, func: (input, config) => this.run(input, config) });
|
|
68
71
|
this.toolMap = toolMap ?? new Map(tools.map((tool) => [tool.name, tool]));
|
|
@@ -75,6 +78,7 @@ export class ToolNode<T = any> extends RunnableCallable<T, T> {
|
|
|
75
78
|
this.sessions = sessions;
|
|
76
79
|
this.eventDrivenMode = eventDrivenMode ?? false;
|
|
77
80
|
this.toolDefinitions = toolDefinitions;
|
|
81
|
+
this.agentId = agentId;
|
|
78
82
|
}
|
|
79
83
|
|
|
80
84
|
/**
|
|
@@ -279,7 +283,11 @@ export class ToolNode<T = any> extends RunnableCallable<T, T> {
|
|
|
279
283
|
const request: t.ToolExecuteBatchRequest = {
|
|
280
284
|
toolCalls: requests,
|
|
281
285
|
userId: config.configurable?.user_id as string | undefined,
|
|
282
|
-
agentId:
|
|
286
|
+
agentId: this.agentId,
|
|
287
|
+
configurable: config.configurable as
|
|
288
|
+
| Record<string, unknown>
|
|
289
|
+
| undefined,
|
|
290
|
+
metadata: config.metadata as Record<string, unknown> | undefined,
|
|
283
291
|
resolve,
|
|
284
292
|
reject,
|
|
285
293
|
};
|
|
@@ -289,27 +297,61 @@ export class ToolNode<T = any> extends RunnableCallable<T, T> {
|
|
|
289
297
|
);
|
|
290
298
|
|
|
291
299
|
const outputs: ToolMessage[] = results.map((result) => {
|
|
292
|
-
const
|
|
293
|
-
|
|
300
|
+
const request = requests.find((r) => r.id === result.toolCallId);
|
|
301
|
+
const toolName = request?.name ?? 'unknown';
|
|
302
|
+
const stepId = this.toolCallStepIds?.get(result.toolCallId) ?? '';
|
|
303
|
+
|
|
304
|
+
let toolMessage: ToolMessage;
|
|
305
|
+
let contentString: string;
|
|
294
306
|
|
|
295
307
|
if (result.status === 'error') {
|
|
296
|
-
|
|
308
|
+
contentString = `Error: ${result.errorMessage ?? 'Unknown error'}\n Please fix your mistakes.`;
|
|
309
|
+
toolMessage = new ToolMessage({
|
|
297
310
|
status: 'error',
|
|
298
|
-
content:
|
|
311
|
+
content: contentString,
|
|
299
312
|
name: toolName,
|
|
300
313
|
tool_call_id: result.toolCallId,
|
|
301
314
|
});
|
|
302
|
-
}
|
|
303
|
-
|
|
304
|
-
return new ToolMessage({
|
|
305
|
-
status: 'success',
|
|
306
|
-
content:
|
|
315
|
+
} else {
|
|
316
|
+
contentString =
|
|
307
317
|
typeof result.content === 'string'
|
|
308
318
|
? result.content
|
|
309
|
-
: JSON.stringify(result.content)
|
|
319
|
+
: JSON.stringify(result.content);
|
|
320
|
+
toolMessage = new ToolMessage({
|
|
321
|
+
status: 'success',
|
|
322
|
+
content: contentString,
|
|
323
|
+
name: toolName,
|
|
324
|
+
tool_call_id: result.toolCallId,
|
|
325
|
+
});
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
const tool_call: t.ProcessedToolCall = {
|
|
329
|
+
args:
|
|
330
|
+
typeof request?.args === 'string'
|
|
331
|
+
? request.args
|
|
332
|
+
: JSON.stringify(request?.args ?? {}),
|
|
310
333
|
name: toolName,
|
|
311
|
-
|
|
312
|
-
|
|
334
|
+
id: result.toolCallId,
|
|
335
|
+
output: contentString,
|
|
336
|
+
progress: 1,
|
|
337
|
+
};
|
|
338
|
+
|
|
339
|
+
const runStepCompletedData = {
|
|
340
|
+
result: {
|
|
341
|
+
id: stepId,
|
|
342
|
+
index: request?.turn ?? 0,
|
|
343
|
+
type: 'tool_call' as const,
|
|
344
|
+
tool_call,
|
|
345
|
+
},
|
|
346
|
+
};
|
|
347
|
+
|
|
348
|
+
safeDispatchCustomEvent(
|
|
349
|
+
GraphEvents.ON_RUN_STEP_COMPLETED,
|
|
350
|
+
runStepCompletedData,
|
|
351
|
+
config
|
|
352
|
+
);
|
|
353
|
+
|
|
354
|
+
return toolMessage;
|
|
313
355
|
});
|
|
314
356
|
|
|
315
357
|
return (Array.isArray(input) ? outputs : { messages: outputs }) as T;
|
package/src/types/tools.ts
CHANGED
|
@@ -45,6 +45,8 @@ export type ToolNodeOptions = {
|
|
|
45
45
|
eventDrivenMode?: boolean;
|
|
46
46
|
/** Tool definitions for event-driven mode (used for context, not invocation) */
|
|
47
47
|
toolDefinitions?: Map<string, LCTool>;
|
|
48
|
+
/** Agent ID for event-driven mode (used to identify which agent's context to use) */
|
|
49
|
+
agentId?: string;
|
|
48
50
|
};
|
|
49
51
|
|
|
50
52
|
export type ToolNodeConstructorParams = ToolRefs & ToolNodeOptions;
|
|
@@ -159,6 +161,10 @@ export type ToolExecuteBatchRequest = {
|
|
|
159
161
|
userId?: string;
|
|
160
162
|
/** Agent ID for context */
|
|
161
163
|
agentId?: string;
|
|
164
|
+
/** Runtime configurable from RunnableConfig (includes user, userMCPAuthMap, etc.) */
|
|
165
|
+
configurable?: Record<string, unknown>;
|
|
166
|
+
/** Runtime metadata from RunnableConfig (includes thread_id, run_id, provider, etc.) */
|
|
167
|
+
metadata?: Record<string, unknown>;
|
|
162
168
|
/** Promise resolver - handler calls this with ALL results */
|
|
163
169
|
resolve: (results: ToolExecuteResult[]) => void;
|
|
164
170
|
/** Promise rejector - handler calls this on fatal error */
|