@agent-inspect/langchain 6.14.1 → 6.15.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +131 -31
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.mjs +131 -31
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.d.cts
CHANGED
|
@@ -98,6 +98,8 @@ declare class AgentInspectCallback extends BaseCallbackHandler {
|
|
|
98
98
|
pendingRelationshipCount: number;
|
|
99
99
|
knownRelationshipCount: number;
|
|
100
100
|
syntheticGroupCount: number;
|
|
101
|
+
selfParentRejectedCount: number;
|
|
102
|
+
ambiguousRelationshipCount: number;
|
|
101
103
|
envelopeStarted: boolean;
|
|
102
104
|
finalized: boolean;
|
|
103
105
|
completionGeneration: number;
|
|
@@ -170,6 +172,8 @@ interface AdapterPersistenceDiagnostics {
|
|
|
170
172
|
readonly pendingRelationshipCount: number;
|
|
171
173
|
readonly knownRelationshipCount: number;
|
|
172
174
|
readonly syntheticGroupCount: number;
|
|
175
|
+
readonly selfParentRejectedCount: number;
|
|
176
|
+
readonly ambiguousRelationshipCount: number;
|
|
173
177
|
readonly envelopeStarted: boolean;
|
|
174
178
|
readonly finalized: boolean;
|
|
175
179
|
readonly completionGeneration: number;
|
package/dist/index.d.ts
CHANGED
|
@@ -98,6 +98,8 @@ declare class AgentInspectCallback extends BaseCallbackHandler {
|
|
|
98
98
|
pendingRelationshipCount: number;
|
|
99
99
|
knownRelationshipCount: number;
|
|
100
100
|
syntheticGroupCount: number;
|
|
101
|
+
selfParentRejectedCount: number;
|
|
102
|
+
ambiguousRelationshipCount: number;
|
|
101
103
|
envelopeStarted: boolean;
|
|
102
104
|
finalized: boolean;
|
|
103
105
|
completionGeneration: number;
|
|
@@ -170,6 +172,8 @@ interface AdapterPersistenceDiagnostics {
|
|
|
170
172
|
readonly pendingRelationshipCount: number;
|
|
171
173
|
readonly knownRelationshipCount: number;
|
|
172
174
|
readonly syntheticGroupCount: number;
|
|
175
|
+
readonly selfParentRejectedCount: number;
|
|
176
|
+
readonly ambiguousRelationshipCount: number;
|
|
173
177
|
readonly envelopeStarted: boolean;
|
|
174
178
|
readonly finalized: boolean;
|
|
175
179
|
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,41 @@ 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
|
+
var AI_LANGGRAPH_RELATIONSHIP_AMBIGUOUS = "AI_LANGGRAPH_RELATIONSHIP_AMBIGUOUS";
|
|
567
|
+
function applySelfParentCaptureInvariant(stepId, parentStepId, metadata, originalParentRunId) {
|
|
568
|
+
if (!parentStepId || parentStepId !== stepId) {
|
|
569
|
+
return { parentStepId, rejected: false };
|
|
570
|
+
}
|
|
571
|
+
metadata.parentMapping = "self-parent-rejected";
|
|
572
|
+
metadata.parentConfidence = "unresolved";
|
|
573
|
+
metadata.relationshipWarning = "self-parent";
|
|
574
|
+
metadata.diagnosticCode = AI_LANGGRAPH_SELF_PARENT_REJECTED;
|
|
575
|
+
if (originalParentRunId && originalParentRunId.trim()) {
|
|
576
|
+
metadata.originalParentRunId = originalParentRunId.slice(0, 128);
|
|
577
|
+
}
|
|
578
|
+
delete metadata.parentCorrelatedVia;
|
|
579
|
+
return { parentStepId: void 0, rejected: true };
|
|
580
|
+
}
|
|
581
|
+
function applyAmbiguousScaffoldingDiagnostic(resolution, metadata) {
|
|
582
|
+
if (resolution.parentStepId) return false;
|
|
583
|
+
if (resolution.parentMapping !== "unresolved") return false;
|
|
584
|
+
if (metadata.diagnosticCode === AI_LANGGRAPH_SELF_PARENT_REJECTED) return false;
|
|
585
|
+
metadata.diagnosticCode = AI_LANGGRAPH_RELATIONSHIP_AMBIGUOUS;
|
|
586
|
+
if (typeof metadata.relationshipWarning !== "string") {
|
|
587
|
+
metadata.relationshipWarning = "ambiguous-root";
|
|
588
|
+
}
|
|
589
|
+
return true;
|
|
590
|
+
}
|
|
541
591
|
function applyParentResolutionMetadata(metadata, resolution) {
|
|
542
592
|
const hasParentSignal = Boolean(resolution.parentStepId) || Boolean(resolution.unresolvedParentRunId) || Boolean(resolution.semanticParentLabel) || Boolean(resolution.correlatedVia);
|
|
543
593
|
if (!hasParentSignal) return;
|
|
@@ -598,6 +648,8 @@ var LangChainTracePersistence = class {
|
|
|
598
648
|
/** Count of unresolved semantic-parent children seen per label (this invocation). */
|
|
599
649
|
#semanticParentCounts = /* @__PURE__ */ new Map();
|
|
600
650
|
#lateEventCount = 0;
|
|
651
|
+
#selfParentRejectedCount = 0;
|
|
652
|
+
#ambiguousRelationshipCount = 0;
|
|
601
653
|
constructor(options = {}) {
|
|
602
654
|
const inContext = hasActiveContext();
|
|
603
655
|
this.#standalone = !inContext;
|
|
@@ -635,12 +687,28 @@ var LangChainTracePersistence = class {
|
|
|
635
687
|
pendingRelationshipCount: this.#lifecycle.pendingRelationships.length,
|
|
636
688
|
knownRelationshipCount: this.#lifecycle.knownRelationships.size,
|
|
637
689
|
syntheticGroupCount: this.#syntheticByLabel.size,
|
|
690
|
+
selfParentRejectedCount: this.#selfParentRejectedCount,
|
|
691
|
+
ambiguousRelationshipCount: this.#ambiguousRelationshipCount,
|
|
638
692
|
envelopeStarted: this.#lifecycle.envelopeStarted,
|
|
639
693
|
finalized: this.#lifecycle.finalized,
|
|
640
694
|
completionGeneration: this.#lifecycle.completionGeneration,
|
|
641
695
|
hasTerminalError: Boolean(this.#lifecycle.terminalError)
|
|
642
696
|
};
|
|
643
697
|
}
|
|
698
|
+
#parentIdForPersist(stepId, resolution, metadata, originalParentRunId) {
|
|
699
|
+
const guarded = applySelfParentCaptureInvariant(
|
|
700
|
+
stepId,
|
|
701
|
+
resolution.parentStepId,
|
|
702
|
+
metadata,
|
|
703
|
+
originalParentRunId ?? resolution.unresolvedParentRunId
|
|
704
|
+
);
|
|
705
|
+
if (guarded.rejected) {
|
|
706
|
+
this.#selfParentRejectedCount += 1;
|
|
707
|
+
} else if (applyAmbiguousScaffoldingDiagnostic(resolution, metadata)) {
|
|
708
|
+
this.#ambiguousRelationshipCount += 1;
|
|
709
|
+
}
|
|
710
|
+
return guarded.parentStepId;
|
|
711
|
+
}
|
|
644
712
|
/**
|
|
645
713
|
* Start a fresh envelope after a prior invocation finalized (callback reuse).
|
|
646
714
|
* Allocates a new run id unless still nested in an inspectRun context.
|
|
@@ -653,6 +721,8 @@ var LangChainTracePersistence = class {
|
|
|
653
721
|
resetInvocationState(this.#lifecycle, this.#runId);
|
|
654
722
|
this.#clearStepIndexes();
|
|
655
723
|
this.#lateEventCount = 0;
|
|
724
|
+
this.#selfParentRejectedCount = 0;
|
|
725
|
+
this.#ambiguousRelationshipCount = 0;
|
|
656
726
|
return;
|
|
657
727
|
}
|
|
658
728
|
}
|
|
@@ -660,11 +730,15 @@ var LangChainTracePersistence = class {
|
|
|
660
730
|
resetInvocationState(this.#lifecycle, this.#runId);
|
|
661
731
|
this.#clearStepIndexes();
|
|
662
732
|
this.#lateEventCount = 0;
|
|
733
|
+
this.#selfParentRejectedCount = 0;
|
|
734
|
+
this.#ambiguousRelationshipCount = 0;
|
|
663
735
|
}
|
|
664
736
|
reset() {
|
|
665
737
|
resetInvocationState(this.#lifecycle);
|
|
666
738
|
this.#clearStepIndexes();
|
|
667
739
|
this.#lateEventCount = 0;
|
|
740
|
+
this.#selfParentRejectedCount = 0;
|
|
741
|
+
this.#ambiguousRelationshipCount = 0;
|
|
668
742
|
}
|
|
669
743
|
#clearStepIndexes() {
|
|
670
744
|
this.#lcToStepId.clear();
|
|
@@ -712,8 +786,8 @@ var LangChainTracePersistence = class {
|
|
|
712
786
|
}
|
|
713
787
|
}
|
|
714
788
|
}
|
|
715
|
-
#resolveParent(parentLcRunId, attributes) {
|
|
716
|
-
|
|
789
|
+
#resolveParent(parentLcRunId, attributes, excludeStepId) {
|
|
790
|
+
const resolution = resolveParentRelationship(
|
|
717
791
|
{ parentLcRunId, attributes },
|
|
718
792
|
{
|
|
719
793
|
exactStepByLcRunId: (lcRunId) => this.#lcToStepId.get(lcRunId),
|
|
@@ -725,8 +799,10 @@ var LangChainTracePersistence = class {
|
|
|
725
799
|
const hit = this.#semanticLabelIndex.get(label);
|
|
726
800
|
return hit === null || hit === void 0 ? void 0 : hit;
|
|
727
801
|
}
|
|
728
|
-
}
|
|
802
|
+
},
|
|
803
|
+
excludeStepId ? { excludeStepId } : {}
|
|
729
804
|
);
|
|
805
|
+
return excludeStepId ? rejectSelfParentResolution(resolution, excludeStepId, parentLcRunId) : resolution;
|
|
730
806
|
}
|
|
731
807
|
/**
|
|
732
808
|
* When ≥2 steps share the same unresolved semantic parent label, emit one
|
|
@@ -804,8 +880,10 @@ var LangChainTracePersistence = class {
|
|
|
804
880
|
try {
|
|
805
881
|
this.#prepareForStart();
|
|
806
882
|
const stepId = createStepId();
|
|
807
|
-
this.#
|
|
808
|
-
|
|
883
|
+
const resolution = await this.#maybeAttachSyntheticGroup(
|
|
884
|
+
this.#resolveParent(params.lcParentRunId, params.attributes, stepId),
|
|
885
|
+
params.startTime
|
|
886
|
+
);
|
|
809
887
|
beginCallbackRun(this.#lifecycle, {
|
|
810
888
|
lcRunId: params.lcRunId,
|
|
811
889
|
parentLcRunId: params.lcParentRunId,
|
|
@@ -816,25 +894,29 @@ var LangChainTracePersistence = class {
|
|
|
816
894
|
if (this.#standalone && !this.#lifecycle.envelopeStarted) {
|
|
817
895
|
await this.#ensureRunStarted(params.startTime, params.attributes);
|
|
818
896
|
}
|
|
819
|
-
const resolution = await this.#maybeAttachSyntheticGroup(
|
|
820
|
-
this.#resolveParent(params.lcParentRunId, params.attributes),
|
|
821
|
-
params.startTime
|
|
822
|
-
);
|
|
823
897
|
const metadata = toStepMetadata(params.attributes);
|
|
824
898
|
applyParentResolutionMetadata(metadata, resolution);
|
|
899
|
+
const parentId = this.#parentIdForPersist(
|
|
900
|
+
stepId,
|
|
901
|
+
resolution,
|
|
902
|
+
metadata,
|
|
903
|
+
params.lcParentRunId
|
|
904
|
+
);
|
|
825
905
|
const event = {
|
|
826
906
|
schemaVersion: "0.1",
|
|
827
907
|
event: "step_started",
|
|
828
908
|
timestamp: params.startTime,
|
|
829
909
|
runId: this.#runId,
|
|
830
910
|
stepId,
|
|
831
|
-
...
|
|
911
|
+
...parentId ? { parentId } : {},
|
|
832
912
|
name: params.name,
|
|
833
913
|
type: kindToStepType(params.kind),
|
|
834
914
|
startTime: params.startTime,
|
|
835
915
|
metadata
|
|
836
916
|
};
|
|
917
|
+
this.#lcToStepId.set(params.lcRunId, stepId);
|
|
837
918
|
await this.#write(event);
|
|
919
|
+
this.#registerStepIndexes(stepId, params.name, params.attributes);
|
|
838
920
|
} catch (err) {
|
|
839
921
|
this.#warn(err);
|
|
840
922
|
}
|
|
@@ -852,30 +934,38 @@ var LangChainTracePersistence = class {
|
|
|
852
934
|
return;
|
|
853
935
|
}
|
|
854
936
|
stepId = createStepId();
|
|
855
|
-
this.#lcToStepId.set(params.lcRunId, stepId);
|
|
856
937
|
const synthName = String(params.completionAttributes.name ?? "llm:llm");
|
|
857
|
-
|
|
938
|
+
const startTime = params.endTime - (params.durationMs ?? 0);
|
|
939
|
+
const resolution = await this.#maybeAttachSyntheticGroup(
|
|
940
|
+
this.#resolveParent(
|
|
941
|
+
params.lcParentRunId,
|
|
942
|
+
params.completionAttributes,
|
|
943
|
+
stepId
|
|
944
|
+
),
|
|
945
|
+
startTime
|
|
946
|
+
);
|
|
858
947
|
beginCallbackRun(this.#lifecycle, {
|
|
859
948
|
lcRunId: params.lcRunId,
|
|
860
949
|
parentLcRunId: params.lcParentRunId,
|
|
861
|
-
startedAt:
|
|
950
|
+
startedAt: startTime,
|
|
862
951
|
kind: params.completionAttributes.kind ?? "LLM",
|
|
863
952
|
stepId
|
|
864
953
|
});
|
|
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
954
|
const metadata = toStepMetadata(params.completionAttributes);
|
|
871
955
|
applyParentResolutionMetadata(metadata, resolution);
|
|
956
|
+
const parentId = this.#parentIdForPersist(
|
|
957
|
+
stepId,
|
|
958
|
+
resolution,
|
|
959
|
+
metadata,
|
|
960
|
+
params.lcParentRunId
|
|
961
|
+
);
|
|
872
962
|
const started = {
|
|
873
963
|
schemaVersion: "0.1",
|
|
874
964
|
event: "step_started",
|
|
875
965
|
timestamp: startTime,
|
|
876
966
|
runId: this.#runId,
|
|
877
967
|
stepId,
|
|
878
|
-
...
|
|
968
|
+
...parentId ? { parentId } : {},
|
|
879
969
|
name: synthName,
|
|
880
970
|
type: kindToStepType(
|
|
881
971
|
params.completionAttributes.kind ?? "LLM"
|
|
@@ -886,7 +976,9 @@ var LangChainTracePersistence = class {
|
|
|
886
976
|
if (this.#standalone && !this.#lifecycle.envelopeStarted) {
|
|
887
977
|
await this.#ensureRunStarted(startTime, params.completionAttributes);
|
|
888
978
|
}
|
|
979
|
+
this.#lcToStepId.set(params.lcRunId, stepId);
|
|
889
980
|
await this.#write(started);
|
|
981
|
+
this.#registerStepIndexes(stepId, synthName, params.completionAttributes);
|
|
890
982
|
}
|
|
891
983
|
if (!stepId) return;
|
|
892
984
|
const durationMs = typeof params.durationMs === "number" && Number.isFinite(params.durationMs) ? Math.max(0, Math.floor(params.durationMs)) : Math.max(
|
|
@@ -922,8 +1014,10 @@ var LangChainTracePersistence = class {
|
|
|
922
1014
|
try {
|
|
923
1015
|
this.#prepareForStart();
|
|
924
1016
|
const stepId = createStepId();
|
|
925
|
-
this.#
|
|
926
|
-
|
|
1017
|
+
const resolution = await this.#maybeAttachSyntheticGroup(
|
|
1018
|
+
this.#resolveParent(params.lcParentRunId, params.attributes, stepId),
|
|
1019
|
+
params.timestamp
|
|
1020
|
+
);
|
|
927
1021
|
beginCallbackRun(this.#lifecycle, {
|
|
928
1022
|
lcRunId: params.lcRunId,
|
|
929
1023
|
parentLcRunId: params.lcParentRunId,
|
|
@@ -934,25 +1028,29 @@ var LangChainTracePersistence = class {
|
|
|
934
1028
|
if (this.#standalone && !this.#lifecycle.envelopeStarted) {
|
|
935
1029
|
await this.#ensureRunStarted(params.timestamp, params.attributes);
|
|
936
1030
|
}
|
|
937
|
-
const resolution = await this.#maybeAttachSyntheticGroup(
|
|
938
|
-
this.#resolveParent(params.lcParentRunId, params.attributes),
|
|
939
|
-
params.timestamp
|
|
940
|
-
);
|
|
941
1031
|
const metadata = toStepMetadata(params.attributes);
|
|
942
1032
|
applyParentResolutionMetadata(metadata, resolution);
|
|
1033
|
+
const parentId = this.#parentIdForPersist(
|
|
1034
|
+
stepId,
|
|
1035
|
+
resolution,
|
|
1036
|
+
metadata,
|
|
1037
|
+
params.lcParentRunId
|
|
1038
|
+
);
|
|
943
1039
|
const started = {
|
|
944
1040
|
schemaVersion: "0.1",
|
|
945
1041
|
event: "step_started",
|
|
946
1042
|
timestamp: params.timestamp,
|
|
947
1043
|
runId: this.#runId,
|
|
948
1044
|
stepId,
|
|
949
|
-
...
|
|
1045
|
+
...parentId ? { parentId } : {},
|
|
950
1046
|
name: params.name,
|
|
951
1047
|
type: kindToStepType(params.kind),
|
|
952
1048
|
startTime: params.timestamp,
|
|
953
1049
|
metadata
|
|
954
1050
|
};
|
|
1051
|
+
this.#lcToStepId.set(params.lcRunId, stepId);
|
|
955
1052
|
await this.#write(started);
|
|
1053
|
+
this.#registerStepIndexes(stepId, params.name, params.attributes);
|
|
956
1054
|
const completed = {
|
|
957
1055
|
schemaVersion: "0.1",
|
|
958
1056
|
event: "step_completed",
|
|
@@ -1198,6 +1296,8 @@ var AgentInspectCallback = class extends BaseCallbackHandler {
|
|
|
1198
1296
|
pendingRelationshipCount: 0,
|
|
1199
1297
|
knownRelationshipCount: 0,
|
|
1200
1298
|
syntheticGroupCount: 0,
|
|
1299
|
+
selfParentRejectedCount: 0,
|
|
1300
|
+
ambiguousRelationshipCount: 0,
|
|
1201
1301
|
envelopeStarted: false,
|
|
1202
1302
|
finalized: false,
|
|
1203
1303
|
completionGeneration: 0,
|