@langchain/core 1.3.3 → 1.3.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.
- package/CHANGELOG.md +8 -0
- package/dist/language_models/base.cjs +1 -1
- package/dist/language_models/base.js +1 -1
- package/dist/tracers/trace_policy.cjs +8 -0
- package/dist/tracers/trace_policy.cjs.map +1 -1
- package/dist/tracers/trace_policy.d.cts +5 -0
- package/dist/tracers/trace_policy.d.cts.map +1 -1
- package/dist/tracers/trace_policy.d.ts +5 -0
- package/dist/tracers/trace_policy.d.ts.map +1 -1
- package/dist/tracers/trace_policy.js +8 -1
- package/dist/tracers/trace_policy.js.map +1 -1
- package/dist/tracers/tracer_langchain.cjs +34 -15
- package/dist/tracers/tracer_langchain.cjs.map +1 -1
- package/dist/tracers/tracer_langchain.d.cts +9 -2
- package/dist/tracers/tracer_langchain.d.cts.map +1 -1
- package/dist/tracers/tracer_langchain.d.ts +9 -2
- package/dist/tracers/tracer_langchain.d.ts.map +1 -1
- package/dist/tracers/tracer_langchain.js +35 -17
- package/dist/tracers/tracer_langchain.js.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# @langchain/core
|
|
2
2
|
|
|
3
|
+
## 1.3.4
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#12104](https://github.com/langchain-ai/langchainjs/pull/12104) [`e006308`](https://github.com/langchain-ai/langchainjs/commit/e006308a58a746da8ca10b8ca483611d869e9a19) Thanks [@hntrl](https://github.com/hntrl)! - Export `omitPayload` from `@langchain/core/tracers/tracer_langchain`, a `TracePolicy` processor that records an empty payload while keeping the run.
|
|
8
|
+
|
|
9
|
+
- [#12102](https://github.com/langchain-ai/langchainjs/pull/12102) [`6d157ae`](https://github.com/langchain-ai/langchainjs/commit/6d157ae5c0816851ea30f5d14fe68184da44c69e) Thanks [@hntrl](https://github.com/hntrl)! - `LangChainTracer` now still sends and ends a run when its trace policy's `processInputs` or `processOutputs` throws, with that payload dropped and the error set, instead of skipping the run or leaving it pending in LangSmith.
|
|
10
|
+
|
|
3
11
|
## 1.3.3
|
|
4
12
|
|
|
5
13
|
### Patch Changes
|
|
@@ -139,7 +139,7 @@ var BaseLangChain = class extends require_base.Runnable {
|
|
|
139
139
|
this.callbacks = params.callbacks;
|
|
140
140
|
this.tags = params.tags ?? [];
|
|
141
141
|
this.metadata = params.metadata ?? {};
|
|
142
|
-
this._addVersion("@langchain/core", "1.3.
|
|
142
|
+
this._addVersion("@langchain/core", "1.3.4");
|
|
143
143
|
}
|
|
144
144
|
_addVersion(pkg, version) {
|
|
145
145
|
const existing = this.metadata?.versions;
|
|
@@ -138,7 +138,7 @@ var BaseLangChain = class extends Runnable {
|
|
|
138
138
|
this.callbacks = params.callbacks;
|
|
139
139
|
this.tags = params.tags ?? [];
|
|
140
140
|
this.metadata = params.metadata ?? {};
|
|
141
|
-
this._addVersion("@langchain/core", "1.3.
|
|
141
|
+
this._addVersion("@langchain/core", "1.3.4");
|
|
142
142
|
}
|
|
143
143
|
_addVersion(pkg, version) {
|
|
144
144
|
const existing = this.metadata?.versions;
|
|
@@ -5,7 +5,15 @@
|
|
|
5
5
|
* @internal
|
|
6
6
|
*/
|
|
7
7
|
const TRACE_POLICY_KEY = Symbol.for("langchain.trace_policy");
|
|
8
|
+
/**
|
|
9
|
+
* Records an empty payload while keeping the run, its timing, and its children.
|
|
10
|
+
* Use as `processInputs` and/or `processOutputs` in a {@link TracePolicy}.
|
|
11
|
+
*/
|
|
12
|
+
function omitPayload(_payload) {
|
|
13
|
+
return {};
|
|
14
|
+
}
|
|
8
15
|
//#endregion
|
|
9
16
|
exports.TRACE_POLICY_KEY = TRACE_POLICY_KEY;
|
|
17
|
+
exports.omitPayload = omitPayload;
|
|
10
18
|
|
|
11
19
|
//# sourceMappingURL=trace_policy.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"trace_policy.cjs","names":[],"sources":["../../src/tracers/trace_policy.ts"],"sourcesContent":["import type { KVMap } from \"langsmith/schemas\";\n\n/**\n * Transforms what `LangChainTracer` sends to LangSmith for a run. Execution\n * values and every other callback handler (including `streamEvents`) still\n * see the raw inputs and outputs. Processors receive the recorded values by\n * reference and must not mutate them.\n */\nexport interface TracePolicy {\n processInputs?: (inputs: KVMap) => KVMap;\n processOutputs?: (outputs: KVMap) => KVMap;\n}\n\n/**\n * Key a run's `extra` carries its policy under. A symbol, so the policy is\n * never serialized with the run.\n * @internal\n */\nexport const TRACE_POLICY_KEY = Symbol.for(\"langchain.trace_policy\");\n"],"mappings":";;;;;;AAkBA,MAAa,mBAAmB,OAAO,IAAI,wBAAwB"}
|
|
1
|
+
{"version":3,"file":"trace_policy.cjs","names":[],"sources":["../../src/tracers/trace_policy.ts"],"sourcesContent":["import type { KVMap } from \"langsmith/schemas\";\n\n/**\n * Transforms what `LangChainTracer` sends to LangSmith for a run. Execution\n * values and every other callback handler (including `streamEvents`) still\n * see the raw inputs and outputs. Processors receive the recorded values by\n * reference and must not mutate them.\n */\nexport interface TracePolicy {\n processInputs?: (inputs: KVMap) => KVMap;\n processOutputs?: (outputs: KVMap) => KVMap;\n}\n\n/**\n * Key a run's `extra` carries its policy under. A symbol, so the policy is\n * never serialized with the run.\n * @internal\n */\nexport const TRACE_POLICY_KEY = Symbol.for(\"langchain.trace_policy\");\n\n/**\n * Records an empty payload while keeping the run, its timing, and its children.\n * Use as `processInputs` and/or `processOutputs` in a {@link TracePolicy}.\n */\nexport function omitPayload(_payload: KVMap): KVMap {\n return {};\n}\n"],"mappings":";;;;;;AAkBA,MAAa,mBAAmB,OAAO,IAAI,wBAAwB;;;;;AAMnE,SAAgB,YAAY,UAAwB;CAClD,OAAO,CAAC;AACV"}
|
|
@@ -10,5 +10,10 @@ export interface TracePolicy {
|
|
|
10
10
|
processInputs?: (inputs: KVMap) => KVMap;
|
|
11
11
|
processOutputs?: (outputs: KVMap) => KVMap;
|
|
12
12
|
}
|
|
13
|
+
/**
|
|
14
|
+
* Records an empty payload while keeping the run, its timing, and its children.
|
|
15
|
+
* Use as `processInputs` and/or `processOutputs` in a {@link TracePolicy}.
|
|
16
|
+
*/
|
|
17
|
+
export declare function omitPayload(_payload: KVMap): KVMap;
|
|
13
18
|
//#endregion
|
|
14
19
|
//# sourceMappingURL=trace_policy.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"trace_policy.d.cts","names":[],"sources":["../../src/tracers/trace_policy.ts"],"mappings":";;;;;;;;iBAQiB;EACf,iBAAiB,QAAQ,UAAU;EACnC,kBAAkB,SAAS,UAAU"}
|
|
1
|
+
{"version":3,"file":"trace_policy.d.cts","names":[],"sources":["../../src/tracers/trace_policy.ts"],"mappings":";;;;;;;;iBAQiB;EACf,iBAAiB,QAAQ,UAAU;EACnC,kBAAkB,SAAS,UAAU;;;;;;wBAcvB,YAAY,UAAU,QAAQ"}
|
|
@@ -10,5 +10,10 @@ export interface TracePolicy {
|
|
|
10
10
|
processInputs?: (inputs: KVMap) => KVMap;
|
|
11
11
|
processOutputs?: (outputs: KVMap) => KVMap;
|
|
12
12
|
}
|
|
13
|
+
/**
|
|
14
|
+
* Records an empty payload while keeping the run, its timing, and its children.
|
|
15
|
+
* Use as `processInputs` and/or `processOutputs` in a {@link TracePolicy}.
|
|
16
|
+
*/
|
|
17
|
+
export declare function omitPayload(_payload: KVMap): KVMap;
|
|
13
18
|
//#endregion
|
|
14
19
|
//# sourceMappingURL=trace_policy.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"trace_policy.d.ts","names":[],"sources":["../../src/tracers/trace_policy.ts"],"mappings":";;;;;;;;iBAQiB;EACf,iBAAiB,QAAQ,UAAU;EACnC,kBAAkB,SAAS,UAAU"}
|
|
1
|
+
{"version":3,"file":"trace_policy.d.ts","names":[],"sources":["../../src/tracers/trace_policy.ts"],"mappings":";;;;;;;;iBAQiB;EACf,iBAAiB,QAAQ,UAAU;EACnC,kBAAkB,SAAS,UAAU;;;;;;wBAcvB,YAAY,UAAU,QAAQ"}
|
|
@@ -5,7 +5,14 @@
|
|
|
5
5
|
* @internal
|
|
6
6
|
*/
|
|
7
7
|
const TRACE_POLICY_KEY = Symbol.for("langchain.trace_policy");
|
|
8
|
+
/**
|
|
9
|
+
* Records an empty payload while keeping the run, its timing, and its children.
|
|
10
|
+
* Use as `processInputs` and/or `processOutputs` in a {@link TracePolicy}.
|
|
11
|
+
*/
|
|
12
|
+
function omitPayload(_payload) {
|
|
13
|
+
return {};
|
|
14
|
+
}
|
|
8
15
|
//#endregion
|
|
9
|
-
export { TRACE_POLICY_KEY };
|
|
16
|
+
export { TRACE_POLICY_KEY, omitPayload };
|
|
10
17
|
|
|
11
18
|
//# sourceMappingURL=trace_policy.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"trace_policy.js","names":[],"sources":["../../src/tracers/trace_policy.ts"],"sourcesContent":["import type { KVMap } from \"langsmith/schemas\";\n\n/**\n * Transforms what `LangChainTracer` sends to LangSmith for a run. Execution\n * values and every other callback handler (including `streamEvents`) still\n * see the raw inputs and outputs. Processors receive the recorded values by\n * reference and must not mutate them.\n */\nexport interface TracePolicy {\n processInputs?: (inputs: KVMap) => KVMap;\n processOutputs?: (outputs: KVMap) => KVMap;\n}\n\n/**\n * Key a run's `extra` carries its policy under. A symbol, so the policy is\n * never serialized with the run.\n * @internal\n */\nexport const TRACE_POLICY_KEY = Symbol.for(\"langchain.trace_policy\");\n"],"mappings":";;;;;;AAkBA,MAAa,mBAAmB,OAAO,IAAI,wBAAwB"}
|
|
1
|
+
{"version":3,"file":"trace_policy.js","names":[],"sources":["../../src/tracers/trace_policy.ts"],"sourcesContent":["import type { KVMap } from \"langsmith/schemas\";\n\n/**\n * Transforms what `LangChainTracer` sends to LangSmith for a run. Execution\n * values and every other callback handler (including `streamEvents`) still\n * see the raw inputs and outputs. Processors receive the recorded values by\n * reference and must not mutate them.\n */\nexport interface TracePolicy {\n processInputs?: (inputs: KVMap) => KVMap;\n processOutputs?: (outputs: KVMap) => KVMap;\n}\n\n/**\n * Key a run's `extra` carries its policy under. A symbol, so the policy is\n * never serialized with the run.\n * @internal\n */\nexport const TRACE_POLICY_KEY = Symbol.for(\"langchain.trace_policy\");\n\n/**\n * Records an empty payload while keeping the run, its timing, and its children.\n * Use as `processInputs` and/or `processOutputs` in a {@link TracePolicy}.\n */\nexport function omitPayload(_payload: KVMap): KVMap {\n return {};\n}\n"],"mappings":";;;;;;AAkBA,MAAa,mBAAmB,OAAO,IAAI,wBAAwB;;;;;AAMnE,SAAgB,YAAY,UAAwB;CAClD,OAAO,CAAC;AACV"}
|
|
@@ -10,7 +10,8 @@ let langsmith_singletons_traceable = require("langsmith/singletons/traceable");
|
|
|
10
10
|
//#region src/tracers/tracer_langchain.ts
|
|
11
11
|
var tracer_langchain_exports = /* @__PURE__ */ require_runtime.__exportAll({
|
|
12
12
|
LangChainTracer: () => LangChainTracer,
|
|
13
|
-
OVERRIDABLE_LANGSMITH_INHERITABLE_METADATA_KEYS: () => OVERRIDABLE_LANGSMITH_INHERITABLE_METADATA_KEYS
|
|
13
|
+
OVERRIDABLE_LANGSMITH_INHERITABLE_METADATA_KEYS: () => OVERRIDABLE_LANGSMITH_INHERITABLE_METADATA_KEYS,
|
|
14
|
+
omitPayload: () => require_trace_policy.omitPayload
|
|
14
15
|
});
|
|
15
16
|
/**
|
|
16
17
|
* Keys that should be inherited from `tracerInheritableMetadata` even when
|
|
@@ -65,16 +66,45 @@ var LangChainTracer = class LangChainTracer extends require_tracers_base.BaseTra
|
|
|
65
66
|
_patchMissingTracingDefaults(this, run);
|
|
66
67
|
if (!run.extra?.lc_defers_inputs) {
|
|
67
68
|
const runTree = this.getRunTreeWithTracingConfig(run.id);
|
|
68
|
-
|
|
69
|
+
const policyError = runTree ? this._applyTracePolicy(runTree) : void 0;
|
|
69
70
|
await runTree?.postRun();
|
|
71
|
+
if (policyError !== void 0) throw policyError;
|
|
70
72
|
}
|
|
71
73
|
}
|
|
72
74
|
async onRunUpdate(run) {
|
|
73
75
|
_patchMissingTracingDefaults(this, run);
|
|
74
76
|
const runTree = this.getRunTreeWithTracingConfig(run.id);
|
|
75
|
-
|
|
77
|
+
const policyError = runTree ? this._applyTracePolicy(runTree) : void 0;
|
|
76
78
|
if (run.extra?.lc_defers_inputs) await runTree?.postRun();
|
|
77
79
|
else await runTree?.patchRun();
|
|
80
|
+
if (policyError !== void 0) throw policyError;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Applies the run's trace policy to the copy that gets sent to LangSmith, and
|
|
84
|
+
* drops the policy from that copy's `extra`. If a processor throws, its
|
|
85
|
+
* payload is dropped and the error is set on the copy and returned, so the
|
|
86
|
+
* run is still sent (and not left pending) before the error is rethrown.
|
|
87
|
+
*/
|
|
88
|
+
_applyTracePolicy(runTree) {
|
|
89
|
+
const { [require_trace_policy.TRACE_POLICY_KEY]: policy, ...extra } = runTree.extra ?? {};
|
|
90
|
+
if (policy === void 0) return void 0;
|
|
91
|
+
const { processInputs, processOutputs } = policy;
|
|
92
|
+
runTree.extra = extra;
|
|
93
|
+
let error;
|
|
94
|
+
if (processInputs && runTree.inputs !== void 0) try {
|
|
95
|
+
runTree.inputs = processInputs(runTree.inputs);
|
|
96
|
+
} catch (e) {
|
|
97
|
+
runTree.inputs = {};
|
|
98
|
+
error = e;
|
|
99
|
+
}
|
|
100
|
+
if (processOutputs && runTree.outputs !== void 0) try {
|
|
101
|
+
runTree.outputs = processOutputs(runTree.outputs);
|
|
102
|
+
} catch (e) {
|
|
103
|
+
runTree.outputs = void 0;
|
|
104
|
+
error ??= e;
|
|
105
|
+
}
|
|
106
|
+
if (error !== void 0) runTree.error ??= this.stringifyError(error);
|
|
107
|
+
return error;
|
|
78
108
|
}
|
|
79
109
|
onLLMEnd(run) {
|
|
80
110
|
const outputs = run.outputs;
|
|
@@ -177,18 +207,6 @@ var LangChainTracer = class LangChainTracer extends require_tracers_base.BaseTra
|
|
|
177
207
|
return "name" in candidate && candidate.name === "langchain_tracer" && "copyWithTracingConfig" in candidate && typeof candidate.copyWithTracingConfig === "function" && "getRunTreeWithTracingConfig" in candidate && typeof candidate.getRunTreeWithTracingConfig === "function";
|
|
178
208
|
}
|
|
179
209
|
};
|
|
180
|
-
/**
|
|
181
|
-
* Applies the run's trace policy to the copy that gets sent to LangSmith, and
|
|
182
|
-
* drops the policy from that copy's `extra`.
|
|
183
|
-
*/
|
|
184
|
-
function _applyTracePolicy(runTree) {
|
|
185
|
-
const { [require_trace_policy.TRACE_POLICY_KEY]: policy, ...extra } = runTree.extra ?? {};
|
|
186
|
-
if (policy === void 0) return;
|
|
187
|
-
const { processInputs, processOutputs } = policy;
|
|
188
|
-
runTree.extra = extra;
|
|
189
|
-
if (processInputs && runTree.inputs !== void 0) runTree.inputs = processInputs(runTree.inputs);
|
|
190
|
-
if (processOutputs && runTree.outputs !== void 0) runTree.outputs = processOutputs(runTree.outputs);
|
|
191
|
-
}
|
|
192
210
|
function _patchMissingTracingDefaults(tracer, run) {
|
|
193
211
|
if (tracer.tracingMetadata) {
|
|
194
212
|
run.extra ??= {};
|
|
@@ -207,6 +225,7 @@ function _patchMissingTracingDefaults(tracer, run) {
|
|
|
207
225
|
//#endregion
|
|
208
226
|
exports.LangChainTracer = LangChainTracer;
|
|
209
227
|
exports.OVERRIDABLE_LANGSMITH_INHERITABLE_METADATA_KEYS = OVERRIDABLE_LANGSMITH_INHERITABLE_METADATA_KEYS;
|
|
228
|
+
exports.omitPayload = require_trace_policy.omitPayload;
|
|
210
229
|
Object.defineProperty(exports, "tracer_langchain_exports", {
|
|
211
230
|
enumerable: true,
|
|
212
231
|
get: function() {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tracer_langchain.cjs","names":["AIMessage","mergeUsageMetadata","BaseTracer","getDefaultLangChainClientSingleton","RunTree","getCurrentRunTree","TRACE_POLICY_KEY"],"sources":["../../src/tracers/tracer_langchain.ts"],"sourcesContent":["import {\n type Client,\n type AgentAddress,\n type LangSmithTracingClientInterface,\n} from \"langsmith\";\nimport { RunTree, type RunTreeConfig } from \"langsmith/run_trees\";\nimport { getCurrentRunTree } from \"langsmith/singletons/traceable\";\n\nimport {\n BaseRun,\n RunCreate,\n RunUpdate as BaseRunUpdate,\n KVMap,\n} from \"langsmith/schemas\";\nimport { BaseTracer, Run as BaseTracerRun } from \"./base.js\";\nimport { BaseCallbackHandlerInput } from \"../callbacks/base.js\";\nimport { getDefaultLangChainClientSingleton } from \"../singletons/tracer.js\";\nimport { ChatGeneration } from \"../outputs.js\";\nimport { AIMessage } from \"../messages/ai.js\";\nimport { mergeUsageMetadata, UsageMetadata } from \"../messages/metadata.js\";\nimport { TRACE_POLICY_KEY, type TracePolicy } from \"./trace_policy.js\";\n\nexport type { TracePolicy } from \"./trace_policy.js\";\n\nexport interface Run extends BaseRun {\n id: string;\n child_runs: this[];\n child_execution_order: number;\n dotted_order?: string;\n trace_id?: string;\n}\n\nexport interface RunCreate2 extends RunCreate {\n trace_id?: string;\n dotted_order?: string;\n}\n\nexport interface RunUpdate extends BaseRunUpdate {\n events: BaseRun[\"events\"];\n inputs: KVMap;\n trace_id?: string;\n dotted_order?: string;\n}\n\nexport interface LangChainTracerFields extends BaseCallbackHandlerInput {\n exampleId?: string;\n projectName?: string;\n address?: AgentAddress;\n client?: LangSmithTracingClientInterface;\n replicas?: RunTreeConfig[\"replicas\"];\n metadata?: Record<string, unknown>;\n tags?: string[];\n}\n\n/**\n * Keys that should be inherited from `tracerInheritableMetadata` even when\n * the run already has a value for them. This lets nested contexts\n * (e.g. a subagent invoked from inside a parent agent) override a\n * LangSmith-only tracing metadata value that was set by an ancestor.\n *\n * Keep this list very small: every key here loses the default\n * \"first wins\" protection and is always clobbered by the nearest\n * enclosing tracer config. Only keys that are strictly for LangSmith\n * tracing bookkeeping should be added.\n */\nexport const OVERRIDABLE_LANGSMITH_INHERITABLE_METADATA_KEYS = new Set<string>([\n \"ls_agent_type\",\n]);\n\n/**\n * Extract usage_metadata from chat generations.\n *\n * Iterates through generations to find and aggregates all usage_metadata\n * found in chat messages. This is typically present in chat model outputs.\n */\nfunction _getUsageMetadataFromGenerations(\n generations: ChatGeneration[][]\n): UsageMetadata | undefined {\n let output: UsageMetadata | undefined = undefined;\n for (const generationBatch of generations) {\n for (const generation of generationBatch) {\n if (\n AIMessage.isInstance(generation.message) &&\n generation.message.usage_metadata !== undefined\n ) {\n output = mergeUsageMetadata(output, generation.message.usage_metadata);\n }\n }\n }\n return output;\n}\n\nexport class LangChainTracer\n extends BaseTracer\n implements LangChainTracerFields\n{\n name = \"langchain_tracer\";\n\n projectName?: string;\n\n address?: AgentAddress;\n\n exampleId?: string;\n\n client: LangSmithTracingClientInterface;\n\n replicas?: RunTreeConfig[\"replicas\"];\n\n usesRunTreeMap = true;\n\n tracingMetadata?: Record<string, unknown>;\n\n tracingTags: string[] = [];\n\n constructor(protected fields: LangChainTracerFields = {}) {\n super(fields);\n const {\n exampleId,\n projectName,\n address,\n client,\n replicas,\n metadata,\n tags,\n } = fields;\n\n this.projectName = projectName;\n this.address = address;\n this.replicas = replicas;\n this.exampleId = exampleId;\n this.client = client ?? getDefaultLangChainClientSingleton();\n this.tracingMetadata = metadata ? { ...metadata } : undefined;\n this.tracingTags = tags ?? [];\n\n const traceableTree = LangChainTracer.getTraceableRunTree();\n if (traceableTree) {\n this.updateFromRunTree(traceableTree);\n }\n }\n\n protected async persistRun(_run: Run): Promise<void> {\n // empty\n }\n\n async onRunCreate(run: Run): Promise<void> {\n _patchMissingTracingDefaults(this, run);\n if (!run.extra?.lc_defers_inputs) {\n const runTree = this.getRunTreeWithTracingConfig(run.id);\n if (runTree) _applyTracePolicy(runTree);\n await runTree?.postRun();\n }\n }\n\n async onRunUpdate(run: Run): Promise<void> {\n _patchMissingTracingDefaults(this, run);\n const runTree = this.getRunTreeWithTracingConfig(run.id);\n if (runTree) _applyTracePolicy(runTree);\n if (run.extra?.lc_defers_inputs) {\n await runTree?.postRun();\n } else {\n await runTree?.patchRun();\n }\n }\n\n onLLMEnd(run: BaseTracerRun): void {\n // Extract usage_metadata from outputs and store in extra.metadata\n const outputs = run.outputs as\n | { generations?: ChatGeneration[][] }\n | undefined;\n if (outputs?.generations) {\n const usageMetadata = _getUsageMetadataFromGenerations(\n outputs.generations\n );\n if (usageMetadata !== undefined) {\n run.extra = run.extra ?? {};\n const metadata =\n (run.extra.metadata as Record<string, unknown> | undefined) ?? {};\n metadata.usage_metadata = usageMetadata;\n run.extra.metadata = metadata;\n }\n }\n }\n\n copyWithTracingConfig({\n metadata,\n tags,\n }: {\n metadata?: Record<string, unknown>;\n tags?: string[];\n }): LangChainTracer {\n let mergedMetadata: Record<string, unknown> | undefined;\n if (metadata === undefined) {\n mergedMetadata = this.tracingMetadata\n ? { ...this.tracingMetadata }\n : undefined;\n } else if (this.tracingMetadata === undefined) {\n mergedMetadata = { ...metadata };\n } else {\n mergedMetadata = { ...this.tracingMetadata };\n for (const [key, value] of Object.entries(metadata)) {\n // For allowlisted LangSmith-only inheritable metadata keys (e.g.\n // `ls_agent_type`), nested callers are allowed to OVERRIDE the\n // value inherited from an ancestor. For all other keys we keep\n // the existing \"first wins\" behavior so that ancestor-provided\n // tracing metadata is not accidentally clobbered by child runs.\n if (\n !Object.prototype.hasOwnProperty.call(mergedMetadata, key) ||\n OVERRIDABLE_LANGSMITH_INHERITABLE_METADATA_KEYS.has(key)\n ) {\n mergedMetadata[key] = value;\n }\n }\n }\n\n const mergedTags = tags\n ? Array.from(new Set([...this.tracingTags, ...tags]))\n : [...this.tracingTags];\n\n const copied = new LangChainTracer({\n ...this.fields,\n metadata: mergedMetadata,\n tags: mergedTags,\n });\n copied.runMap = this.runMap;\n copied.runTreeMap = this.runTreeMap;\n return copied;\n }\n\n /** @internal */\n _getRunStoreKey(): object {\n return this.runTreeMap;\n }\n\n getRun(id: string): Run | undefined {\n return this.runTreeMap.get(id);\n }\n\n updateFromRunTree(runTree: RunTree) {\n this.runTreeMap.set(runTree.id, runTree);\n let rootRun: RunTree = runTree;\n const visited = new Set<string>();\n while (rootRun.parent_run) {\n if (visited.has(rootRun.id)) break;\n visited.add(rootRun.id);\n\n if (!rootRun.parent_run) break;\n rootRun = rootRun.parent_run as RunTree;\n }\n visited.clear();\n\n const queue = [rootRun];\n while (queue.length > 0) {\n const current = queue.shift();\n if (!current || visited.has(current.id)) continue;\n visited.add(current.id);\n\n this.runTreeMap.set(current.id, current);\n if (current.child_runs) {\n queue.push(...current.child_runs);\n }\n }\n\n this.client = runTree.client ?? this.client;\n this.replicas = runTree.replicas ?? this.replicas;\n if (runTree.project_name || runTree.address) {\n this.projectName = runTree.project_name;\n this.address = runTree.address;\n }\n this.exampleId = runTree.reference_example_id ?? this.exampleId;\n this.fields = {\n ...this.fields,\n client: this.client,\n replicas: this.replicas,\n projectName: this.projectName,\n address: this.address,\n exampleId: this.exampleId,\n };\n }\n\n getRunTreeWithTracingConfig(id: string): RunTree | undefined {\n const runTree = this.runTreeMap.get(id);\n if (!runTree) return undefined;\n\n const config: RunTreeConfig = {\n ...runTree,\n client: this.client as Client,\n project_name: this.projectName,\n address: this.address,\n replicas: this.replicas,\n reference_example_id: this.exampleId,\n tracingEnabled: true,\n };\n\n // Older SDKs merge the config over their defaults, so an explicit undefined\n // would erase the project instead of letting the SDK resolve it.\n if (config.project_name == null) delete config.project_name;\n if (config.address == null) delete config.address;\n return new RunTree(config);\n }\n\n static getTraceableRunTree(): RunTree | undefined {\n try {\n return (\n // The type cast here provides forward compatibility. Old versions of LangSmith will just\n // ignore the permitAbsentRunTree arg.\n (\n getCurrentRunTree as (\n permitAbsentRunTree: boolean\n ) => ReturnType<typeof getCurrentRunTree> | undefined\n )(true)\n );\n } catch {\n return undefined;\n }\n }\n\n static [Symbol.hasInstance](instance: unknown): boolean {\n if (typeof instance !== \"object\" || instance === null) {\n return false;\n }\n const candidate = instance as Record<string, unknown>;\n return (\n \"name\" in candidate &&\n candidate.name === \"langchain_tracer\" &&\n \"copyWithTracingConfig\" in candidate &&\n typeof candidate.copyWithTracingConfig === \"function\" &&\n \"getRunTreeWithTracingConfig\" in candidate &&\n typeof candidate.getRunTreeWithTracingConfig === \"function\"\n );\n }\n}\n\n/**\n * Applies the run's trace policy to the copy that gets sent to LangSmith, and\n * drops the policy from that copy's `extra`.\n */\nfunction _applyTracePolicy(runTree: RunTree): void {\n const { [TRACE_POLICY_KEY]: policy, ...extra } = (runTree.extra ??\n {}) as Record<PropertyKey, unknown>;\n if (policy === undefined) return;\n const { processInputs, processOutputs } = policy as TracePolicy;\n runTree.extra = extra;\n if (processInputs && runTree.inputs !== undefined) {\n runTree.inputs = processInputs(runTree.inputs);\n }\n if (processOutputs && runTree.outputs !== undefined) {\n runTree.outputs = processOutputs(runTree.outputs);\n }\n}\n\nfunction _patchMissingTracingDefaults(tracer: LangChainTracer, run: Run): void {\n if (tracer.tracingMetadata) {\n run.extra ??= {};\n const metadata: Record<string, unknown> =\n (run.extra.metadata as Record<string, unknown> | undefined) ?? {};\n let didPatchMetadata = false;\n for (const [key, value] of Object.entries(tracer.tracingMetadata)) {\n // `OVERRIDABLE_LANGSMITH_INHERITABLE_METADATA_KEYS` are a small, LangSmith-only\n // allowlist that bypasses the \"first wins\" merge so a nested caller\n // (e.g. a subagent) can override a parent-set value.\n if (\n !Object.prototype.hasOwnProperty.call(metadata, key) ||\n OVERRIDABLE_LANGSMITH_INHERITABLE_METADATA_KEYS.has(key)\n ) {\n if (metadata[key] !== value) {\n metadata[key] = value;\n didPatchMetadata = true;\n }\n }\n }\n if (didPatchMetadata) {\n run.extra.metadata = metadata;\n }\n }\n\n if (tracer.tracingTags.length > 0) {\n run.tags = Array.from(\n new Set([...(run.tags ?? []), ...tracer.tracingTags])\n );\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAiEA,MAAa,kEAAkD,IAAI,IAAY,CAC7E,eACF,CAAC;;;;;;;AAQ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mergeUsageMetadata","BaseTracer","getDefaultLangChainClientSingleton","TRACE_POLICY_KEY","RunTree","getCurrentRunTree"],"sources":["../../src/tracers/tracer_langchain.ts"],"sourcesContent":["import {\n type Client,\n type AgentAddress,\n type LangSmithTracingClientInterface,\n} from \"langsmith\";\nimport { RunTree, type RunTreeConfig } from \"langsmith/run_trees\";\nimport { getCurrentRunTree } from \"langsmith/singletons/traceable\";\n\nimport {\n BaseRun,\n RunCreate,\n RunUpdate as BaseRunUpdate,\n KVMap,\n} from \"langsmith/schemas\";\nimport { BaseTracer, Run as BaseTracerRun } from \"./base.js\";\nimport { BaseCallbackHandlerInput } from \"../callbacks/base.js\";\nimport { getDefaultLangChainClientSingleton } from \"../singletons/tracer.js\";\nimport { ChatGeneration } from \"../outputs.js\";\nimport { AIMessage } from \"../messages/ai.js\";\nimport { mergeUsageMetadata, UsageMetadata } from \"../messages/metadata.js\";\nimport { TRACE_POLICY_KEY, type TracePolicy } from \"./trace_policy.js\";\n\nexport { omitPayload, type TracePolicy } from \"./trace_policy.js\";\n\nexport interface Run extends BaseRun {\n id: string;\n child_runs: this[];\n child_execution_order: number;\n dotted_order?: string;\n trace_id?: string;\n}\n\nexport interface RunCreate2 extends RunCreate {\n trace_id?: string;\n dotted_order?: string;\n}\n\nexport interface RunUpdate extends BaseRunUpdate {\n events: BaseRun[\"events\"];\n inputs: KVMap;\n trace_id?: string;\n dotted_order?: string;\n}\n\nexport interface LangChainTracerFields extends BaseCallbackHandlerInput {\n exampleId?: string;\n projectName?: string;\n address?: AgentAddress;\n client?: LangSmithTracingClientInterface;\n replicas?: RunTreeConfig[\"replicas\"];\n metadata?: Record<string, unknown>;\n tags?: string[];\n}\n\n/**\n * Keys that should be inherited from `tracerInheritableMetadata` even when\n * the run already has a value for them. This lets nested contexts\n * (e.g. a subagent invoked from inside a parent agent) override a\n * LangSmith-only tracing metadata value that was set by an ancestor.\n *\n * Keep this list very small: every key here loses the default\n * \"first wins\" protection and is always clobbered by the nearest\n * enclosing tracer config. Only keys that are strictly for LangSmith\n * tracing bookkeeping should be added.\n */\nexport const OVERRIDABLE_LANGSMITH_INHERITABLE_METADATA_KEYS = new Set<string>([\n \"ls_agent_type\",\n]);\n\n/**\n * Extract usage_metadata from chat generations.\n *\n * Iterates through generations to find and aggregates all usage_metadata\n * found in chat messages. This is typically present in chat model outputs.\n */\nfunction _getUsageMetadataFromGenerations(\n generations: ChatGeneration[][]\n): UsageMetadata | undefined {\n let output: UsageMetadata | undefined = undefined;\n for (const generationBatch of generations) {\n for (const generation of generationBatch) {\n if (\n AIMessage.isInstance(generation.message) &&\n generation.message.usage_metadata !== undefined\n ) {\n output = mergeUsageMetadata(output, generation.message.usage_metadata);\n }\n }\n }\n return output;\n}\n\nexport class LangChainTracer\n extends BaseTracer\n implements LangChainTracerFields\n{\n name = \"langchain_tracer\";\n\n projectName?: string;\n\n address?: AgentAddress;\n\n exampleId?: string;\n\n client: LangSmithTracingClientInterface;\n\n replicas?: RunTreeConfig[\"replicas\"];\n\n usesRunTreeMap = true;\n\n tracingMetadata?: Record<string, unknown>;\n\n tracingTags: string[] = [];\n\n constructor(protected fields: LangChainTracerFields = {}) {\n super(fields);\n const {\n exampleId,\n projectName,\n address,\n client,\n replicas,\n metadata,\n tags,\n } = fields;\n\n this.projectName = projectName;\n this.address = address;\n this.replicas = replicas;\n this.exampleId = exampleId;\n this.client = client ?? getDefaultLangChainClientSingleton();\n this.tracingMetadata = metadata ? { ...metadata } : undefined;\n this.tracingTags = tags ?? [];\n\n const traceableTree = LangChainTracer.getTraceableRunTree();\n if (traceableTree) {\n this.updateFromRunTree(traceableTree);\n }\n }\n\n protected async persistRun(_run: Run): Promise<void> {\n // empty\n }\n\n async onRunCreate(run: Run): Promise<void> {\n _patchMissingTracingDefaults(this, run);\n if (!run.extra?.lc_defers_inputs) {\n const runTree = this.getRunTreeWithTracingConfig(run.id);\n const policyError = runTree ? this._applyTracePolicy(runTree) : undefined;\n await runTree?.postRun();\n if (policyError !== undefined) throw policyError;\n }\n }\n\n async onRunUpdate(run: Run): Promise<void> {\n _patchMissingTracingDefaults(this, run);\n const runTree = this.getRunTreeWithTracingConfig(run.id);\n const policyError = runTree ? this._applyTracePolicy(runTree) : undefined;\n if (run.extra?.lc_defers_inputs) {\n await runTree?.postRun();\n } else {\n await runTree?.patchRun();\n }\n if (policyError !== undefined) throw policyError;\n }\n\n /**\n * Applies the run's trace policy to the copy that gets sent to LangSmith, and\n * drops the policy from that copy's `extra`. If a processor throws, its\n * payload is dropped and the error is set on the copy and returned, so the\n * run is still sent (and not left pending) before the error is rethrown.\n */\n private _applyTracePolicy(runTree: RunTree): unknown {\n const { [TRACE_POLICY_KEY]: policy, ...extra } = (runTree.extra ??\n {}) as Record<PropertyKey, unknown>;\n if (policy === undefined) return undefined;\n const { processInputs, processOutputs } = policy as TracePolicy;\n runTree.extra = extra;\n let error: unknown;\n if (processInputs && runTree.inputs !== undefined) {\n try {\n runTree.inputs = processInputs(runTree.inputs);\n } catch (e) {\n runTree.inputs = {};\n error = e;\n }\n }\n if (processOutputs && runTree.outputs !== undefined) {\n try {\n runTree.outputs = processOutputs(runTree.outputs);\n } catch (e) {\n runTree.outputs = undefined;\n error ??= e;\n }\n }\n // Keep the run's own error, if it failed; the policy error is still rethrown.\n if (error !== undefined) runTree.error ??= this.stringifyError(error);\n return error;\n }\n\n onLLMEnd(run: BaseTracerRun): void {\n // Extract usage_metadata from outputs and store in extra.metadata\n const outputs = run.outputs as\n | { generations?: ChatGeneration[][] }\n | undefined;\n if (outputs?.generations) {\n const usageMetadata = _getUsageMetadataFromGenerations(\n outputs.generations\n );\n if (usageMetadata !== undefined) {\n run.extra = run.extra ?? {};\n const metadata =\n (run.extra.metadata as Record<string, unknown> | undefined) ?? {};\n metadata.usage_metadata = usageMetadata;\n run.extra.metadata = metadata;\n }\n }\n }\n\n copyWithTracingConfig({\n metadata,\n tags,\n }: {\n metadata?: Record<string, unknown>;\n tags?: string[];\n }): LangChainTracer {\n let mergedMetadata: Record<string, unknown> | undefined;\n if (metadata === undefined) {\n mergedMetadata = this.tracingMetadata\n ? { ...this.tracingMetadata }\n : undefined;\n } else if (this.tracingMetadata === undefined) {\n mergedMetadata = { ...metadata };\n } else {\n mergedMetadata = { ...this.tracingMetadata };\n for (const [key, value] of Object.entries(metadata)) {\n // For allowlisted LangSmith-only inheritable metadata keys (e.g.\n // `ls_agent_type`), nested callers are allowed to OVERRIDE the\n // value inherited from an ancestor. For all other keys we keep\n // the existing \"first wins\" behavior so that ancestor-provided\n // tracing metadata is not accidentally clobbered by child runs.\n if (\n !Object.prototype.hasOwnProperty.call(mergedMetadata, key) ||\n OVERRIDABLE_LANGSMITH_INHERITABLE_METADATA_KEYS.has(key)\n ) {\n mergedMetadata[key] = value;\n }\n }\n }\n\n const mergedTags = tags\n ? Array.from(new Set([...this.tracingTags, ...tags]))\n : [...this.tracingTags];\n\n const copied = new LangChainTracer({\n ...this.fields,\n metadata: mergedMetadata,\n tags: mergedTags,\n });\n copied.runMap = this.runMap;\n copied.runTreeMap = this.runTreeMap;\n return copied;\n }\n\n /** @internal */\n _getRunStoreKey(): object {\n return this.runTreeMap;\n }\n\n getRun(id: string): Run | undefined {\n return this.runTreeMap.get(id);\n }\n\n updateFromRunTree(runTree: RunTree) {\n this.runTreeMap.set(runTree.id, runTree);\n let rootRun: RunTree = runTree;\n const visited = new Set<string>();\n while (rootRun.parent_run) {\n if (visited.has(rootRun.id)) break;\n visited.add(rootRun.id);\n\n if (!rootRun.parent_run) break;\n rootRun = rootRun.parent_run as RunTree;\n }\n visited.clear();\n\n const queue = [rootRun];\n while (queue.length > 0) {\n const current = queue.shift();\n if (!current || visited.has(current.id)) continue;\n visited.add(current.id);\n\n this.runTreeMap.set(current.id, current);\n if (current.child_runs) {\n queue.push(...current.child_runs);\n }\n }\n\n this.client = runTree.client ?? this.client;\n this.replicas = runTree.replicas ?? this.replicas;\n if (runTree.project_name || runTree.address) {\n this.projectName = runTree.project_name;\n this.address = runTree.address;\n }\n this.exampleId = runTree.reference_example_id ?? this.exampleId;\n this.fields = {\n ...this.fields,\n client: this.client,\n replicas: this.replicas,\n projectName: this.projectName,\n address: this.address,\n exampleId: this.exampleId,\n };\n }\n\n getRunTreeWithTracingConfig(id: string): RunTree | undefined {\n const runTree = this.runTreeMap.get(id);\n if (!runTree) return undefined;\n\n const config: RunTreeConfig = {\n ...runTree,\n client: this.client as Client,\n project_name: this.projectName,\n address: this.address,\n replicas: this.replicas,\n reference_example_id: this.exampleId,\n tracingEnabled: true,\n };\n\n // Older SDKs merge the config over their defaults, so an explicit undefined\n // would erase the project instead of letting the SDK resolve it.\n if (config.project_name == null) delete config.project_name;\n if (config.address == null) delete config.address;\n return new RunTree(config);\n }\n\n static getTraceableRunTree(): RunTree | undefined {\n try {\n return (\n // The type cast here provides forward compatibility. Old versions of LangSmith will just\n // ignore the permitAbsentRunTree arg.\n (\n getCurrentRunTree as (\n permitAbsentRunTree: boolean\n ) => ReturnType<typeof getCurrentRunTree> | undefined\n )(true)\n );\n } catch {\n return undefined;\n }\n }\n\n static [Symbol.hasInstance](instance: unknown): boolean {\n if (typeof instance !== \"object\" || instance === null) {\n return false;\n }\n const candidate = instance as Record<string, unknown>;\n return (\n \"name\" in candidate &&\n candidate.name === \"langchain_tracer\" &&\n \"copyWithTracingConfig\" in candidate &&\n typeof candidate.copyWithTracingConfig === \"function\" &&\n \"getRunTreeWithTracingConfig\" in candidate &&\n typeof candidate.getRunTreeWithTracingConfig === \"function\"\n );\n }\n}\n\nfunction _patchMissingTracingDefaults(tracer: LangChainTracer, run: Run): void {\n if (tracer.tracingMetadata) {\n run.extra ??= {};\n const metadata: Record<string, unknown> =\n (run.extra.metadata as Record<string, unknown> | undefined) ?? {};\n let didPatchMetadata = false;\n for (const [key, value] of Object.entries(tracer.tracingMetadata)) {\n // `OVERRIDABLE_LANGSMITH_INHERITABLE_METADATA_KEYS` are a small, LangSmith-only\n // allowlist that bypasses the \"first wins\" merge so a nested caller\n // (e.g. a subagent) can override a parent-set value.\n if (\n !Object.prototype.hasOwnProperty.call(metadata, key) ||\n OVERRIDABLE_LANGSMITH_INHERITABLE_METADATA_KEYS.has(key)\n ) {\n if (metadata[key] !== value) {\n metadata[key] = value;\n didPatchMetadata = true;\n }\n }\n }\n if (didPatchMetadata) {\n run.extra.metadata = metadata;\n }\n }\n\n if (tracer.tracingTags.length > 0) {\n run.tags = Array.from(\n new Set([...(run.tags ?? []), ...tracer.tracingTags])\n );\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAiEA,MAAa,kEAAkD,IAAI,IAAY,CAC7E,eACF,CAAC;;;;;;;AAQD,SAAS,iCACP,aAC2B;CAC3B,IAAI,SAAoC,KAAA;CACxC,KAAK,MAAM,mBAAmB,aAC5B,KAAK,MAAM,cAAc,iBACvB,IACEA,WAAAA,UAAU,WAAW,WAAW,OAAO,KACvC,WAAW,QAAQ,mBAAmB,KAAA,GAEtC,SAASC,iBAAAA,mBAAmB,QAAQ,WAAW,QAAQ,cAAc;CAI3E,OAAO;AACT;AAEA,IAAa,kBAAb,MAAa,wBACHC,qBAAAA,WAEV;CAmBwB;CAlBtB,OAAO;CAEP;CAEA;CAEA;CAEA;CAEA;CAEA,iBAAiB;CAEjB;CAEA,cAAwB,CAAC;CAEzB,YAAY,SAA0C,CAAC,GAAG;EACxD,MAAM,MAAM;EADQ,KAAA,SAAA;EAEpB,MAAM,EACJ,WACA,aACA,SACA,QACA,UACA,UACA,SACE;EAEJ,KAAK,cAAc;EACnB,KAAK,UAAU;EACf,KAAK,WAAW;EAChB,KAAK,YAAY;EACjB,KAAK,SAAS,UAAUC,eAAAA,mCAAmC;EAC3D,KAAK,kBAAkB,WAAW,EAAE,GAAG,SAAS,IAAI,KAAA;EACpD,KAAK,cAAc,QAAQ,CAAC;EAE5B,MAAM,gBAAgB,gBAAgB,oBAAoB;EAC1D,IAAI,eACF,KAAK,kBAAkB,aAAa;CAExC;CAEA,MAAgB,WAAW,MAA0B,CAErD;CA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EAET,MAAM,YAAY;EAClB,OACE,UAAU,aACV,UAAU,SAAS,sBACnB,2BAA2B,aAC3B,OAAO,UAAU,0BAA0B,cAC3C,iCAAiC,aACjC,OAAO,UAAU,gCAAgC;CAErD;AACF;AAEA,SAAS,6BAA6B,QAAyB,KAAgB;CAC7E,IAAI,OAAO,iBAAiB;EAC1B,IAAI,UAAU,CAAC;EACf,MAAM,WACH,IAAI,MAAM,YAAoD,CAAC;EAClE,IAAI,mBAAmB;EACvB,KAAK,MAAM,CAAC,KAAK,UAAU,OAAO,QAAQ,OAAO,eAAe,GAI9D,IACE,CAAC,OAAO,UAAU,eAAe,KAAK,UAAU,GAAG,KACnD,gDAAgD,IAAI,GAAG,GAEnD;OAAA,SAAS,SAAS,OAAO;IAC3B,SAAS,OAAO;IAChB,mBAAmB;GACrB;;EAGJ,IAAI,kBACF,IAAI,MAAM,WAAW;CAEzB;CAEA,IAAI,OAAO,YAAY,SAAS,GAC9B,IAAI,OAAO,MAAM,qBACf,IAAI,IAAI,CAAC,GAAI,IAAI,QAAQ,CAAC,GAAI,GAAG,OAAO,WAAW,CAAC,CACtD;AAEJ"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { BaseCallbackHandlerInput } from "../callbacks/base.cjs";
|
|
2
2
|
import { BaseTracer, Run as Run$2 } from "./base.cjs";
|
|
3
|
-
import { TracePolicy } from "./trace_policy.cjs";
|
|
3
|
+
import { TracePolicy, omitPayload } from "./trace_policy.cjs";
|
|
4
4
|
import { BaseRun, KVMap, RunCreate, RunUpdate as RunUpdate$1 } from "langsmith/schemas";
|
|
5
5
|
import { RunTree, RunTreeConfig } from "langsmith/run_trees";
|
|
6
6
|
import { AgentAddress, LangSmithTracingClientInterface } from "langsmith";
|
|
@@ -58,6 +58,13 @@ export declare class LangChainTracer extends BaseTracer implements LangChainTrac
|
|
|
58
58
|
protected persistRun(_run: Run): Promise<void>;
|
|
59
59
|
onRunCreate(run: Run): Promise<void>;
|
|
60
60
|
onRunUpdate(run: Run): Promise<void>;
|
|
61
|
+
/**
|
|
62
|
+
* Applies the run's trace policy to the copy that gets sent to LangSmith, and
|
|
63
|
+
* drops the policy from that copy's `extra`. If a processor throws, its
|
|
64
|
+
* payload is dropped and the error is set on the copy and returned, so the
|
|
65
|
+
* run is still sent (and not left pending) before the error is rethrown.
|
|
66
|
+
*/
|
|
67
|
+
private _applyTracePolicy;
|
|
61
68
|
onLLMEnd(run: Run$2): void;
|
|
62
69
|
copyWithTracingConfig({ metadata, tags }: {
|
|
63
70
|
metadata?: Record<string, unknown>;
|
|
@@ -72,5 +79,5 @@ export declare class LangChainTracer extends BaseTracer implements LangChainTrac
|
|
|
72
79
|
static [Symbol.hasInstance](instance: unknown): boolean;
|
|
73
80
|
}
|
|
74
81
|
//#endregion
|
|
75
|
-
export type
|
|
82
|
+
export { type TracePolicy, omitPayload };
|
|
76
83
|
//# sourceMappingURL=tracer_langchain.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tracer_langchain.d.cts","names":["BaseRunUpdate","BaseTracerRun"],"sources":["../../src/tracers/tracer_langchain.ts"],"mappings":";;;;;;;iBAwBiB,YAAY;EAC3B;EACA;EACA;EACA;EACA;;iBAGe,mBAAmB;EAClC;EACA;;iBAGe,kBAAkBA;EACjC,QAAQ;EACR,QAAQ;EACR;EACA;;iBAGe,8BAA8B;EAC7C;EACA;EACA,UAAU;EACV,SAAS;EACT,WAAW;EACX,WAAW;EACX;;;;;;;;;;;;;qBAcW,iDAA+C;qBA2B/C,wBACH,sBACG;YAoBW,QAAQ;EAlB9B;EAEA;EAEA,UAAU;EAEV;EAEA,QAAQ;EAER,WAAW;EAEX;EAEA,kBAAkB;EAElB;EAEA,YAAsB,SAAQ;YA0Bd,WAAW,MAAM,MAAM;EAIjC,YAAY,KAAK,MAAM;
|
|
1
|
+
{"version":3,"file":"tracer_langchain.d.cts","names":["BaseRunUpdate","BaseTracerRun"],"sources":["../../src/tracers/tracer_langchain.ts"],"mappings":";;;;;;;iBAwBiB,YAAY;EAC3B;EACA;EACA;EACA;EACA;;iBAGe,mBAAmB;EAClC;EACA;;iBAGe,kBAAkBA;EACjC,QAAQ;EACR,QAAQ;EACR;EACA;;iBAGe,8BAA8B;EAC7C;EACA;EACA,UAAU;EACV,SAAS;EACT,WAAW;EACX,WAAW;EACX;;;;;;;;;;;;;qBAcW,iDAA+C;qBA2B/C,wBACH,sBACG;YAoBW,QAAQ;EAlB9B;EAEA;EAEA,UAAU;EAEV;EAEA,QAAQ;EAER,WAAW;EAEX;EAEA,kBAAkB;EAElB;EAEA,YAAsB,SAAQ;YA0Bd,WAAW,MAAM,MAAM;EAIjC,YAAY,KAAK,MAAM;EAUvB,YAAY,KAAK,MAAM;;;;;;;UAkBrB;EA4BR,SAAS,KAAKC;EAmBd,wBACE,UACA;IAEA,WAAW;IACX;MACE;;EAwCJ;EAIA,OAAO,aAAa;EAIpB,kBAAkB,SAAS;EA0C3B,4BAA4B,aAAa;SAqBlC,uBAAuB;UAgBtB,OAAO,aAAa"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { BaseCallbackHandlerInput } from "../callbacks/base.js";
|
|
2
2
|
import { BaseTracer, Run as Run$2 } from "./base.js";
|
|
3
|
-
import { TracePolicy } from "./trace_policy.js";
|
|
3
|
+
import { TracePolicy, omitPayload } from "./trace_policy.js";
|
|
4
4
|
import { RunTree, RunTreeConfig } from "langsmith/run_trees";
|
|
5
5
|
import { AgentAddress, LangSmithTracingClientInterface } from "langsmith";
|
|
6
6
|
import { BaseRun, KVMap, RunCreate, RunUpdate as RunUpdate$1 } from "langsmith/schemas";
|
|
@@ -58,6 +58,13 @@ export declare class LangChainTracer extends BaseTracer implements LangChainTrac
|
|
|
58
58
|
protected persistRun(_run: Run): Promise<void>;
|
|
59
59
|
onRunCreate(run: Run): Promise<void>;
|
|
60
60
|
onRunUpdate(run: Run): Promise<void>;
|
|
61
|
+
/**
|
|
62
|
+
* Applies the run's trace policy to the copy that gets sent to LangSmith, and
|
|
63
|
+
* drops the policy from that copy's `extra`. If a processor throws, its
|
|
64
|
+
* payload is dropped and the error is set on the copy and returned, so the
|
|
65
|
+
* run is still sent (and not left pending) before the error is rethrown.
|
|
66
|
+
*/
|
|
67
|
+
private _applyTracePolicy;
|
|
61
68
|
onLLMEnd(run: Run$2): void;
|
|
62
69
|
copyWithTracingConfig({ metadata, tags }: {
|
|
63
70
|
metadata?: Record<string, unknown>;
|
|
@@ -72,5 +79,5 @@ export declare class LangChainTracer extends BaseTracer implements LangChainTrac
|
|
|
72
79
|
static [Symbol.hasInstance](instance: unknown): boolean;
|
|
73
80
|
}
|
|
74
81
|
//#endregion
|
|
75
|
-
export type
|
|
82
|
+
export { type TracePolicy, omitPayload };
|
|
76
83
|
//# sourceMappingURL=tracer_langchain.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tracer_langchain.d.ts","names":["BaseRunUpdate","BaseTracerRun"],"sources":["../../src/tracers/tracer_langchain.ts"],"mappings":";;;;;;;iBAwBiB,YAAY;EAC3B;EACA;EACA;EACA;EACA;;iBAGe,mBAAmB;EAClC;EACA;;iBAGe,kBAAkBA;EACjC,QAAQ;EACR,QAAQ;EACR;EACA;;iBAGe,8BAA8B;EAC7C;EACA;EACA,UAAU;EACV,SAAS;EACT,WAAW;EACX,WAAW;EACX;;;;;;;;;;;;;qBAcW,iDAA+C;qBA2B/C,wBACH,sBACG;YAoBW,QAAQ;EAlB9B;EAEA;EAEA,UAAU;EAEV;EAEA,QAAQ;EAER,WAAW;EAEX;EAEA,kBAAkB;EAElB;EAEA,YAAsB,SAAQ;YA0Bd,WAAW,MAAM,MAAM;EAIjC,YAAY,KAAK,MAAM;
|
|
1
|
+
{"version":3,"file":"tracer_langchain.d.ts","names":["BaseRunUpdate","BaseTracerRun"],"sources":["../../src/tracers/tracer_langchain.ts"],"mappings":";;;;;;;iBAwBiB,YAAY;EAC3B;EACA;EACA;EACA;EACA;;iBAGe,mBAAmB;EAClC;EACA;;iBAGe,kBAAkBA;EACjC,QAAQ;EACR,QAAQ;EACR;EACA;;iBAGe,8BAA8B;EAC7C;EACA;EACA,UAAU;EACV,SAAS;EACT,WAAW;EACX,WAAW;EACX;;;;;;;;;;;;;qBAcW,iDAA+C;qBA2B/C,wBACH,sBACG;YAoBW,QAAQ;EAlB9B;EAEA;EAEA,UAAU;EAEV;EAEA,QAAQ;EAER,WAAW;EAEX;EAEA,kBAAkB;EAElB;EAEA,YAAsB,SAAQ;YA0Bd,WAAW,MAAM,MAAM;EAIjC,YAAY,KAAK,MAAM;EAUvB,YAAY,KAAK,MAAM;;;;;;;UAkBrB;EA4BR,SAAS,KAAKC;EAmBd,wBACE,UACA;IAEA,WAAW;IACX;MACE;;EAwCJ;EAIA,OAAO,aAAa;EAIpB,kBAAkB,SAAS;EA0C3B,4BAA4B,aAAa;SAqBlC,uBAAuB;UAgBtB,OAAO,aAAa"}
|
|
@@ -3,13 +3,14 @@ import { mergeUsageMetadata } from "../messages/metadata.js";
|
|
|
3
3
|
import { AIMessage } from "../messages/ai.js";
|
|
4
4
|
import { BaseTracer } from "./base.js";
|
|
5
5
|
import { getDefaultLangChainClientSingleton } from "../singletons/tracer.js";
|
|
6
|
-
import { TRACE_POLICY_KEY } from "./trace_policy.js";
|
|
6
|
+
import { TRACE_POLICY_KEY, omitPayload } from "./trace_policy.js";
|
|
7
7
|
import { RunTree } from "langsmith/run_trees";
|
|
8
8
|
import { getCurrentRunTree } from "langsmith/singletons/traceable";
|
|
9
9
|
//#region src/tracers/tracer_langchain.ts
|
|
10
10
|
var tracer_langchain_exports = /* @__PURE__ */ __exportAll({
|
|
11
11
|
LangChainTracer: () => LangChainTracer,
|
|
12
|
-
OVERRIDABLE_LANGSMITH_INHERITABLE_METADATA_KEYS: () => OVERRIDABLE_LANGSMITH_INHERITABLE_METADATA_KEYS
|
|
12
|
+
OVERRIDABLE_LANGSMITH_INHERITABLE_METADATA_KEYS: () => OVERRIDABLE_LANGSMITH_INHERITABLE_METADATA_KEYS,
|
|
13
|
+
omitPayload: () => omitPayload
|
|
13
14
|
});
|
|
14
15
|
/**
|
|
15
16
|
* Keys that should be inherited from `tracerInheritableMetadata` even when
|
|
@@ -64,16 +65,45 @@ var LangChainTracer = class LangChainTracer extends BaseTracer {
|
|
|
64
65
|
_patchMissingTracingDefaults(this, run);
|
|
65
66
|
if (!run.extra?.lc_defers_inputs) {
|
|
66
67
|
const runTree = this.getRunTreeWithTracingConfig(run.id);
|
|
67
|
-
|
|
68
|
+
const policyError = runTree ? this._applyTracePolicy(runTree) : void 0;
|
|
68
69
|
await runTree?.postRun();
|
|
70
|
+
if (policyError !== void 0) throw policyError;
|
|
69
71
|
}
|
|
70
72
|
}
|
|
71
73
|
async onRunUpdate(run) {
|
|
72
74
|
_patchMissingTracingDefaults(this, run);
|
|
73
75
|
const runTree = this.getRunTreeWithTracingConfig(run.id);
|
|
74
|
-
|
|
76
|
+
const policyError = runTree ? this._applyTracePolicy(runTree) : void 0;
|
|
75
77
|
if (run.extra?.lc_defers_inputs) await runTree?.postRun();
|
|
76
78
|
else await runTree?.patchRun();
|
|
79
|
+
if (policyError !== void 0) throw policyError;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Applies the run's trace policy to the copy that gets sent to LangSmith, and
|
|
83
|
+
* drops the policy from that copy's `extra`. If a processor throws, its
|
|
84
|
+
* payload is dropped and the error is set on the copy and returned, so the
|
|
85
|
+
* run is still sent (and not left pending) before the error is rethrown.
|
|
86
|
+
*/
|
|
87
|
+
_applyTracePolicy(runTree) {
|
|
88
|
+
const { [TRACE_POLICY_KEY]: policy, ...extra } = runTree.extra ?? {};
|
|
89
|
+
if (policy === void 0) return void 0;
|
|
90
|
+
const { processInputs, processOutputs } = policy;
|
|
91
|
+
runTree.extra = extra;
|
|
92
|
+
let error;
|
|
93
|
+
if (processInputs && runTree.inputs !== void 0) try {
|
|
94
|
+
runTree.inputs = processInputs(runTree.inputs);
|
|
95
|
+
} catch (e) {
|
|
96
|
+
runTree.inputs = {};
|
|
97
|
+
error = e;
|
|
98
|
+
}
|
|
99
|
+
if (processOutputs && runTree.outputs !== void 0) try {
|
|
100
|
+
runTree.outputs = processOutputs(runTree.outputs);
|
|
101
|
+
} catch (e) {
|
|
102
|
+
runTree.outputs = void 0;
|
|
103
|
+
error ??= e;
|
|
104
|
+
}
|
|
105
|
+
if (error !== void 0) runTree.error ??= this.stringifyError(error);
|
|
106
|
+
return error;
|
|
77
107
|
}
|
|
78
108
|
onLLMEnd(run) {
|
|
79
109
|
const outputs = run.outputs;
|
|
@@ -176,18 +206,6 @@ var LangChainTracer = class LangChainTracer extends BaseTracer {
|
|
|
176
206
|
return "name" in candidate && candidate.name === "langchain_tracer" && "copyWithTracingConfig" in candidate && typeof candidate.copyWithTracingConfig === "function" && "getRunTreeWithTracingConfig" in candidate && typeof candidate.getRunTreeWithTracingConfig === "function";
|
|
177
207
|
}
|
|
178
208
|
};
|
|
179
|
-
/**
|
|
180
|
-
* Applies the run's trace policy to the copy that gets sent to LangSmith, and
|
|
181
|
-
* drops the policy from that copy's `extra`.
|
|
182
|
-
*/
|
|
183
|
-
function _applyTracePolicy(runTree) {
|
|
184
|
-
const { [TRACE_POLICY_KEY]: policy, ...extra } = runTree.extra ?? {};
|
|
185
|
-
if (policy === void 0) return;
|
|
186
|
-
const { processInputs, processOutputs } = policy;
|
|
187
|
-
runTree.extra = extra;
|
|
188
|
-
if (processInputs && runTree.inputs !== void 0) runTree.inputs = processInputs(runTree.inputs);
|
|
189
|
-
if (processOutputs && runTree.outputs !== void 0) runTree.outputs = processOutputs(runTree.outputs);
|
|
190
|
-
}
|
|
191
209
|
function _patchMissingTracingDefaults(tracer, run) {
|
|
192
210
|
if (tracer.tracingMetadata) {
|
|
193
211
|
run.extra ??= {};
|
|
@@ -204,6 +222,6 @@ function _patchMissingTracingDefaults(tracer, run) {
|
|
|
204
222
|
if (tracer.tracingTags.length > 0) run.tags = Array.from(/* @__PURE__ */ new Set([...run.tags ?? [], ...tracer.tracingTags]));
|
|
205
223
|
}
|
|
206
224
|
//#endregion
|
|
207
|
-
export { LangChainTracer, OVERRIDABLE_LANGSMITH_INHERITABLE_METADATA_KEYS, tracer_langchain_exports };
|
|
225
|
+
export { LangChainTracer, OVERRIDABLE_LANGSMITH_INHERITABLE_METADATA_KEYS, omitPayload, tracer_langchain_exports };
|
|
208
226
|
|
|
209
227
|
//# sourceMappingURL=tracer_langchain.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tracer_langchain.js","names":[],"sources":["../../src/tracers/tracer_langchain.ts"],"sourcesContent":["import {\n type Client,\n type AgentAddress,\n type LangSmithTracingClientInterface,\n} from \"langsmith\";\nimport { RunTree, type RunTreeConfig } from \"langsmith/run_trees\";\nimport { getCurrentRunTree } from \"langsmith/singletons/traceable\";\n\nimport {\n BaseRun,\n RunCreate,\n RunUpdate as BaseRunUpdate,\n KVMap,\n} from \"langsmith/schemas\";\nimport { BaseTracer, Run as BaseTracerRun } from \"./base.js\";\nimport { BaseCallbackHandlerInput } from \"../callbacks/base.js\";\nimport { getDefaultLangChainClientSingleton } from \"../singletons/tracer.js\";\nimport { ChatGeneration } from \"../outputs.js\";\nimport { AIMessage } from \"../messages/ai.js\";\nimport { mergeUsageMetadata, UsageMetadata } from \"../messages/metadata.js\";\nimport { TRACE_POLICY_KEY, type TracePolicy } from \"./trace_policy.js\";\n\nexport type { TracePolicy } from \"./trace_policy.js\";\n\nexport interface Run extends BaseRun {\n id: string;\n child_runs: this[];\n child_execution_order: number;\n dotted_order?: string;\n trace_id?: string;\n}\n\nexport interface RunCreate2 extends RunCreate {\n trace_id?: string;\n dotted_order?: string;\n}\n\nexport interface RunUpdate extends BaseRunUpdate {\n events: BaseRun[\"events\"];\n inputs: KVMap;\n trace_id?: string;\n dotted_order?: string;\n}\n\nexport interface LangChainTracerFields extends BaseCallbackHandlerInput {\n exampleId?: string;\n projectName?: string;\n address?: AgentAddress;\n client?: LangSmithTracingClientInterface;\n replicas?: RunTreeConfig[\"replicas\"];\n metadata?: Record<string, unknown>;\n tags?: string[];\n}\n\n/**\n * Keys that should be inherited from `tracerInheritableMetadata` even when\n * the run already has a value for them. This lets nested contexts\n * (e.g. a subagent invoked from inside a parent agent) override a\n * LangSmith-only tracing metadata value that was set by an ancestor.\n *\n * Keep this list very small: every key here loses the default\n * \"first wins\" protection and is always clobbered by the nearest\n * enclosing tracer config. Only keys that are strictly for LangSmith\n * tracing bookkeeping should be added.\n */\nexport const OVERRIDABLE_LANGSMITH_INHERITABLE_METADATA_KEYS = new Set<string>([\n \"ls_agent_type\",\n]);\n\n/**\n * Extract usage_metadata from chat generations.\n *\n * Iterates through generations to find and aggregates all usage_metadata\n * found in chat messages. This is typically present in chat model outputs.\n */\nfunction _getUsageMetadataFromGenerations(\n generations: ChatGeneration[][]\n): UsageMetadata | undefined {\n let output: UsageMetadata | undefined = undefined;\n for (const generationBatch of generations) {\n for (const generation of generationBatch) {\n if (\n AIMessage.isInstance(generation.message) &&\n generation.message.usage_metadata !== undefined\n ) {\n output = mergeUsageMetadata(output, generation.message.usage_metadata);\n }\n }\n }\n return output;\n}\n\nexport class LangChainTracer\n extends BaseTracer\n implements LangChainTracerFields\n{\n name = \"langchain_tracer\";\n\n projectName?: string;\n\n address?: AgentAddress;\n\n exampleId?: string;\n\n client: LangSmithTracingClientInterface;\n\n replicas?: RunTreeConfig[\"replicas\"];\n\n usesRunTreeMap = true;\n\n tracingMetadata?: Record<string, unknown>;\n\n tracingTags: string[] = [];\n\n constructor(protected fields: LangChainTracerFields = {}) {\n super(fields);\n const {\n exampleId,\n projectName,\n address,\n client,\n replicas,\n metadata,\n tags,\n } = fields;\n\n this.projectName = projectName;\n this.address = address;\n this.replicas = replicas;\n this.exampleId = exampleId;\n this.client = client ?? getDefaultLangChainClientSingleton();\n this.tracingMetadata = metadata ? { ...metadata } : undefined;\n this.tracingTags = tags ?? [];\n\n const traceableTree = LangChainTracer.getTraceableRunTree();\n if (traceableTree) {\n this.updateFromRunTree(traceableTree);\n }\n }\n\n protected async persistRun(_run: Run): Promise<void> {\n // empty\n }\n\n async onRunCreate(run: Run): Promise<void> {\n _patchMissingTracingDefaults(this, run);\n if (!run.extra?.lc_defers_inputs) {\n const runTree = this.getRunTreeWithTracingConfig(run.id);\n if (runTree) _applyTracePolicy(runTree);\n await runTree?.postRun();\n }\n }\n\n async onRunUpdate(run: Run): Promise<void> {\n _patchMissingTracingDefaults(this, run);\n const runTree = this.getRunTreeWithTracingConfig(run.id);\n if (runTree) _applyTracePolicy(runTree);\n if (run.extra?.lc_defers_inputs) {\n await runTree?.postRun();\n } else {\n await runTree?.patchRun();\n }\n }\n\n onLLMEnd(run: BaseTracerRun): void {\n // Extract usage_metadata from outputs and store in extra.metadata\n const outputs = run.outputs as\n | { generations?: ChatGeneration[][] }\n | undefined;\n if (outputs?.generations) {\n const usageMetadata = _getUsageMetadataFromGenerations(\n outputs.generations\n );\n if (usageMetadata !== undefined) {\n run.extra = run.extra ?? {};\n const metadata =\n (run.extra.metadata as Record<string, unknown> | undefined) ?? {};\n metadata.usage_metadata = usageMetadata;\n run.extra.metadata = metadata;\n }\n }\n }\n\n copyWithTracingConfig({\n metadata,\n tags,\n }: {\n metadata?: Record<string, unknown>;\n tags?: string[];\n }): LangChainTracer {\n let mergedMetadata: Record<string, unknown> | undefined;\n if (metadata === undefined) {\n mergedMetadata = this.tracingMetadata\n ? { ...this.tracingMetadata }\n : undefined;\n } else if (this.tracingMetadata === undefined) {\n mergedMetadata = { ...metadata };\n } else {\n mergedMetadata = { ...this.tracingMetadata };\n for (const [key, value] of Object.entries(metadata)) {\n // For allowlisted LangSmith-only inheritable metadata keys (e.g.\n // `ls_agent_type`), nested callers are allowed to OVERRIDE the\n // value inherited from an ancestor. For all other keys we keep\n // the existing \"first wins\" behavior so that ancestor-provided\n // tracing metadata is not accidentally clobbered by child runs.\n if (\n !Object.prototype.hasOwnProperty.call(mergedMetadata, key) ||\n OVERRIDABLE_LANGSMITH_INHERITABLE_METADATA_KEYS.has(key)\n ) {\n mergedMetadata[key] = value;\n }\n }\n }\n\n const mergedTags = tags\n ? Array.from(new Set([...this.tracingTags, ...tags]))\n : [...this.tracingTags];\n\n const copied = new LangChainTracer({\n ...this.fields,\n metadata: mergedMetadata,\n tags: mergedTags,\n });\n copied.runMap = this.runMap;\n copied.runTreeMap = this.runTreeMap;\n return copied;\n }\n\n /** @internal */\n _getRunStoreKey(): object {\n return this.runTreeMap;\n }\n\n getRun(id: string): Run | undefined {\n return this.runTreeMap.get(id);\n }\n\n updateFromRunTree(runTree: RunTree) {\n this.runTreeMap.set(runTree.id, runTree);\n let rootRun: RunTree = runTree;\n const visited = new Set<string>();\n while (rootRun.parent_run) {\n if (visited.has(rootRun.id)) break;\n visited.add(rootRun.id);\n\n if (!rootRun.parent_run) break;\n rootRun = rootRun.parent_run as RunTree;\n }\n visited.clear();\n\n const queue = [rootRun];\n while (queue.length > 0) {\n const current = queue.shift();\n if (!current || visited.has(current.id)) continue;\n visited.add(current.id);\n\n this.runTreeMap.set(current.id, current);\n if (current.child_runs) {\n queue.push(...current.child_runs);\n }\n }\n\n this.client = runTree.client ?? this.client;\n this.replicas = runTree.replicas ?? this.replicas;\n if (runTree.project_name || runTree.address) {\n this.projectName = runTree.project_name;\n this.address = runTree.address;\n }\n this.exampleId = runTree.reference_example_id ?? this.exampleId;\n this.fields = {\n ...this.fields,\n client: this.client,\n replicas: this.replicas,\n projectName: this.projectName,\n address: this.address,\n exampleId: this.exampleId,\n };\n }\n\n getRunTreeWithTracingConfig(id: string): RunTree | undefined {\n const runTree = this.runTreeMap.get(id);\n if (!runTree) return undefined;\n\n const config: RunTreeConfig = {\n ...runTree,\n client: this.client as Client,\n project_name: this.projectName,\n address: this.address,\n replicas: this.replicas,\n reference_example_id: this.exampleId,\n tracingEnabled: true,\n };\n\n // Older SDKs merge the config over their defaults, so an explicit undefined\n // would erase the project instead of letting the SDK resolve it.\n if (config.project_name == null) delete config.project_name;\n if (config.address == null) delete config.address;\n return new RunTree(config);\n }\n\n static getTraceableRunTree(): RunTree | undefined {\n try {\n return (\n // The type cast here provides forward compatibility. Old versions of LangSmith will just\n // ignore the permitAbsentRunTree arg.\n (\n getCurrentRunTree as (\n permitAbsentRunTree: boolean\n ) => ReturnType<typeof getCurrentRunTree> | undefined\n )(true)\n );\n } catch {\n return undefined;\n }\n }\n\n static [Symbol.hasInstance](instance: unknown): boolean {\n if (typeof instance !== \"object\" || instance === null) {\n return false;\n }\n const candidate = instance as Record<string, unknown>;\n return (\n \"name\" in candidate &&\n candidate.name === \"langchain_tracer\" &&\n \"copyWithTracingConfig\" in candidate &&\n typeof candidate.copyWithTracingConfig === \"function\" &&\n \"getRunTreeWithTracingConfig\" in candidate &&\n typeof candidate.getRunTreeWithTracingConfig === \"function\"\n );\n }\n}\n\n/**\n * Applies the run's trace policy to the copy that gets sent to LangSmith, and\n * drops the policy from that copy's `extra`.\n */\nfunction _applyTracePolicy(runTree: RunTree): void {\n const { [TRACE_POLICY_KEY]: policy, ...extra } = (runTree.extra ??\n {}) as Record<PropertyKey, unknown>;\n if (policy === undefined) return;\n const { processInputs, processOutputs } = policy as TracePolicy;\n runTree.extra = extra;\n if (processInputs && runTree.inputs !== undefined) {\n runTree.inputs = processInputs(runTree.inputs);\n }\n if (processOutputs && runTree.outputs !== undefined) {\n runTree.outputs = processOutputs(runTree.outputs);\n }\n}\n\nfunction _patchMissingTracingDefaults(tracer: LangChainTracer, run: Run): void {\n if (tracer.tracingMetadata) {\n run.extra ??= {};\n const metadata: Record<string, unknown> =\n (run.extra.metadata as Record<string, unknown> | undefined) ?? {};\n let didPatchMetadata = false;\n for (const [key, value] of Object.entries(tracer.tracingMetadata)) {\n // `OVERRIDABLE_LANGSMITH_INHERITABLE_METADATA_KEYS` are a small, LangSmith-only\n // allowlist that bypasses the \"first wins\" merge so a nested caller\n // (e.g. a subagent) can override a parent-set value.\n if (\n !Object.prototype.hasOwnProperty.call(metadata, key) ||\n OVERRIDABLE_LANGSMITH_INHERITABLE_METADATA_KEYS.has(key)\n ) {\n if (metadata[key] !== value) {\n metadata[key] = value;\n didPatchMetadata = true;\n }\n }\n }\n if (didPatchMetadata) {\n run.extra.metadata = metadata;\n }\n }\n\n if (tracer.tracingTags.length > 0) {\n run.tags = Array.from(\n new Set([...(run.tags ?? []), ...tracer.tracingTags])\n );\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAiEA,MAAa,kEAAkD,IAAI,IAAY,CAC7E,eACF,CAAC;;;;;;;AAQD,SAAS,iCACP,aAC2B;CAC3B,IAAI,SAAoC,KAAA;CACxC,KAAK,MAAM,mBAAmB,aAC5B,KAAK,MAAM,cAAc,iBACvB,IACE,UAAU,WAAW,WAAW,OAAO,KACvC,WAAW,QAAQ,mBAAmB,KAAA,GAEtC,SAAS,mBAAmB,QAAQ,WAAW,QAAQ,cAAc;CAI3E,OAAO;AACT;AAEA,IAAa,kBAAb,MAAa,wBACH,WAEV;CAmBwB;CAlBtB,OAAO;CAEP;CAEA;CAEA;CAEA;CAEA;CAEA,iBAAiB;CAEjB;CAEA,cAAwB,CAAC;CAEzB,YAAY,SAA0C,CAAC,GAAG;EACxD,MAAM,MAAM;EADQ,KAAA,SAAA;EAEpB,MAAM,EACJ,WACA,aACA,SACA,QACA,UACA,UACA,SACE;EAEJ,KAAK,cAAc;EACnB,KAAK,UAAU;EACf,KAAK,WAAW;EAChB,KAAK,YAAY;EACjB,KAAK,SAAS,UAAU,mCAAmC;EAC3D,KAAK,kBAAkB,WAAW,EAAE,GAAG,SAAS,IAAI,KAAA;EACpD,KAAK,cAAc,QAAQ,CAAC;EAE5B,MAAM,gBAAgB,gBAAgB,oBAAoB;EAC1D,IAAI,eACF,KAAK,kBAAkB,aAAa;CAExC;CAEA,MAAgB,WAAW,MAA0B,CAErD;CAEA,MAAM,YAAY,KAAyB;EACzC,6BAA6B,MAAM,GAAG;EACtC,IAAI,CAAC,IAAI,OAAO,k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,OAAO;IAChB,mBAAmB;GACrB;;EAGJ,IAAI,kBACF,IAAI,MAAM,WAAW;CAEzB;CAEA,IAAI,OAAO,YAAY,SAAS,GAC9B,IAAI,OAAO,MAAM,qBACf,IAAI,IAAI,CAAC,GAAI,IAAI,QAAQ,CAAC,GAAI,GAAG,OAAO,WAAW,CAAC,CACtD;AAEJ"}
|
|
1
|
+
{"version":3,"file":"tracer_langchain.js","names":[],"sources":["../../src/tracers/tracer_langchain.ts"],"sourcesContent":["import {\n type Client,\n type AgentAddress,\n type LangSmithTracingClientInterface,\n} from \"langsmith\";\nimport { RunTree, type RunTreeConfig } from \"langsmith/run_trees\";\nimport { getCurrentRunTree } from \"langsmith/singletons/traceable\";\n\nimport {\n BaseRun,\n RunCreate,\n RunUpdate as BaseRunUpdate,\n KVMap,\n} from \"langsmith/schemas\";\nimport { BaseTracer, Run as BaseTracerRun } from \"./base.js\";\nimport { BaseCallbackHandlerInput } from \"../callbacks/base.js\";\nimport { getDefaultLangChainClientSingleton } from \"../singletons/tracer.js\";\nimport { ChatGeneration } from \"../outputs.js\";\nimport { AIMessage } from \"../messages/ai.js\";\nimport { mergeUsageMetadata, UsageMetadata } from \"../messages/metadata.js\";\nimport { TRACE_POLICY_KEY, type TracePolicy } from \"./trace_policy.js\";\n\nexport { omitPayload, type TracePolicy } from \"./trace_policy.js\";\n\nexport interface Run extends BaseRun {\n id: string;\n child_runs: this[];\n child_execution_order: number;\n dotted_order?: string;\n trace_id?: string;\n}\n\nexport interface RunCreate2 extends RunCreate {\n trace_id?: string;\n dotted_order?: string;\n}\n\nexport interface RunUpdate extends BaseRunUpdate {\n events: BaseRun[\"events\"];\n inputs: KVMap;\n trace_id?: string;\n dotted_order?: string;\n}\n\nexport interface LangChainTracerFields extends BaseCallbackHandlerInput {\n exampleId?: string;\n projectName?: string;\n address?: AgentAddress;\n client?: LangSmithTracingClientInterface;\n replicas?: RunTreeConfig[\"replicas\"];\n metadata?: Record<string, unknown>;\n tags?: string[];\n}\n\n/**\n * Keys that should be inherited from `tracerInheritableMetadata` even when\n * the run already has a value for them. This lets nested contexts\n * (e.g. a subagent invoked from inside a parent agent) override a\n * LangSmith-only tracing metadata value that was set by an ancestor.\n *\n * Keep this list very small: every key here loses the default\n * \"first wins\" protection and is always clobbered by the nearest\n * enclosing tracer config. Only keys that are strictly for LangSmith\n * tracing bookkeeping should be added.\n */\nexport const OVERRIDABLE_LANGSMITH_INHERITABLE_METADATA_KEYS = new Set<string>([\n \"ls_agent_type\",\n]);\n\n/**\n * Extract usage_metadata from chat generations.\n *\n * Iterates through generations to find and aggregates all usage_metadata\n * found in chat messages. This is typically present in chat model outputs.\n */\nfunction _getUsageMetadataFromGenerations(\n generations: ChatGeneration[][]\n): UsageMetadata | undefined {\n let output: UsageMetadata | undefined = undefined;\n for (const generationBatch of generations) {\n for (const generation of generationBatch) {\n if (\n AIMessage.isInstance(generation.message) &&\n generation.message.usage_metadata !== undefined\n ) {\n output = mergeUsageMetadata(output, generation.message.usage_metadata);\n }\n }\n }\n return output;\n}\n\nexport class LangChainTracer\n extends BaseTracer\n implements LangChainTracerFields\n{\n name = \"langchain_tracer\";\n\n projectName?: string;\n\n address?: AgentAddress;\n\n exampleId?: string;\n\n client: LangSmithTracingClientInterface;\n\n replicas?: RunTreeConfig[\"replicas\"];\n\n usesRunTreeMap = true;\n\n tracingMetadata?: Record<string, unknown>;\n\n tracingTags: string[] = [];\n\n constructor(protected fields: LangChainTracerFields = {}) {\n super(fields);\n const {\n exampleId,\n projectName,\n address,\n client,\n replicas,\n metadata,\n tags,\n } = fields;\n\n this.projectName = projectName;\n this.address = address;\n this.replicas = replicas;\n this.exampleId = exampleId;\n this.client = client ?? getDefaultLangChainClientSingleton();\n this.tracingMetadata = metadata ? { ...metadata } : undefined;\n this.tracingTags = tags ?? [];\n\n const traceableTree = LangChainTracer.getTraceableRunTree();\n if (traceableTree) {\n this.updateFromRunTree(traceableTree);\n }\n }\n\n protected async persistRun(_run: Run): Promise<void> {\n // empty\n }\n\n async onRunCreate(run: Run): Promise<void> {\n _patchMissingTracingDefaults(this, run);\n if (!run.extra?.lc_defers_inputs) {\n const runTree = this.getRunTreeWithTracingConfig(run.id);\n const policyError = runTree ? this._applyTracePolicy(runTree) : undefined;\n await runTree?.postRun();\n if (policyError !== undefined) throw policyError;\n }\n }\n\n async onRunUpdate(run: Run): Promise<void> {\n _patchMissingTracingDefaults(this, run);\n const runTree = this.getRunTreeWithTracingConfig(run.id);\n const policyError = runTree ? this._applyTracePolicy(runTree) : undefined;\n if (run.extra?.lc_defers_inputs) {\n await runTree?.postRun();\n } else {\n await runTree?.patchRun();\n }\n if (policyError !== undefined) throw policyError;\n }\n\n /**\n * Applies the run's trace policy to the copy that gets sent to LangSmith, and\n * drops the policy from that copy's `extra`. If a processor throws, its\n * payload is dropped and the error is set on the copy and returned, so the\n * run is still sent (and not left pending) before the error is rethrown.\n */\n private _applyTracePolicy(runTree: RunTree): unknown {\n const { [TRACE_POLICY_KEY]: policy, ...extra } = (runTree.extra ??\n {}) as Record<PropertyKey, unknown>;\n if (policy === undefined) return undefined;\n const { processInputs, processOutputs } = policy as TracePolicy;\n runTree.extra = extra;\n let error: unknown;\n if (processInputs && runTree.inputs !== undefined) {\n try {\n runTree.inputs = processInputs(runTree.inputs);\n } catch (e) {\n runTree.inputs = {};\n error = e;\n }\n }\n if (processOutputs && runTree.outputs !== undefined) {\n try {\n runTree.outputs = processOutputs(runTree.outputs);\n } catch (e) {\n runTree.outputs = undefined;\n error ??= e;\n }\n }\n // Keep the run's own error, if it failed; the policy error is still rethrown.\n if (error !== undefined) runTree.error ??= this.stringifyError(error);\n return error;\n }\n\n onLLMEnd(run: BaseTracerRun): void {\n // Extract usage_metadata from outputs and store in extra.metadata\n const outputs = run.outputs as\n | { generations?: ChatGeneration[][] }\n | undefined;\n if (outputs?.generations) {\n const usageMetadata = _getUsageMetadataFromGenerations(\n outputs.generations\n );\n if (usageMetadata !== undefined) {\n run.extra = run.extra ?? {};\n const metadata =\n (run.extra.metadata as Record<string, unknown> | undefined) ?? {};\n metadata.usage_metadata = usageMetadata;\n run.extra.metadata = metadata;\n }\n }\n }\n\n copyWithTracingConfig({\n metadata,\n tags,\n }: {\n metadata?: Record<string, unknown>;\n tags?: string[];\n }): LangChainTracer {\n let mergedMetadata: Record<string, unknown> | undefined;\n if (metadata === undefined) {\n mergedMetadata = this.tracingMetadata\n ? { ...this.tracingMetadata }\n : undefined;\n } else if (this.tracingMetadata === undefined) {\n mergedMetadata = { ...metadata };\n } else {\n mergedMetadata = { ...this.tracingMetadata };\n for (const [key, value] of Object.entries(metadata)) {\n // For allowlisted LangSmith-only inheritable metadata keys (e.g.\n // `ls_agent_type`), nested callers are allowed to OVERRIDE the\n // value inherited from an ancestor. For all other keys we keep\n // the existing \"first wins\" behavior so that ancestor-provided\n // tracing metadata is not accidentally clobbered by child runs.\n if (\n !Object.prototype.hasOwnProperty.call(mergedMetadata, key) ||\n OVERRIDABLE_LANGSMITH_INHERITABLE_METADATA_KEYS.has(key)\n ) {\n mergedMetadata[key] = value;\n }\n }\n }\n\n const mergedTags = tags\n ? Array.from(new Set([...this.tracingTags, ...tags]))\n : [...this.tracingTags];\n\n const copied = new LangChainTracer({\n ...this.fields,\n metadata: mergedMetadata,\n tags: mergedTags,\n });\n copied.runMap = this.runMap;\n copied.runTreeMap = this.runTreeMap;\n return copied;\n }\n\n /** @internal */\n _getRunStoreKey(): object {\n return this.runTreeMap;\n }\n\n getRun(id: string): Run | undefined {\n return this.runTreeMap.get(id);\n }\n\n updateFromRunTree(runTree: RunTree) {\n this.runTreeMap.set(runTree.id, runTree);\n let rootRun: RunTree = runTree;\n const visited = new Set<string>();\n while (rootRun.parent_run) {\n if (visited.has(rootRun.id)) break;\n visited.add(rootRun.id);\n\n if (!rootRun.parent_run) break;\n rootRun = rootRun.parent_run as RunTree;\n }\n visited.clear();\n\n const queue = [rootRun];\n while (queue.length > 0) {\n const current = queue.shift();\n if (!current || visited.has(current.id)) continue;\n visited.add(current.id);\n\n this.runTreeMap.set(current.id, current);\n if (current.child_runs) {\n queue.push(...current.child_runs);\n }\n }\n\n this.client = runTree.client ?? this.client;\n this.replicas = runTree.replicas ?? this.replicas;\n if (runTree.project_name || runTree.address) {\n this.projectName = runTree.project_name;\n this.address = runTree.address;\n }\n this.exampleId = runTree.reference_example_id ?? this.exampleId;\n this.fields = {\n ...this.fields,\n client: this.client,\n replicas: this.replicas,\n projectName: this.projectName,\n address: this.address,\n exampleId: this.exampleId,\n };\n }\n\n getRunTreeWithTracingConfig(id: string): RunTree | undefined {\n const runTree = this.runTreeMap.get(id);\n if (!runTree) return undefined;\n\n const config: RunTreeConfig = {\n ...runTree,\n client: this.client as Client,\n project_name: this.projectName,\n address: this.address,\n replicas: this.replicas,\n reference_example_id: this.exampleId,\n tracingEnabled: true,\n };\n\n // Older SDKs merge the config over their defaults, so an explicit undefined\n // would erase the project instead of letting the SDK resolve it.\n if (config.project_name == null) delete config.project_name;\n if (config.address == null) delete config.address;\n return new RunTree(config);\n }\n\n static getTraceableRunTree(): RunTree | undefined {\n try {\n return (\n // The type cast here provides forward compatibility. Old versions of LangSmith will just\n // ignore the permitAbsentRunTree arg.\n (\n getCurrentRunTree as (\n permitAbsentRunTree: boolean\n ) => ReturnType<typeof getCurrentRunTree> | undefined\n )(true)\n );\n } catch {\n return undefined;\n }\n }\n\n static [Symbol.hasInstance](instance: unknown): boolean {\n if (typeof instance !== \"object\" || instance === null) {\n return false;\n }\n const candidate = instance as Record<string, unknown>;\n return (\n \"name\" in candidate &&\n candidate.name === \"langchain_tracer\" &&\n \"copyWithTracingConfig\" in candidate &&\n typeof candidate.copyWithTracingConfig === \"function\" &&\n \"getRunTreeWithTracingConfig\" in candidate &&\n typeof candidate.getRunTreeWithTracingConfig === \"function\"\n );\n }\n}\n\nfunction _patchMissingTracingDefaults(tracer: LangChainTracer, run: Run): void {\n if (tracer.tracingMetadata) {\n run.extra ??= {};\n const metadata: Record<string, unknown> =\n (run.extra.metadata as Record<string, unknown> | undefined) ?? {};\n let didPatchMetadata = false;\n for (const [key, value] of Object.entries(tracer.tracingMetadata)) {\n // `OVERRIDABLE_LANGSMITH_INHERITABLE_METADATA_KEYS` are a small, LangSmith-only\n // allowlist that bypasses the \"first wins\" merge so a nested caller\n // (e.g. a subagent) can override a parent-set value.\n if (\n !Object.prototype.hasOwnProperty.call(metadata, key) ||\n OVERRIDABLE_LANGSMITH_INHERITABLE_METADATA_KEYS.has(key)\n ) {\n if (metadata[key] !== value) {\n metadata[key] = value;\n didPatchMetadata = true;\n }\n }\n }\n if (didPatchMetadata) {\n run.extra.metadata = metadata;\n }\n }\n\n if (tracer.tracingTags.length > 0) {\n run.tags = Array.from(\n new Set([...(run.tags ?? []), ...tracer.tracingTags])\n );\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAiEA,MAAa,kEAAkD,IAAI,IAAY,CAC7E,eACF,CAAC;;;;;;;AAQD,SAAS,iCACP,aAC2B;CAC3B,IAAI,SAAoC,KAAA;CACxC,KAAK,MAAM,mBAAmB,aAC5B,KAAK,MAAM,cAAc,iBACvB,IACE,UAAU,WAAW,WAAW,OAAO,KACvC,WAAW,QAAQ,mBAAmB,KAAA,GAEtC,SAAS,mBAAmB,QAAQ,WAAW,QAAQ,cAAc;CAI3E,OAAO;AACT;AAEA,IAAa,kBAAb,MAAa,wBACH,WAEV;CAmBwB;CAlBtB,OAAO;CAEP;CAEA;CAEA;CAEA;CAEA;CAEA,iBAAiB;CAEjB;CAEA,cAAwB,CAAC;CAEzB,YAAY,SAA0C,CAAC,GAAG;EACxD,MAAM,MAAM;EADQ,KAAA,SAAA;EAEpB,MAAM,EACJ,WACA,aACA,SACA,QACA,UACA,UACA,SACE;EAEJ,KAAK,cAAc;EACnB,KAAK,UAAU;EACf,KAAK,WAAW;EAChB,KAAK,YAAY;EACjB,KAAK,SAAS,UAAU,mCAAmC;EAC3D,KAAK,kBAAkB,WAAW,EAAE,GAAG,SAAS,IAAI,KAA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