@caupulican/pi-agent-core 0.93.3 → 0.93.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/dist/agent-loop.d.ts.map +1 -1
- package/dist/agent-loop.js +6 -4
- package/dist/agent-loop.js.map +1 -1
- package/dist/session/session-manager.d.ts +4 -1
- package/dist/session/session-manager.d.ts.map +1 -1
- package/dist/session/session-manager.js +45 -4
- package/dist/session/session-manager.js.map +1 -1
- package/dist/tool-failure-memory.d.ts +5 -1
- package/dist/tool-failure-memory.d.ts.map +1 -1
- package/dist/tool-failure-memory.js +48 -34
- package/dist/tool-failure-memory.js.map +1 -1
- package/dist/tool-failure-recovery-gate.d.ts +4 -2
- package/dist/tool-failure-recovery-gate.d.ts.map +1 -1
- package/dist/tool-failure-recovery-gate.js +33 -7
- package/dist/tool-failure-recovery-gate.js.map +1 -1
- package/dist/types.d.ts +11 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/package.json +2 -2
|
@@ -19,6 +19,8 @@ export interface ToolFailureMemoryRecord {
|
|
|
19
19
|
phase: ToolFailurePhase;
|
|
20
20
|
failureCode: string;
|
|
21
21
|
diagnostic?: string;
|
|
22
|
+
/** Bounded tool-owned source evidence needed to construct a changed operation. */
|
|
23
|
+
evidence?: string;
|
|
22
24
|
correction: string;
|
|
23
25
|
attemptMemory?: "discard";
|
|
24
26
|
}
|
|
@@ -37,6 +39,8 @@ export interface ToolFailureDirectiveDetails {
|
|
|
37
39
|
}
|
|
38
40
|
export type ToolFailureResultDetails = ToolFailureMemoryDetails | ToolFailureDirectiveDetails;
|
|
39
41
|
export type ToolFailureMemoryTracker = Map<string, ToolFailureMemoryRecord>;
|
|
42
|
+
/** Normalize and bound tool-owned evidence at every live and persisted ingress. */
|
|
43
|
+
export declare function sanitizeToolFailureEvidence(value: unknown): string | undefined;
|
|
40
44
|
export declare function normalizeToolSignature(pairs: Array<[string, unknown]>): string;
|
|
41
45
|
export declare function getToolExecutionKey(tool: string, args: unknown): string;
|
|
42
46
|
/** Read the four hash words already encoded by this module's exact execution-key owner. */
|
|
@@ -76,7 +80,7 @@ export interface ToolFailureTelemetry {
|
|
|
76
80
|
/** Read only bounded failure identity and guidance; operation arguments never cross this telemetry boundary. */
|
|
77
81
|
export declare function readToolFailureTelemetry(details: unknown): ToolFailureTelemetry | undefined;
|
|
78
82
|
export declare function createToolFailureMemoryTracker(messages: AgentMessage[]): ToolFailureMemoryTracker;
|
|
79
|
-
export declare function rememberToolFailure(tracker: ToolFailureMemoryTracker, tool: string, args: unknown, state: ToolFailureState, failureCode: string, correction: string, diagnostic?: string, phase?: ToolFailurePhase): ToolFailureMemoryRecord;
|
|
83
|
+
export declare function rememberToolFailure(tracker: ToolFailureMemoryTracker, tool: string, args: unknown, state: ToolFailureState, failureCode: string, correction: string, diagnostic?: string, phase?: ToolFailurePhase, evidence?: string): ToolFailureMemoryRecord;
|
|
80
84
|
export declare function clearToolFailure(tracker: ToolFailureMemoryTracker, tool: string, args: unknown): void;
|
|
81
85
|
export declare function createToolFailureResult(record: ToolFailureMemoryRecord, terminate?: boolean): AgentToolResult<ToolFailureResultDetails>;
|
|
82
86
|
export declare function createRepeatedToolFailureResult(record: ToolFailureMemoryRecord): AgentToolResult<ToolFailureMemoryDetails>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tool-failure-memory.d.ts","sourceRoot":"","sources":["../src/tool-failure-memory.ts"],"names":[],"mappings":"AAAA,OAAO,EAGN,KAAK,gBAAgB,EACrB,MAAM,wCAAwC,CAAC;AAChD,OAAO,KAAK,EAAoB,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAKnF,OAAO,KAAK,EAAE,YAAY,EAAiB,eAAe,EAAE,MAAM,YAAY,CAAC;AAG/E,QAAA,MAAM,2BAA2B,IAAI,CAAC;AACtC,QAAA,MAAM,8BAA8B,IAAI,CAAC;AACzC,QAAA,MAAM,0BAA0B,eAAoC,CAAC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GNOSTIC_CHARS = 240;
|
|
10
10
|
const MAX_CORRECTION_CHARS = 320;
|
|
11
|
+
const MAX_TOOL_FAILURE_EVIDENCE_CHARS = 1_600;
|
|
12
|
+
const MAX_ACTIVE_FAILURE_EVIDENCE_CHARS = 2_400;
|
|
11
13
|
const MAX_TOOL_NAME_CHARS = 64;
|
|
12
14
|
const TOOL_SIGNATURE_HEX_CHARS = 32;
|
|
13
15
|
const MAX_ACTIVE_FAILURES = 8;
|
|
@@ -25,6 +27,13 @@ function truncate(value, maxChars) {
|
|
|
25
27
|
end--;
|
|
26
28
|
return `${value.slice(0, end)}…`;
|
|
27
29
|
}
|
|
30
|
+
/** Normalize and bound tool-owned evidence at every live and persisted ingress. */
|
|
31
|
+
export function sanitizeToolFailureEvidence(value) {
|
|
32
|
+
if (typeof value !== "string")
|
|
33
|
+
return undefined;
|
|
34
|
+
const sanitized = sanitizeBinaryOutput(value).trim();
|
|
35
|
+
return sanitized ? truncate(sanitized, MAX_TOOL_FAILURE_EVIDENCE_CHARS) : undefined;
|
|
36
|
+
}
|
|
28
37
|
function truncateMiddle(value, maxChars) {
|
|
29
38
|
if (value.length <= maxChars)
|
|
30
39
|
return value;
|
|
@@ -583,6 +592,7 @@ function readFailureRecord(details) {
|
|
|
583
592
|
return undefined;
|
|
584
593
|
}
|
|
585
594
|
const diagnostic = typeof candidate.diagnostic === "string" ? truncate(candidate.diagnostic, MAX_DIAGNOSTIC_CHARS) : undefined;
|
|
595
|
+
const evidence = sanitizeToolFailureEvidence(candidate.evidence);
|
|
586
596
|
const retainedCorrection = typeof candidate.correction === "string" ? truncate(candidate.correction, MAX_CORRECTION_CHARS) : undefined;
|
|
587
597
|
const correction = candidate.state === "failed" && retainedCorrection === LEGACY_GENERIC_EXECUTION_CORRECTION
|
|
588
598
|
? fallbackFailureGuidance("failed", diagnostic !== undefined, "execution")
|
|
@@ -606,6 +616,7 @@ function readFailureRecord(details) {
|
|
|
606
616
|
phase,
|
|
607
617
|
failureCode: boundedFailureCode(candidate.failureCode),
|
|
608
618
|
diagnostic,
|
|
619
|
+
evidence,
|
|
609
620
|
correction,
|
|
610
621
|
};
|
|
611
622
|
}
|
|
@@ -750,6 +761,7 @@ function analyzeToolFailureContext(messages) {
|
|
|
750
761
|
phase: retained?.phase ?? assessment?.phase ?? inferToolFailurePhase(state, "tool_error"),
|
|
751
762
|
failureCode: retained?.failureCode ?? assessment?.failureCode ?? "tool_error",
|
|
752
763
|
diagnostic: retained?.diagnostic ?? assessment?.diagnostic,
|
|
764
|
+
evidence: retained?.evidence,
|
|
753
765
|
correction: retained?.correction ??
|
|
754
766
|
assessment?.guidance ??
|
|
755
767
|
fallbackFailureGuidance(state, false, inferToolFailurePhase(state, "tool_error")),
|
|
@@ -840,59 +852,50 @@ function analyzeToolFailureContext(messages) {
|
|
|
840
852
|
export function createToolFailureMemoryTracker(messages) {
|
|
841
853
|
return new Map(analyzeToolFailureContext(messages).activeRecords.map((record) => [record.failureKey, record]));
|
|
842
854
|
}
|
|
843
|
-
export function rememberToolFailure(tracker, tool, args, state, failureCode, correction, diagnostic, phase = inferToolFailurePhase(state, failureCode)) {
|
|
855
|
+
export function rememberToolFailure(tracker, tool, args, state, failureCode, correction, diagnostic, phase = inferToolFailurePhase(state, failureCode), evidence) {
|
|
844
856
|
let kindCount = 1;
|
|
845
857
|
for (const previous of tracker.values()) {
|
|
846
858
|
if (previous.tool === tool) {
|
|
847
859
|
kindCount = Math.max(kindCount, (previous.kindMistakes ?? previous.occurrence) + 1);
|
|
848
860
|
}
|
|
849
861
|
}
|
|
850
|
-
|
|
862
|
+
const isDiscard = getToolExecutionAttemptMemory(failureCode) === "discard";
|
|
863
|
+
if (isDiscard) {
|
|
851
864
|
for (const [failureKey, previous] of tracker) {
|
|
852
865
|
if (previous.tool === tool && previous.failureCode === failureCode)
|
|
853
866
|
tracker.delete(failureKey);
|
|
854
867
|
}
|
|
855
|
-
return {
|
|
856
|
-
version: TOOL_FAILURE_MEMORY_VERSION,
|
|
857
|
-
failureKey: `directive:${boundedFailureCode(failureCode)}`,
|
|
858
|
-
[TOOL_FAILURE_EXECUTION_KEY]: getToolExecutionKey(tool, args),
|
|
859
|
-
tool: truncate(tool, MAX_TOOL_NAME_CHARS),
|
|
860
|
-
operation: "[discarded]",
|
|
861
|
-
occurrence: 1,
|
|
862
|
-
kindMistakes: kindCount,
|
|
863
|
-
mistakeKind: tool,
|
|
864
|
-
state,
|
|
865
|
-
phase,
|
|
866
|
-
failureCode: boundedFailureCode(failureCode),
|
|
867
|
-
diagnostic: diagnostic ? truncate(diagnostic, MAX_DIAGNOSTIC_CHARS) : undefined,
|
|
868
|
-
correction: truncate(correction, MAX_CORRECTION_CHARS),
|
|
869
|
-
attemptMemory: "discard",
|
|
870
|
-
};
|
|
871
868
|
}
|
|
872
|
-
const identity = operationIdentity(tool, args);
|
|
873
|
-
const previous = tracker.get(identity.failureKey);
|
|
869
|
+
const identity = isDiscard ? undefined : operationIdentity(tool, args);
|
|
870
|
+
const previous = identity ? tracker.get(identity.failureKey) : undefined;
|
|
874
871
|
const record = {
|
|
875
872
|
version: TOOL_FAILURE_MEMORY_VERSION,
|
|
876
|
-
failureKey: identity.failureKey
|
|
877
|
-
[TOOL_FAILURE_EXECUTION_KEY]: identity.executionKey,
|
|
878
|
-
tool: identity.tool,
|
|
879
|
-
operation: identity.operation,
|
|
880
|
-
occurrence: (previous?.occurrence ?? 0) + 1,
|
|
873
|
+
failureKey: identity ? identity.failureKey : `directive:${boundedFailureCode(failureCode)}`,
|
|
874
|
+
[TOOL_FAILURE_EXECUTION_KEY]: identity ? identity.executionKey : getToolExecutionKey(tool, args),
|
|
875
|
+
tool: identity ? identity.tool : truncate(tool, MAX_TOOL_NAME_CHARS),
|
|
876
|
+
operation: identity ? identity.operation : "[discarded]",
|
|
877
|
+
occurrence: isDiscard ? 1 : (previous?.occurrence ?? 0) + 1,
|
|
881
878
|
kindMistakes: kindCount,
|
|
882
879
|
mistakeKind: tool,
|
|
883
880
|
state,
|
|
884
881
|
phase,
|
|
885
882
|
failureCode: boundedFailureCode(failureCode),
|
|
886
883
|
diagnostic: diagnostic ? truncate(diagnostic, MAX_DIAGNOSTIC_CHARS) : undefined,
|
|
884
|
+
evidence: sanitizeToolFailureEvidence(evidence),
|
|
887
885
|
correction: truncate(correction, MAX_CORRECTION_CHARS),
|
|
886
|
+
...(isDiscard ? { attemptMemory: "discard" } : {}),
|
|
888
887
|
};
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
888
|
+
if (isDiscard)
|
|
889
|
+
return record;
|
|
890
|
+
if (identity) {
|
|
891
|
+
tracker.delete(identity.failureKey);
|
|
892
|
+
tracker.set(identity.failureKey, record);
|
|
893
|
+
while (tracker.size > MAX_TRACKED_FAILURES) {
|
|
894
|
+
const oldest = tracker.keys().next().value;
|
|
895
|
+
if (oldest === undefined)
|
|
896
|
+
break;
|
|
897
|
+
tracker.delete(oldest);
|
|
898
|
+
}
|
|
896
899
|
}
|
|
897
900
|
return record;
|
|
898
901
|
}
|
|
@@ -908,7 +911,7 @@ function failureGuidance(record) {
|
|
|
908
911
|
? { repair: record.correction }
|
|
909
912
|
: { next_action: record.correction };
|
|
910
913
|
}
|
|
911
|
-
function formatRecordJson(record, includeOperation = false) {
|
|
914
|
+
function formatRecordJson(record, includeOperation = false, evidence = record.evidence) {
|
|
912
915
|
const guidance = failureGuidance(record);
|
|
913
916
|
return JSON.stringify({
|
|
914
917
|
...mandatoryToolFailureRecoveryMetadata(),
|
|
@@ -922,6 +925,7 @@ function formatRecordJson(record, includeOperation = false) {
|
|
|
922
925
|
...(includeOperation ? { operation: record.operation } : {}),
|
|
923
926
|
failure_code: record.failureCode,
|
|
924
927
|
...(record.diagnostic ? { diagnostic: record.diagnostic } : {}),
|
|
928
|
+
...(evidence ? { evidence } : {}),
|
|
925
929
|
...guidance,
|
|
926
930
|
...(record.attemptMemory === "discard" ? { attempt_memory: "discarded" } : {}),
|
|
927
931
|
});
|
|
@@ -1020,7 +1024,17 @@ export function sanitizeToolFailureContext(messages, systemPrompt) {
|
|
|
1020
1024
|
const kindSummary = Object.entries(analysis.kindMistakesSummary)
|
|
1021
1025
|
.map(([kind, count]) => `${kind}:${count}`)
|
|
1022
1026
|
.join(", ");
|
|
1023
|
-
|
|
1027
|
+
let remainingEvidenceChars = MAX_ACTIVE_FAILURE_EVIDENCE_CHARS;
|
|
1028
|
+
const evidenceByFailureKey = new Map();
|
|
1029
|
+
for (let index = records.length - 1; index >= 0 && remainingEvidenceChars > 1; index--) {
|
|
1030
|
+
const record = records[index];
|
|
1031
|
+
if (!record.evidence)
|
|
1032
|
+
continue;
|
|
1033
|
+
const retained = truncate(record.evidence, remainingEvidenceChars);
|
|
1034
|
+
evidenceByFailureKey.set(record.failureKey, retained);
|
|
1035
|
+
remainingEvidenceChars -= retained.length;
|
|
1036
|
+
}
|
|
1037
|
+
const lines = records.map((record) => escapePromptData(formatRecordJson(record, true, evidenceByFailureKey.get(record.failureKey) ?? null)));
|
|
1024
1038
|
for (const directive of analysis.activeDirectives) {
|
|
1025
1039
|
lines.push(escapePromptData(JSON.stringify({
|
|
1026
1040
|
...mandatoryToolFailureRecoveryMetadata(),
|