@langchain/core 0.2.16 → 0.2.18-rc.0
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/callbacks/manager.cjs +71 -23
- package/dist/callbacks/manager.js +71 -23
- package/dist/callbacks/tests/callbacks.test.js +3 -0
- package/dist/language_models/chat_models.d.ts +18 -1
- package/dist/messages/ai.cjs +17 -0
- package/dist/messages/ai.d.ts +2 -0
- package/dist/messages/ai.js +17 -0
- package/dist/messages/base.cjs +50 -0
- package/dist/messages/base.d.ts +4 -1
- package/dist/messages/base.js +50 -0
- package/dist/messages/chat.cjs +12 -0
- package/dist/messages/chat.d.ts +2 -0
- package/dist/messages/chat.js +12 -0
- package/dist/messages/index.cjs +1 -0
- package/dist/messages/index.d.ts +1 -0
- package/dist/messages/index.js +1 -0
- package/dist/messages/modifier.cjs +35 -0
- package/dist/messages/modifier.d.ts +19 -0
- package/dist/messages/modifier.js +31 -0
- package/dist/messages/tool.cjs +14 -0
- package/dist/messages/tool.d.ts +2 -0
- package/dist/messages/tool.js +14 -0
- package/dist/messages/transformers.cjs +5 -0
- package/dist/messages/transformers.d.ts +3 -2
- package/dist/messages/transformers.js +5 -0
- package/dist/runnables/base.cjs +35 -4
- package/dist/runnables/base.d.ts +52 -5
- package/dist/runnables/base.js +35 -4
- package/dist/runnables/config.cjs +4 -7
- package/dist/runnables/config.d.ts +3 -17
- package/dist/runnables/config.js +5 -8
- package/dist/runnables/graph.d.ts +1 -1
- package/dist/runnables/iter.cjs +2 -4
- package/dist/runnables/iter.js +2 -4
- package/dist/runnables/tests/runnable_stream_events_v2.test.js +52 -48
- package/dist/runnables/tests/runnable_tools.test.js +38 -0
- package/dist/runnables/types.d.ts +14 -1
- package/dist/singletons/index.cjs +35 -5
- package/dist/singletons/index.d.ts +2 -0
- package/dist/singletons/index.js +34 -4
- package/dist/singletons/tests/async_local_storage.test.js +2 -3
- package/dist/tools/index.cjs +17 -45
- package/dist/tools/index.d.ts +19 -28
- package/dist/tools/index.js +15 -42
- package/dist/tools/tests/tools.test.js +11 -0
- package/dist/tools/utils.cjs +28 -0
- package/dist/tools/utils.d.ts +11 -0
- package/dist/tools/utils.js +23 -0
- package/dist/tracers/base.cjs +67 -13
- package/dist/tracers/base.d.ts +176 -1
- package/dist/tracers/base.js +65 -12
- package/dist/tracers/event_stream.cjs +15 -2
- package/dist/tracers/event_stream.js +15 -2
- package/dist/tracers/tests/langsmith_interop.test.d.ts +1 -0
- package/dist/tracers/tests/langsmith_interop.test.js +551 -0
- package/dist/tracers/tracer_langchain.cjs +73 -31
- package/dist/tracers/tracer_langchain.d.ts +3 -1
- package/dist/tracers/tracer_langchain.js +73 -31
- package/dist/types/zod.d.ts +1 -1
- package/dist/utils/stream.cjs +8 -9
- package/dist/utils/stream.js +8 -9
- package/package.json +2 -2
package/dist/tools/index.js
CHANGED
|
@@ -4,23 +4,8 @@ import { BaseLangChain, } from "../language_models/base.js";
|
|
|
4
4
|
import { ensureConfig, patchConfig, } from "../runnables/config.js";
|
|
5
5
|
import { ToolMessage } from "../messages/tool.js";
|
|
6
6
|
import { AsyncLocalStorageProviderSingleton } from "../singletons/index.js";
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
* It extends the built-in `Error` class and adds an optional `output`
|
|
10
|
-
* property that can hold the output that caused the exception.
|
|
11
|
-
*/
|
|
12
|
-
export class ToolInputParsingException extends Error {
|
|
13
|
-
constructor(message, output) {
|
|
14
|
-
super(message);
|
|
15
|
-
Object.defineProperty(this, "output", {
|
|
16
|
-
enumerable: true,
|
|
17
|
-
configurable: true,
|
|
18
|
-
writable: true,
|
|
19
|
-
value: void 0
|
|
20
|
-
});
|
|
21
|
-
this.output = output;
|
|
22
|
-
}
|
|
23
|
-
}
|
|
7
|
+
import { _isToolCall, ToolInputParsingException } from "./utils.js";
|
|
8
|
+
export { ToolInputParsingException };
|
|
24
9
|
/**
|
|
25
10
|
* Base class for Tools that accept input of any shape defined by a Zod schema.
|
|
26
11
|
*/
|
|
@@ -282,29 +267,23 @@ export class BaseToolkit {
|
|
|
282
267
|
return this.tools;
|
|
283
268
|
}
|
|
284
269
|
}
|
|
285
|
-
/**
|
|
286
|
-
* Creates a new StructuredTool instance with the provided function, name, description, and schema.
|
|
287
|
-
* @function
|
|
288
|
-
* @template {RunInput extends ZodAny = ZodAny} RunInput The input schema for the tool. This corresponds to the input type when the tool is invoked.
|
|
289
|
-
* @template {RunOutput = any} RunOutput The output type for the tool. This corresponds to the output type when the tool is invoked.
|
|
290
|
-
* @template {FuncInput extends z.infer<RunInput> | ToolCall = z.infer<RunInput>} FuncInput The input type for the function.
|
|
291
|
-
*
|
|
292
|
-
* @param {RunnableFunc<z.infer<RunInput> | ToolCall, RunOutput>} func - The function to invoke when the tool is called.
|
|
293
|
-
* @param fields - An object containing the following properties:
|
|
294
|
-
* @param {string} fields.name The name of the tool.
|
|
295
|
-
* @param {string | undefined} fields.description The description of the tool. Defaults to either the description on the Zod schema, or `${fields.name} tool`.
|
|
296
|
-
* @param {z.ZodObject<any, any, any, any>} fields.schema The Zod schema defining the input for the tool.
|
|
297
|
-
*
|
|
298
|
-
* @returns {DynamicStructuredTool<RunInput, RunOutput>} A new StructuredTool instance.
|
|
299
|
-
*/
|
|
300
270
|
export function tool(func, fields) {
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
271
|
+
// If the schema is not provided, or it's a string schema, create a DynamicTool
|
|
272
|
+
if (!fields.schema || !("shape" in fields.schema) || !fields.schema.shape) {
|
|
273
|
+
return new DynamicTool({
|
|
274
|
+
name: fields.name,
|
|
275
|
+
description: fields.description ??
|
|
276
|
+
fields.schema?.description ??
|
|
277
|
+
`${fields.name} tool`,
|
|
278
|
+
responseFormat: fields.responseFormat,
|
|
279
|
+
func,
|
|
280
|
+
});
|
|
281
|
+
}
|
|
282
|
+
const description = fields.description ?? fields.schema.description ?? `${fields.name} tool`;
|
|
304
283
|
return new DynamicStructuredTool({
|
|
305
284
|
name: fields.name,
|
|
306
285
|
description,
|
|
307
|
-
schema: schema,
|
|
286
|
+
schema: fields.schema,
|
|
308
287
|
// TODO: Consider moving into DynamicStructuredTool constructor
|
|
309
288
|
func: async (input, runManager, config) => {
|
|
310
289
|
return new Promise((resolve, reject) => {
|
|
@@ -324,12 +303,6 @@ export function tool(func, fields) {
|
|
|
324
303
|
responseFormat: fields.responseFormat,
|
|
325
304
|
});
|
|
326
305
|
}
|
|
327
|
-
function _isToolCall(toolCall) {
|
|
328
|
-
return !!(toolCall &&
|
|
329
|
-
typeof toolCall === "object" &&
|
|
330
|
-
"type" in toolCall &&
|
|
331
|
-
toolCall.type === "tool_call");
|
|
332
|
-
}
|
|
333
306
|
function _formatToolOutput(params) {
|
|
334
307
|
const { content, artifact, toolCallId } = params;
|
|
335
308
|
if (toolCallId) {
|
|
@@ -72,3 +72,14 @@ test("Returns tool message if responseFormat is content_and_artifact and returns
|
|
|
72
72
|
expect(toolResult.artifact).toEqual({ location: "San Francisco" });
|
|
73
73
|
expect(toolResult.name).toBe("weather");
|
|
74
74
|
});
|
|
75
|
+
test("Tool can accept single string input", async () => {
|
|
76
|
+
const stringTool = tool((input) => {
|
|
77
|
+
return `${input}a`;
|
|
78
|
+
}, {
|
|
79
|
+
name: "string_tool",
|
|
80
|
+
description: "A tool that appends 'a' to the input string",
|
|
81
|
+
schema: z.string(),
|
|
82
|
+
});
|
|
83
|
+
const result = await stringTool.invoke("b");
|
|
84
|
+
expect(result).toBe("ba");
|
|
85
|
+
});
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ToolInputParsingException = exports._isToolCall = void 0;
|
|
4
|
+
function _isToolCall(toolCall) {
|
|
5
|
+
return !!(toolCall &&
|
|
6
|
+
typeof toolCall === "object" &&
|
|
7
|
+
"type" in toolCall &&
|
|
8
|
+
toolCall.type === "tool_call");
|
|
9
|
+
}
|
|
10
|
+
exports._isToolCall = _isToolCall;
|
|
11
|
+
/**
|
|
12
|
+
* Custom error class used to handle exceptions related to tool input parsing.
|
|
13
|
+
* It extends the built-in `Error` class and adds an optional `output`
|
|
14
|
+
* property that can hold the output that caused the exception.
|
|
15
|
+
*/
|
|
16
|
+
class ToolInputParsingException extends Error {
|
|
17
|
+
constructor(message, output) {
|
|
18
|
+
super(message);
|
|
19
|
+
Object.defineProperty(this, "output", {
|
|
20
|
+
enumerable: true,
|
|
21
|
+
configurable: true,
|
|
22
|
+
writable: true,
|
|
23
|
+
value: void 0
|
|
24
|
+
});
|
|
25
|
+
this.output = output;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
exports.ToolInputParsingException = ToolInputParsingException;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ToolCall } from "../messages/tool.js";
|
|
2
|
+
export declare function _isToolCall(toolCall?: unknown): toolCall is ToolCall;
|
|
3
|
+
/**
|
|
4
|
+
* Custom error class used to handle exceptions related to tool input parsing.
|
|
5
|
+
* It extends the built-in `Error` class and adds an optional `output`
|
|
6
|
+
* property that can hold the output that caused the exception.
|
|
7
|
+
*/
|
|
8
|
+
export declare class ToolInputParsingException extends Error {
|
|
9
|
+
output?: string;
|
|
10
|
+
constructor(message: string, output?: string);
|
|
11
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export function _isToolCall(toolCall) {
|
|
2
|
+
return !!(toolCall &&
|
|
3
|
+
typeof toolCall === "object" &&
|
|
4
|
+
"type" in toolCall &&
|
|
5
|
+
toolCall.type === "tool_call");
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Custom error class used to handle exceptions related to tool input parsing.
|
|
9
|
+
* It extends the built-in `Error` class and adds an optional `output`
|
|
10
|
+
* property that can hold the output that caused the exception.
|
|
11
|
+
*/
|
|
12
|
+
export class ToolInputParsingException extends Error {
|
|
13
|
+
constructor(message, output) {
|
|
14
|
+
super(message);
|
|
15
|
+
Object.defineProperty(this, "output", {
|
|
16
|
+
enumerable: true,
|
|
17
|
+
configurable: true,
|
|
18
|
+
writable: true,
|
|
19
|
+
value: void 0
|
|
20
|
+
});
|
|
21
|
+
this.output = output;
|
|
22
|
+
}
|
|
23
|
+
}
|
package/dist/tracers/base.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.BaseTracer = void 0;
|
|
3
|
+
exports.BaseTracer = exports.isBaseTracer = void 0;
|
|
4
4
|
const base_js_1 = require("../callbacks/base.cjs");
|
|
5
5
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
6
6
|
function _coerceToDict(value, defaultKey) {
|
|
@@ -15,6 +15,10 @@ function convertToDottedOrderFormat(epoch, runId, executionOrder) {
|
|
|
15
15
|
const paddedOrder = executionOrder.toFixed(0).slice(0, 3).padStart(3, "0");
|
|
16
16
|
return (stripNonAlphanumeric(`${new Date(epoch).toISOString().slice(0, -1)}${paddedOrder}Z`) + runId);
|
|
17
17
|
}
|
|
18
|
+
function isBaseTracer(x) {
|
|
19
|
+
return typeof x._addRunToRunMap === "function";
|
|
20
|
+
}
|
|
21
|
+
exports.isBaseTracer = isBaseTracer;
|
|
18
22
|
class BaseTracer extends base_js_1.BaseCallbackHandler {
|
|
19
23
|
constructor(_fields) {
|
|
20
24
|
super(...arguments);
|
|
@@ -41,7 +45,7 @@ class BaseTracer extends base_js_1.BaseCallbackHandler {
|
|
|
41
45
|
_addChildRun(parentRun, childRun) {
|
|
42
46
|
parentRun.child_runs.push(childRun);
|
|
43
47
|
}
|
|
44
|
-
|
|
48
|
+
_addRunToRunMap(run) {
|
|
45
49
|
const currentDottedOrder = convertToDottedOrderFormat(run.start_time, run.id, run.execution_order);
|
|
46
50
|
const storedRun = { ...run };
|
|
47
51
|
if (storedRun.parent_run_id !== undefined) {
|
|
@@ -73,7 +77,7 @@ class BaseTracer extends base_js_1.BaseCallbackHandler {
|
|
|
73
77
|
storedRun.dotted_order = currentDottedOrder;
|
|
74
78
|
}
|
|
75
79
|
this.runMap.set(storedRun.id, storedRun);
|
|
76
|
-
|
|
80
|
+
return storedRun;
|
|
77
81
|
}
|
|
78
82
|
async _endTrace(run) {
|
|
79
83
|
const parentRun = run.parent_run_id !== undefined && this.runMap.get(run.parent_run_id);
|
|
@@ -94,7 +98,12 @@ class BaseTracer extends base_js_1.BaseCallbackHandler {
|
|
|
94
98
|
}
|
|
95
99
|
return parentRun.child_execution_order + 1;
|
|
96
100
|
}
|
|
97
|
-
|
|
101
|
+
/**
|
|
102
|
+
* Create and add a run to the run map for LLM start events.
|
|
103
|
+
* This must sometimes be done synchronously to avoid race conditions
|
|
104
|
+
* when callbacks are backgrounded, so we expose it as a separate method here.
|
|
105
|
+
*/
|
|
106
|
+
_createRunForLLMStart(llm, prompts, runId, parentRunId, extraParams, tags, metadata, name) {
|
|
98
107
|
const execution_order = this._getExecutionOrder(parentRunId);
|
|
99
108
|
const start_time = Date.now();
|
|
100
109
|
const finalExtraParams = metadata
|
|
@@ -120,11 +129,21 @@ class BaseTracer extends base_js_1.BaseCallbackHandler {
|
|
|
120
129
|
extra: finalExtraParams ?? {},
|
|
121
130
|
tags: tags || [],
|
|
122
131
|
};
|
|
123
|
-
|
|
132
|
+
return this._addRunToRunMap(run);
|
|
133
|
+
}
|
|
134
|
+
async handleLLMStart(llm, prompts, runId, parentRunId, extraParams, tags, metadata, name) {
|
|
135
|
+
const run = this.runMap.get(runId) ??
|
|
136
|
+
this._createRunForLLMStart(llm, prompts, runId, parentRunId, extraParams, tags, metadata, name);
|
|
137
|
+
await this.onRunCreate?.(run);
|
|
124
138
|
await this.onLLMStart?.(run);
|
|
125
139
|
return run;
|
|
126
140
|
}
|
|
127
|
-
|
|
141
|
+
/**
|
|
142
|
+
* Create and add a run to the run map for chat model start events.
|
|
143
|
+
* This must sometimes be done synchronously to avoid race conditions
|
|
144
|
+
* when callbacks are backgrounded, so we expose it as a separate method here.
|
|
145
|
+
*/
|
|
146
|
+
_createRunForChatModelStart(llm, messages, runId, parentRunId, extraParams, tags, metadata, name) {
|
|
128
147
|
const execution_order = this._getExecutionOrder(parentRunId);
|
|
129
148
|
const start_time = Date.now();
|
|
130
149
|
const finalExtraParams = metadata
|
|
@@ -150,7 +169,12 @@ class BaseTracer extends base_js_1.BaseCallbackHandler {
|
|
|
150
169
|
extra: finalExtraParams ?? {},
|
|
151
170
|
tags: tags || [],
|
|
152
171
|
};
|
|
153
|
-
|
|
172
|
+
return this._addRunToRunMap(run);
|
|
173
|
+
}
|
|
174
|
+
async handleChatModelStart(llm, messages, runId, parentRunId, extraParams, tags, metadata, name) {
|
|
175
|
+
const run = this.runMap.get(runId) ??
|
|
176
|
+
this._createRunForChatModelStart(llm, messages, runId, parentRunId, extraParams, tags, metadata, name);
|
|
177
|
+
await this.onRunCreate?.(run);
|
|
154
178
|
await this.onLLMStart?.(run);
|
|
155
179
|
return run;
|
|
156
180
|
}
|
|
@@ -184,7 +208,12 @@ class BaseTracer extends base_js_1.BaseCallbackHandler {
|
|
|
184
208
|
await this._endTrace(run);
|
|
185
209
|
return run;
|
|
186
210
|
}
|
|
187
|
-
|
|
211
|
+
/**
|
|
212
|
+
* Create and add a run to the run map for chain start events.
|
|
213
|
+
* This must sometimes be done synchronously to avoid race conditions
|
|
214
|
+
* when callbacks are backgrounded, so we expose it as a separate method here.
|
|
215
|
+
*/
|
|
216
|
+
_createRunForChainStart(chain, inputs, runId, parentRunId, tags, metadata, runType, name) {
|
|
188
217
|
const execution_order = this._getExecutionOrder(parentRunId);
|
|
189
218
|
const start_time = Date.now();
|
|
190
219
|
const run = {
|
|
@@ -207,7 +236,12 @@ class BaseTracer extends base_js_1.BaseCallbackHandler {
|
|
|
207
236
|
extra: metadata ? { metadata } : {},
|
|
208
237
|
tags: tags || [],
|
|
209
238
|
};
|
|
210
|
-
|
|
239
|
+
return this._addRunToRunMap(run);
|
|
240
|
+
}
|
|
241
|
+
async handleChainStart(chain, inputs, runId, parentRunId, tags, metadata, runType, name) {
|
|
242
|
+
const run = this.runMap.get(runId) ??
|
|
243
|
+
this._createRunForChainStart(chain, inputs, runId, parentRunId, tags, metadata, runType, name);
|
|
244
|
+
await this.onRunCreate?.(run);
|
|
211
245
|
await this.onChainStart?.(run);
|
|
212
246
|
return run;
|
|
213
247
|
}
|
|
@@ -247,7 +281,12 @@ class BaseTracer extends base_js_1.BaseCallbackHandler {
|
|
|
247
281
|
await this._endTrace(run);
|
|
248
282
|
return run;
|
|
249
283
|
}
|
|
250
|
-
|
|
284
|
+
/**
|
|
285
|
+
* Create and add a run to the run map for tool start events.
|
|
286
|
+
* This must sometimes be done synchronously to avoid race conditions
|
|
287
|
+
* when callbacks are backgrounded, so we expose it as a separate method here.
|
|
288
|
+
*/
|
|
289
|
+
_createRunForToolStart(tool, input, runId, parentRunId, tags, metadata, name) {
|
|
251
290
|
const execution_order = this._getExecutionOrder(parentRunId);
|
|
252
291
|
const start_time = Date.now();
|
|
253
292
|
const run = {
|
|
@@ -270,7 +309,12 @@ class BaseTracer extends base_js_1.BaseCallbackHandler {
|
|
|
270
309
|
extra: metadata ? { metadata } : {},
|
|
271
310
|
tags: tags || [],
|
|
272
311
|
};
|
|
273
|
-
|
|
312
|
+
return this._addRunToRunMap(run);
|
|
313
|
+
}
|
|
314
|
+
async handleToolStart(tool, input, runId, parentRunId, tags, metadata, name) {
|
|
315
|
+
const run = this.runMap.get(runId) ??
|
|
316
|
+
this._createRunForToolStart(tool, input, runId, parentRunId, tags, metadata, name);
|
|
317
|
+
await this.onRunCreate?.(run);
|
|
274
318
|
await this.onToolStart?.(run);
|
|
275
319
|
return run;
|
|
276
320
|
}
|
|
@@ -332,7 +376,12 @@ class BaseTracer extends base_js_1.BaseCallbackHandler {
|
|
|
332
376
|
});
|
|
333
377
|
await this.onAgentEnd?.(run);
|
|
334
378
|
}
|
|
335
|
-
|
|
379
|
+
/**
|
|
380
|
+
* Create and add a run to the run map for retriever start events.
|
|
381
|
+
* This must sometimes be done synchronously to avoid race conditions
|
|
382
|
+
* when callbacks are backgrounded, so we expose it as a separate method here.
|
|
383
|
+
*/
|
|
384
|
+
_createRunForRetrieverStart(retriever, query, runId, parentRunId, tags, metadata, name) {
|
|
336
385
|
const execution_order = this._getExecutionOrder(parentRunId);
|
|
337
386
|
const start_time = Date.now();
|
|
338
387
|
const run = {
|
|
@@ -355,7 +404,12 @@ class BaseTracer extends base_js_1.BaseCallbackHandler {
|
|
|
355
404
|
extra: metadata ? { metadata } : {},
|
|
356
405
|
tags: tags || [],
|
|
357
406
|
};
|
|
358
|
-
|
|
407
|
+
return this._addRunToRunMap(run);
|
|
408
|
+
}
|
|
409
|
+
async handleRetrieverStart(retriever, query, runId, parentRunId, tags, metadata, name) {
|
|
410
|
+
const run = this.runMap.get(runId) ??
|
|
411
|
+
this._createRunForRetrieverStart(retriever, query, runId, parentRunId, tags, metadata, name);
|
|
412
|
+
await this.onRunCreate?.(run);
|
|
359
413
|
await this.onRetrieverStart?.(run);
|
|
360
414
|
return run;
|
|
361
415
|
}
|
package/dist/tracers/base.d.ts
CHANGED
|
@@ -24,6 +24,7 @@ export interface Run extends BaseRun {
|
|
|
24
24
|
export interface AgentRun extends Run {
|
|
25
25
|
actions: AgentAction[];
|
|
26
26
|
}
|
|
27
|
+
export declare function isBaseTracer(x: BaseCallbackHandler): x is BaseTracer;
|
|
27
28
|
export declare abstract class BaseTracer extends BaseCallbackHandler {
|
|
28
29
|
protected runMap: Map<string, Run>;
|
|
29
30
|
constructor(_fields?: BaseCallbackHandlerInput);
|
|
@@ -31,13 +32,127 @@ export declare abstract class BaseTracer extends BaseCallbackHandler {
|
|
|
31
32
|
protected stringifyError(error: unknown): string;
|
|
32
33
|
protected abstract persistRun(run: Run): Promise<void>;
|
|
33
34
|
protected _addChildRun(parentRun: Run, childRun: Run): void;
|
|
34
|
-
|
|
35
|
+
_addRunToRunMap(run: Run): {
|
|
36
|
+
id: string;
|
|
37
|
+
start_time: number;
|
|
38
|
+
execution_order: number;
|
|
39
|
+
child_runs: Run[];
|
|
40
|
+
child_execution_order: number;
|
|
41
|
+
events: {
|
|
42
|
+
name: string;
|
|
43
|
+
time: string;
|
|
44
|
+
kwargs?: Record<string, unknown> | undefined;
|
|
45
|
+
}[];
|
|
46
|
+
trace_id?: string | undefined;
|
|
47
|
+
dotted_order?: string | undefined;
|
|
48
|
+
name: string;
|
|
49
|
+
run_type: string;
|
|
50
|
+
end_time?: number | undefined;
|
|
51
|
+
extra?: KVMap | undefined;
|
|
52
|
+
error?: string | undefined;
|
|
53
|
+
serialized?: object | undefined;
|
|
54
|
+
inputs: KVMap;
|
|
55
|
+
outputs?: KVMap | undefined;
|
|
56
|
+
reference_example_id?: string | undefined;
|
|
57
|
+
parent_run_id?: string | undefined;
|
|
58
|
+
tags?: string[] | undefined;
|
|
59
|
+
};
|
|
35
60
|
protected _endTrace(run: Run): Promise<void>;
|
|
36
61
|
protected _getExecutionOrder(parentRunId: string | undefined): number;
|
|
62
|
+
/**
|
|
63
|
+
* Create and add a run to the run map for LLM start events.
|
|
64
|
+
* This must sometimes be done synchronously to avoid race conditions
|
|
65
|
+
* when callbacks are backgrounded, so we expose it as a separate method here.
|
|
66
|
+
*/
|
|
67
|
+
_createRunForLLMStart(llm: Serialized, prompts: string[], runId: string, parentRunId?: string, extraParams?: KVMap, tags?: string[], metadata?: KVMap, name?: string): {
|
|
68
|
+
id: string;
|
|
69
|
+
start_time: number;
|
|
70
|
+
execution_order: number;
|
|
71
|
+
child_runs: Run[];
|
|
72
|
+
child_execution_order: number;
|
|
73
|
+
events: {
|
|
74
|
+
name: string;
|
|
75
|
+
time: string;
|
|
76
|
+
kwargs?: Record<string, unknown> | undefined;
|
|
77
|
+
}[];
|
|
78
|
+
trace_id?: string | undefined;
|
|
79
|
+
dotted_order?: string | undefined;
|
|
80
|
+
name: string;
|
|
81
|
+
run_type: string;
|
|
82
|
+
end_time?: number | undefined;
|
|
83
|
+
extra?: KVMap | undefined;
|
|
84
|
+
error?: string | undefined;
|
|
85
|
+
serialized?: object | undefined;
|
|
86
|
+
inputs: KVMap;
|
|
87
|
+
outputs?: KVMap | undefined;
|
|
88
|
+
reference_example_id?: string | undefined;
|
|
89
|
+
parent_run_id?: string | undefined;
|
|
90
|
+
tags?: string[] | undefined;
|
|
91
|
+
};
|
|
37
92
|
handleLLMStart(llm: Serialized, prompts: string[], runId: string, parentRunId?: string, extraParams?: KVMap, tags?: string[], metadata?: KVMap, name?: string): Promise<Run>;
|
|
93
|
+
/**
|
|
94
|
+
* Create and add a run to the run map for chat model start events.
|
|
95
|
+
* This must sometimes be done synchronously to avoid race conditions
|
|
96
|
+
* when callbacks are backgrounded, so we expose it as a separate method here.
|
|
97
|
+
*/
|
|
98
|
+
_createRunForChatModelStart(llm: Serialized, messages: BaseMessage[][], runId: string, parentRunId?: string, extraParams?: KVMap, tags?: string[], metadata?: KVMap, name?: string): {
|
|
99
|
+
id: string;
|
|
100
|
+
start_time: number;
|
|
101
|
+
execution_order: number;
|
|
102
|
+
child_runs: Run[];
|
|
103
|
+
child_execution_order: number;
|
|
104
|
+
events: {
|
|
105
|
+
name: string;
|
|
106
|
+
time: string;
|
|
107
|
+
kwargs?: Record<string, unknown> | undefined;
|
|
108
|
+
}[];
|
|
109
|
+
trace_id?: string | undefined;
|
|
110
|
+
dotted_order?: string | undefined;
|
|
111
|
+
name: string;
|
|
112
|
+
run_type: string;
|
|
113
|
+
end_time?: number | undefined;
|
|
114
|
+
extra?: KVMap | undefined;
|
|
115
|
+
error?: string | undefined;
|
|
116
|
+
serialized?: object | undefined;
|
|
117
|
+
inputs: KVMap;
|
|
118
|
+
outputs?: KVMap | undefined;
|
|
119
|
+
reference_example_id?: string | undefined;
|
|
120
|
+
parent_run_id?: string | undefined;
|
|
121
|
+
tags?: string[] | undefined;
|
|
122
|
+
};
|
|
38
123
|
handleChatModelStart(llm: Serialized, messages: BaseMessage[][], runId: string, parentRunId?: string, extraParams?: KVMap, tags?: string[], metadata?: KVMap, name?: string): Promise<Run>;
|
|
39
124
|
handleLLMEnd(output: LLMResult, runId: string): Promise<Run>;
|
|
40
125
|
handleLLMError(error: unknown, runId: string): Promise<Run>;
|
|
126
|
+
/**
|
|
127
|
+
* Create and add a run to the run map for chain start events.
|
|
128
|
+
* This must sometimes be done synchronously to avoid race conditions
|
|
129
|
+
* when callbacks are backgrounded, so we expose it as a separate method here.
|
|
130
|
+
*/
|
|
131
|
+
_createRunForChainStart(chain: Serialized, inputs: ChainValues, runId: string, parentRunId?: string, tags?: string[], metadata?: KVMap, runType?: string, name?: string): {
|
|
132
|
+
id: string;
|
|
133
|
+
start_time: number;
|
|
134
|
+
execution_order: number;
|
|
135
|
+
child_runs: Run[];
|
|
136
|
+
child_execution_order: number;
|
|
137
|
+
events: {
|
|
138
|
+
name: string;
|
|
139
|
+
time: string;
|
|
140
|
+
kwargs?: Record<string, unknown> | undefined;
|
|
141
|
+
}[];
|
|
142
|
+
trace_id?: string | undefined;
|
|
143
|
+
dotted_order?: string | undefined;
|
|
144
|
+
name: string;
|
|
145
|
+
run_type: string;
|
|
146
|
+
end_time?: number | undefined;
|
|
147
|
+
extra?: KVMap | undefined;
|
|
148
|
+
error?: string | undefined;
|
|
149
|
+
serialized?: object | undefined;
|
|
150
|
+
inputs: KVMap;
|
|
151
|
+
outputs?: KVMap | undefined;
|
|
152
|
+
reference_example_id?: string | undefined;
|
|
153
|
+
parent_run_id?: string | undefined;
|
|
154
|
+
tags?: string[] | undefined;
|
|
155
|
+
};
|
|
41
156
|
handleChainStart(chain: Serialized, inputs: ChainValues, runId: string, parentRunId?: string, tags?: string[], metadata?: KVMap, runType?: string, name?: string): Promise<Run>;
|
|
42
157
|
handleChainEnd(outputs: ChainValues, runId: string, _parentRunId?: string, _tags?: string[], kwargs?: {
|
|
43
158
|
inputs?: Record<string, unknown>;
|
|
@@ -45,11 +160,71 @@ export declare abstract class BaseTracer extends BaseCallbackHandler {
|
|
|
45
160
|
handleChainError(error: unknown, runId: string, _parentRunId?: string, _tags?: string[], kwargs?: {
|
|
46
161
|
inputs?: Record<string, unknown>;
|
|
47
162
|
}): Promise<Run>;
|
|
163
|
+
/**
|
|
164
|
+
* Create and add a run to the run map for tool start events.
|
|
165
|
+
* This must sometimes be done synchronously to avoid race conditions
|
|
166
|
+
* when callbacks are backgrounded, so we expose it as a separate method here.
|
|
167
|
+
*/
|
|
168
|
+
_createRunForToolStart(tool: Serialized, input: string, runId: string, parentRunId?: string, tags?: string[], metadata?: KVMap, name?: string): {
|
|
169
|
+
id: string;
|
|
170
|
+
start_time: number;
|
|
171
|
+
execution_order: number;
|
|
172
|
+
child_runs: Run[];
|
|
173
|
+
child_execution_order: number;
|
|
174
|
+
events: {
|
|
175
|
+
name: string;
|
|
176
|
+
time: string;
|
|
177
|
+
kwargs?: Record<string, unknown> | undefined;
|
|
178
|
+
}[];
|
|
179
|
+
trace_id?: string | undefined;
|
|
180
|
+
dotted_order?: string | undefined;
|
|
181
|
+
name: string;
|
|
182
|
+
run_type: string;
|
|
183
|
+
end_time?: number | undefined;
|
|
184
|
+
extra?: KVMap | undefined;
|
|
185
|
+
error?: string | undefined;
|
|
186
|
+
serialized?: object | undefined;
|
|
187
|
+
inputs: KVMap;
|
|
188
|
+
outputs?: KVMap | undefined;
|
|
189
|
+
reference_example_id?: string | undefined;
|
|
190
|
+
parent_run_id?: string | undefined;
|
|
191
|
+
tags?: string[] | undefined;
|
|
192
|
+
};
|
|
48
193
|
handleToolStart(tool: Serialized, input: string, runId: string, parentRunId?: string, tags?: string[], metadata?: KVMap, name?: string): Promise<Run>;
|
|
49
194
|
handleToolEnd(output: any, runId: string): Promise<Run>;
|
|
50
195
|
handleToolError(error: unknown, runId: string): Promise<Run>;
|
|
51
196
|
handleAgentAction(action: AgentAction, runId: string): Promise<void>;
|
|
52
197
|
handleAgentEnd(action: AgentFinish, runId: string): Promise<void>;
|
|
198
|
+
/**
|
|
199
|
+
* Create and add a run to the run map for retriever start events.
|
|
200
|
+
* This must sometimes be done synchronously to avoid race conditions
|
|
201
|
+
* when callbacks are backgrounded, so we expose it as a separate method here.
|
|
202
|
+
*/
|
|
203
|
+
_createRunForRetrieverStart(retriever: Serialized, query: string, runId: string, parentRunId?: string, tags?: string[], metadata?: KVMap, name?: string): {
|
|
204
|
+
id: string;
|
|
205
|
+
start_time: number;
|
|
206
|
+
execution_order: number;
|
|
207
|
+
child_runs: Run[];
|
|
208
|
+
child_execution_order: number;
|
|
209
|
+
events: {
|
|
210
|
+
name: string;
|
|
211
|
+
time: string;
|
|
212
|
+
kwargs?: Record<string, unknown> | undefined;
|
|
213
|
+
}[];
|
|
214
|
+
trace_id?: string | undefined;
|
|
215
|
+
dotted_order?: string | undefined;
|
|
216
|
+
name: string;
|
|
217
|
+
run_type: string;
|
|
218
|
+
end_time?: number | undefined;
|
|
219
|
+
extra?: KVMap | undefined;
|
|
220
|
+
error?: string | undefined;
|
|
221
|
+
serialized?: object | undefined;
|
|
222
|
+
inputs: KVMap;
|
|
223
|
+
outputs?: KVMap | undefined;
|
|
224
|
+
reference_example_id?: string | undefined;
|
|
225
|
+
parent_run_id?: string | undefined;
|
|
226
|
+
tags?: string[] | undefined;
|
|
227
|
+
};
|
|
53
228
|
handleRetrieverStart(retriever: Serialized, query: string, runId: string, parentRunId?: string, tags?: string[], metadata?: KVMap, name?: string): Promise<Run>;
|
|
54
229
|
handleRetrieverEnd(documents: Document<Record<string, unknown>>[], runId: string): Promise<Run>;
|
|
55
230
|
handleRetrieverError(error: unknown, runId: string): Promise<Run>;
|