@agent-inspect/langchain 6.14.0 → 6.14.2
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/README.md +1 -0
- package/dist/index.cjs +112 -31
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.mjs +112 -31
- package/dist/index.mjs.map +1 -1
- package/package.json +11 -3
package/dist/index.d.cts
CHANGED
|
@@ -98,6 +98,7 @@ declare class AgentInspectCallback extends BaseCallbackHandler {
|
|
|
98
98
|
pendingRelationshipCount: number;
|
|
99
99
|
knownRelationshipCount: number;
|
|
100
100
|
syntheticGroupCount: number;
|
|
101
|
+
selfParentRejectedCount: number;
|
|
101
102
|
envelopeStarted: boolean;
|
|
102
103
|
finalized: boolean;
|
|
103
104
|
completionGeneration: number;
|
|
@@ -170,6 +171,7 @@ interface AdapterPersistenceDiagnostics {
|
|
|
170
171
|
readonly pendingRelationshipCount: number;
|
|
171
172
|
readonly knownRelationshipCount: number;
|
|
172
173
|
readonly syntheticGroupCount: number;
|
|
174
|
+
readonly selfParentRejectedCount: number;
|
|
173
175
|
readonly envelopeStarted: boolean;
|
|
174
176
|
readonly finalized: boolean;
|
|
175
177
|
readonly completionGeneration: number;
|
package/dist/index.d.ts
CHANGED
|
@@ -98,6 +98,7 @@ declare class AgentInspectCallback extends BaseCallbackHandler {
|
|
|
98
98
|
pendingRelationshipCount: number;
|
|
99
99
|
knownRelationshipCount: number;
|
|
100
100
|
syntheticGroupCount: number;
|
|
101
|
+
selfParentRejectedCount: number;
|
|
101
102
|
envelopeStarted: boolean;
|
|
102
103
|
finalized: boolean;
|
|
103
104
|
completionGeneration: number;
|
|
@@ -170,6 +171,7 @@ interface AdapterPersistenceDiagnostics {
|
|
|
170
171
|
readonly pendingRelationshipCount: number;
|
|
171
172
|
readonly knownRelationshipCount: number;
|
|
172
173
|
readonly syntheticGroupCount: number;
|
|
174
|
+
readonly selfParentRejectedCount: number;
|
|
173
175
|
readonly envelopeStarted: boolean;
|
|
174
176
|
readonly finalized: boolean;
|
|
175
177
|
readonly completionGeneration: number;
|
package/dist/index.mjs
CHANGED
|
@@ -467,6 +467,11 @@ function isSemanticParentLabel(parentLcRunId) {
|
|
|
467
467
|
if (WELL_KNOWN_SEMANTIC_PARENTS.has(parentLcRunId)) return true;
|
|
468
468
|
return parentLcRunId.startsWith("__") && parentLcRunId.endsWith("__");
|
|
469
469
|
}
|
|
470
|
+
function excludeSelf(stepId, excludeStepId) {
|
|
471
|
+
if (!stepId) return void 0;
|
|
472
|
+
if (excludeStepId && stepId === excludeStepId) return void 0;
|
|
473
|
+
return stepId;
|
|
474
|
+
}
|
|
470
475
|
var LANGGRAPH_PARENT_KEYS = [
|
|
471
476
|
"handoffFrom",
|
|
472
477
|
"taskId",
|
|
@@ -479,10 +484,11 @@ function langGraphRecord(attributes) {
|
|
|
479
484
|
if (typeof lg !== "object" || lg === null || Array.isArray(lg)) return void 0;
|
|
480
485
|
return lg;
|
|
481
486
|
}
|
|
482
|
-
function resolveParentRelationship(input, lookup) {
|
|
487
|
+
function resolveParentRelationship(input, lookup, context = {}) {
|
|
483
488
|
const parentLcRunId = input.parentLcRunId;
|
|
489
|
+
const excludeStepId = context.excludeStepId;
|
|
484
490
|
if (parentLcRunId) {
|
|
485
|
-
const exact = lookup.exactStepByLcRunId(parentLcRunId);
|
|
491
|
+
const exact = excludeSelf(lookup.exactStepByLcRunId(parentLcRunId), excludeStepId);
|
|
486
492
|
if (exact) {
|
|
487
493
|
return {
|
|
488
494
|
parentStepId: exact,
|
|
@@ -497,8 +503,14 @@ function resolveParentRelationship(input, lookup) {
|
|
|
497
503
|
if (key !== "handoffFrom" && key !== "checkpointNamespace") continue;
|
|
498
504
|
const raw = lg[key];
|
|
499
505
|
if (typeof raw !== "string" || !raw.trim()) continue;
|
|
500
|
-
const stepId =
|
|
501
|
-
|
|
506
|
+
const stepId = excludeSelf(
|
|
507
|
+
lookup.uniqueStepByLangGraphKey(key === "handoffFrom" ? "taskId" : key, raw),
|
|
508
|
+
excludeStepId
|
|
509
|
+
);
|
|
510
|
+
const matched = stepId ?? excludeSelf(
|
|
511
|
+
key === "handoffFrom" ? lookup.uniqueStepByLangGraphKey("nodeName", raw) ?? lookup.uniqueStepByLangGraphKey("nodeId", raw) : void 0,
|
|
512
|
+
excludeStepId
|
|
513
|
+
);
|
|
502
514
|
if (matched) {
|
|
503
515
|
return {
|
|
504
516
|
parentStepId: matched,
|
|
@@ -510,7 +522,10 @@ function resolveParentRelationship(input, lookup) {
|
|
|
510
522
|
}
|
|
511
523
|
}
|
|
512
524
|
if (parentLcRunId && isSemanticParentLabel(parentLcRunId)) {
|
|
513
|
-
const semantic =
|
|
525
|
+
const semantic = excludeSelf(
|
|
526
|
+
lookup.uniqueStepBySemanticLabel(parentLcRunId),
|
|
527
|
+
excludeStepId
|
|
528
|
+
);
|
|
514
529
|
if (semantic) {
|
|
515
530
|
return {
|
|
516
531
|
parentStepId: semantic,
|
|
@@ -538,6 +553,30 @@ function resolveParentRelationship(input, lookup) {
|
|
|
538
553
|
parentMapping: "exact"
|
|
539
554
|
};
|
|
540
555
|
}
|
|
556
|
+
function rejectSelfParentResolution(resolution, stepId, parentLcRunId) {
|
|
557
|
+
if (resolution.parentStepId !== stepId) return resolution;
|
|
558
|
+
return {
|
|
559
|
+
confidence: "unresolved",
|
|
560
|
+
parentMapping: "unresolved",
|
|
561
|
+
unresolvedParentRunId: parentLcRunId ?? resolution.unresolvedParentRunId,
|
|
562
|
+
...resolution.semanticParentLabel ? { semanticParentLabel: resolution.semanticParentLabel } : {}
|
|
563
|
+
};
|
|
564
|
+
}
|
|
565
|
+
var AI_LANGGRAPH_SELF_PARENT_REJECTED = "AI_LANGGRAPH_SELF_PARENT_REJECTED";
|
|
566
|
+
function applySelfParentCaptureInvariant(stepId, parentStepId, metadata, originalParentRunId) {
|
|
567
|
+
if (!parentStepId || parentStepId !== stepId) {
|
|
568
|
+
return { parentStepId, rejected: false };
|
|
569
|
+
}
|
|
570
|
+
metadata.parentMapping = "self-parent-rejected";
|
|
571
|
+
metadata.parentConfidence = "unresolved";
|
|
572
|
+
metadata.relationshipWarning = "self-parent";
|
|
573
|
+
metadata.diagnosticCode = AI_LANGGRAPH_SELF_PARENT_REJECTED;
|
|
574
|
+
if (originalParentRunId && originalParentRunId.trim()) {
|
|
575
|
+
metadata.originalParentRunId = originalParentRunId.slice(0, 128);
|
|
576
|
+
}
|
|
577
|
+
delete metadata.parentCorrelatedVia;
|
|
578
|
+
return { parentStepId: void 0, rejected: true };
|
|
579
|
+
}
|
|
541
580
|
function applyParentResolutionMetadata(metadata, resolution) {
|
|
542
581
|
const hasParentSignal = Boolean(resolution.parentStepId) || Boolean(resolution.unresolvedParentRunId) || Boolean(resolution.semanticParentLabel) || Boolean(resolution.correlatedVia);
|
|
543
582
|
if (!hasParentSignal) return;
|
|
@@ -598,6 +637,7 @@ var LangChainTracePersistence = class {
|
|
|
598
637
|
/** Count of unresolved semantic-parent children seen per label (this invocation). */
|
|
599
638
|
#semanticParentCounts = /* @__PURE__ */ new Map();
|
|
600
639
|
#lateEventCount = 0;
|
|
640
|
+
#selfParentRejectedCount = 0;
|
|
601
641
|
constructor(options = {}) {
|
|
602
642
|
const inContext = hasActiveContext();
|
|
603
643
|
this.#standalone = !inContext;
|
|
@@ -635,12 +675,25 @@ var LangChainTracePersistence = class {
|
|
|
635
675
|
pendingRelationshipCount: this.#lifecycle.pendingRelationships.length,
|
|
636
676
|
knownRelationshipCount: this.#lifecycle.knownRelationships.size,
|
|
637
677
|
syntheticGroupCount: this.#syntheticByLabel.size,
|
|
678
|
+
selfParentRejectedCount: this.#selfParentRejectedCount,
|
|
638
679
|
envelopeStarted: this.#lifecycle.envelopeStarted,
|
|
639
680
|
finalized: this.#lifecycle.finalized,
|
|
640
681
|
completionGeneration: this.#lifecycle.completionGeneration,
|
|
641
682
|
hasTerminalError: Boolean(this.#lifecycle.terminalError)
|
|
642
683
|
};
|
|
643
684
|
}
|
|
685
|
+
#parentIdForPersist(stepId, resolution, metadata, originalParentRunId) {
|
|
686
|
+
const guarded = applySelfParentCaptureInvariant(
|
|
687
|
+
stepId,
|
|
688
|
+
resolution.parentStepId,
|
|
689
|
+
metadata,
|
|
690
|
+
originalParentRunId ?? resolution.unresolvedParentRunId
|
|
691
|
+
);
|
|
692
|
+
if (guarded.rejected) {
|
|
693
|
+
this.#selfParentRejectedCount += 1;
|
|
694
|
+
}
|
|
695
|
+
return guarded.parentStepId;
|
|
696
|
+
}
|
|
644
697
|
/**
|
|
645
698
|
* Start a fresh envelope after a prior invocation finalized (callback reuse).
|
|
646
699
|
* Allocates a new run id unless still nested in an inspectRun context.
|
|
@@ -653,6 +706,7 @@ var LangChainTracePersistence = class {
|
|
|
653
706
|
resetInvocationState(this.#lifecycle, this.#runId);
|
|
654
707
|
this.#clearStepIndexes();
|
|
655
708
|
this.#lateEventCount = 0;
|
|
709
|
+
this.#selfParentRejectedCount = 0;
|
|
656
710
|
return;
|
|
657
711
|
}
|
|
658
712
|
}
|
|
@@ -660,11 +714,13 @@ var LangChainTracePersistence = class {
|
|
|
660
714
|
resetInvocationState(this.#lifecycle, this.#runId);
|
|
661
715
|
this.#clearStepIndexes();
|
|
662
716
|
this.#lateEventCount = 0;
|
|
717
|
+
this.#selfParentRejectedCount = 0;
|
|
663
718
|
}
|
|
664
719
|
reset() {
|
|
665
720
|
resetInvocationState(this.#lifecycle);
|
|
666
721
|
this.#clearStepIndexes();
|
|
667
722
|
this.#lateEventCount = 0;
|
|
723
|
+
this.#selfParentRejectedCount = 0;
|
|
668
724
|
}
|
|
669
725
|
#clearStepIndexes() {
|
|
670
726
|
this.#lcToStepId.clear();
|
|
@@ -712,8 +768,8 @@ var LangChainTracePersistence = class {
|
|
|
712
768
|
}
|
|
713
769
|
}
|
|
714
770
|
}
|
|
715
|
-
#resolveParent(parentLcRunId, attributes) {
|
|
716
|
-
|
|
771
|
+
#resolveParent(parentLcRunId, attributes, excludeStepId) {
|
|
772
|
+
const resolution = resolveParentRelationship(
|
|
717
773
|
{ parentLcRunId, attributes },
|
|
718
774
|
{
|
|
719
775
|
exactStepByLcRunId: (lcRunId) => this.#lcToStepId.get(lcRunId),
|
|
@@ -725,8 +781,10 @@ var LangChainTracePersistence = class {
|
|
|
725
781
|
const hit = this.#semanticLabelIndex.get(label);
|
|
726
782
|
return hit === null || hit === void 0 ? void 0 : hit;
|
|
727
783
|
}
|
|
728
|
-
}
|
|
784
|
+
},
|
|
785
|
+
excludeStepId ? { excludeStepId } : {}
|
|
729
786
|
);
|
|
787
|
+
return excludeStepId ? rejectSelfParentResolution(resolution, excludeStepId, parentLcRunId) : resolution;
|
|
730
788
|
}
|
|
731
789
|
/**
|
|
732
790
|
* When ≥2 steps share the same unresolved semantic parent label, emit one
|
|
@@ -804,8 +862,10 @@ var LangChainTracePersistence = class {
|
|
|
804
862
|
try {
|
|
805
863
|
this.#prepareForStart();
|
|
806
864
|
const stepId = createStepId();
|
|
807
|
-
this.#
|
|
808
|
-
|
|
865
|
+
const resolution = await this.#maybeAttachSyntheticGroup(
|
|
866
|
+
this.#resolveParent(params.lcParentRunId, params.attributes, stepId),
|
|
867
|
+
params.startTime
|
|
868
|
+
);
|
|
809
869
|
beginCallbackRun(this.#lifecycle, {
|
|
810
870
|
lcRunId: params.lcRunId,
|
|
811
871
|
parentLcRunId: params.lcParentRunId,
|
|
@@ -816,25 +876,29 @@ var LangChainTracePersistence = class {
|
|
|
816
876
|
if (this.#standalone && !this.#lifecycle.envelopeStarted) {
|
|
817
877
|
await this.#ensureRunStarted(params.startTime, params.attributes);
|
|
818
878
|
}
|
|
819
|
-
const resolution = await this.#maybeAttachSyntheticGroup(
|
|
820
|
-
this.#resolveParent(params.lcParentRunId, params.attributes),
|
|
821
|
-
params.startTime
|
|
822
|
-
);
|
|
823
879
|
const metadata = toStepMetadata(params.attributes);
|
|
824
880
|
applyParentResolutionMetadata(metadata, resolution);
|
|
881
|
+
const parentId = this.#parentIdForPersist(
|
|
882
|
+
stepId,
|
|
883
|
+
resolution,
|
|
884
|
+
metadata,
|
|
885
|
+
params.lcParentRunId
|
|
886
|
+
);
|
|
825
887
|
const event = {
|
|
826
888
|
schemaVersion: "0.1",
|
|
827
889
|
event: "step_started",
|
|
828
890
|
timestamp: params.startTime,
|
|
829
891
|
runId: this.#runId,
|
|
830
892
|
stepId,
|
|
831
|
-
...
|
|
893
|
+
...parentId ? { parentId } : {},
|
|
832
894
|
name: params.name,
|
|
833
895
|
type: kindToStepType(params.kind),
|
|
834
896
|
startTime: params.startTime,
|
|
835
897
|
metadata
|
|
836
898
|
};
|
|
899
|
+
this.#lcToStepId.set(params.lcRunId, stepId);
|
|
837
900
|
await this.#write(event);
|
|
901
|
+
this.#registerStepIndexes(stepId, params.name, params.attributes);
|
|
838
902
|
} catch (err) {
|
|
839
903
|
this.#warn(err);
|
|
840
904
|
}
|
|
@@ -852,30 +916,38 @@ var LangChainTracePersistence = class {
|
|
|
852
916
|
return;
|
|
853
917
|
}
|
|
854
918
|
stepId = createStepId();
|
|
855
|
-
this.#lcToStepId.set(params.lcRunId, stepId);
|
|
856
919
|
const synthName = String(params.completionAttributes.name ?? "llm:llm");
|
|
857
|
-
|
|
920
|
+
const startTime = params.endTime - (params.durationMs ?? 0);
|
|
921
|
+
const resolution = await this.#maybeAttachSyntheticGroup(
|
|
922
|
+
this.#resolveParent(
|
|
923
|
+
params.lcParentRunId,
|
|
924
|
+
params.completionAttributes,
|
|
925
|
+
stepId
|
|
926
|
+
),
|
|
927
|
+
startTime
|
|
928
|
+
);
|
|
858
929
|
beginCallbackRun(this.#lifecycle, {
|
|
859
930
|
lcRunId: params.lcRunId,
|
|
860
931
|
parentLcRunId: params.lcParentRunId,
|
|
861
|
-
startedAt:
|
|
932
|
+
startedAt: startTime,
|
|
862
933
|
kind: params.completionAttributes.kind ?? "LLM",
|
|
863
934
|
stepId
|
|
864
935
|
});
|
|
865
|
-
const startTime = params.endTime - (params.durationMs ?? 0);
|
|
866
|
-
const resolution = await this.#maybeAttachSyntheticGroup(
|
|
867
|
-
this.#resolveParent(params.lcParentRunId, params.completionAttributes),
|
|
868
|
-
startTime
|
|
869
|
-
);
|
|
870
936
|
const metadata = toStepMetadata(params.completionAttributes);
|
|
871
937
|
applyParentResolutionMetadata(metadata, resolution);
|
|
938
|
+
const parentId = this.#parentIdForPersist(
|
|
939
|
+
stepId,
|
|
940
|
+
resolution,
|
|
941
|
+
metadata,
|
|
942
|
+
params.lcParentRunId
|
|
943
|
+
);
|
|
872
944
|
const started = {
|
|
873
945
|
schemaVersion: "0.1",
|
|
874
946
|
event: "step_started",
|
|
875
947
|
timestamp: startTime,
|
|
876
948
|
runId: this.#runId,
|
|
877
949
|
stepId,
|
|
878
|
-
...
|
|
950
|
+
...parentId ? { parentId } : {},
|
|
879
951
|
name: synthName,
|
|
880
952
|
type: kindToStepType(
|
|
881
953
|
params.completionAttributes.kind ?? "LLM"
|
|
@@ -886,7 +958,9 @@ var LangChainTracePersistence = class {
|
|
|
886
958
|
if (this.#standalone && !this.#lifecycle.envelopeStarted) {
|
|
887
959
|
await this.#ensureRunStarted(startTime, params.completionAttributes);
|
|
888
960
|
}
|
|
961
|
+
this.#lcToStepId.set(params.lcRunId, stepId);
|
|
889
962
|
await this.#write(started);
|
|
963
|
+
this.#registerStepIndexes(stepId, synthName, params.completionAttributes);
|
|
890
964
|
}
|
|
891
965
|
if (!stepId) return;
|
|
892
966
|
const durationMs = typeof params.durationMs === "number" && Number.isFinite(params.durationMs) ? Math.max(0, Math.floor(params.durationMs)) : Math.max(
|
|
@@ -922,8 +996,10 @@ var LangChainTracePersistence = class {
|
|
|
922
996
|
try {
|
|
923
997
|
this.#prepareForStart();
|
|
924
998
|
const stepId = createStepId();
|
|
925
|
-
this.#
|
|
926
|
-
|
|
999
|
+
const resolution = await this.#maybeAttachSyntheticGroup(
|
|
1000
|
+
this.#resolveParent(params.lcParentRunId, params.attributes, stepId),
|
|
1001
|
+
params.timestamp
|
|
1002
|
+
);
|
|
927
1003
|
beginCallbackRun(this.#lifecycle, {
|
|
928
1004
|
lcRunId: params.lcRunId,
|
|
929
1005
|
parentLcRunId: params.lcParentRunId,
|
|
@@ -934,25 +1010,29 @@ var LangChainTracePersistence = class {
|
|
|
934
1010
|
if (this.#standalone && !this.#lifecycle.envelopeStarted) {
|
|
935
1011
|
await this.#ensureRunStarted(params.timestamp, params.attributes);
|
|
936
1012
|
}
|
|
937
|
-
const resolution = await this.#maybeAttachSyntheticGroup(
|
|
938
|
-
this.#resolveParent(params.lcParentRunId, params.attributes),
|
|
939
|
-
params.timestamp
|
|
940
|
-
);
|
|
941
1013
|
const metadata = toStepMetadata(params.attributes);
|
|
942
1014
|
applyParentResolutionMetadata(metadata, resolution);
|
|
1015
|
+
const parentId = this.#parentIdForPersist(
|
|
1016
|
+
stepId,
|
|
1017
|
+
resolution,
|
|
1018
|
+
metadata,
|
|
1019
|
+
params.lcParentRunId
|
|
1020
|
+
);
|
|
943
1021
|
const started = {
|
|
944
1022
|
schemaVersion: "0.1",
|
|
945
1023
|
event: "step_started",
|
|
946
1024
|
timestamp: params.timestamp,
|
|
947
1025
|
runId: this.#runId,
|
|
948
1026
|
stepId,
|
|
949
|
-
...
|
|
1027
|
+
...parentId ? { parentId } : {},
|
|
950
1028
|
name: params.name,
|
|
951
1029
|
type: kindToStepType(params.kind),
|
|
952
1030
|
startTime: params.timestamp,
|
|
953
1031
|
metadata
|
|
954
1032
|
};
|
|
1033
|
+
this.#lcToStepId.set(params.lcRunId, stepId);
|
|
955
1034
|
await this.#write(started);
|
|
1035
|
+
this.#registerStepIndexes(stepId, params.name, params.attributes);
|
|
956
1036
|
const completed = {
|
|
957
1037
|
schemaVersion: "0.1",
|
|
958
1038
|
event: "step_completed",
|
|
@@ -1198,6 +1278,7 @@ var AgentInspectCallback = class extends BaseCallbackHandler {
|
|
|
1198
1278
|
pendingRelationshipCount: 0,
|
|
1199
1279
|
knownRelationshipCount: 0,
|
|
1200
1280
|
syntheticGroupCount: 0,
|
|
1281
|
+
selfParentRejectedCount: 0,
|
|
1201
1282
|
envelopeStarted: false,
|
|
1202
1283
|
finalized: false,
|
|
1203
1284
|
completionGeneration: 0,
|