@caupulican/pi-agent-core 0.93.7 → 0.93.9
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 +179 -155
- package/dist/agent-loop.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/tool-failure-memory.d.ts +17 -5
- package/dist/tool-failure-memory.d.ts.map +1 -1
- package/dist/tool-failure-memory.js +128 -82
- package/dist/tool-failure-memory.js.map +1 -1
- package/dist/tool-failure-recovery-gate.d.ts +32 -42
- package/dist/tool-failure-recovery-gate.d.ts.map +1 -1
- package/dist/tool-failure-recovery-gate.js +161 -267
- package/dist/tool-failure-recovery-gate.js.map +1 -1
- package/dist/tool-failure-recovery-protocol.d.ts +2 -0
- package/dist/tool-failure-recovery-protocol.d.ts.map +1 -1
- package/dist/tool-failure-recovery-protocol.js +7 -6
- package/dist/tool-failure-recovery-protocol.js.map +1 -1
- package/dist/tool-protocol-residue.d.ts +9 -0
- package/dist/tool-protocol-residue.d.ts.map +1 -1
- package/dist/tool-protocol-residue.js +28 -1
- package/dist/tool-protocol-residue.js.map +1 -1
- package/dist/types.d.ts +50 -18
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +17 -0
- package/dist/types.js.map +1 -1
- package/package.json +2 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tool-failure-recovery-gate.js","sourceRoot":"","sources":["../src/tool-failure-recovery-gate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mCAAmC,EAAE,MAAM,wCAAwC,CAAC;AAE7F,OAAO,EACN,uBAAuB,EACvB,mBAAmB,EACnB,4BAA4B,EAC5B,gCAAgC,EAChC,4BAA4B,EAC5B,yBAAyB,EACzB,0BAA0B,EAC1B,wBAAwB,EACxB,2BAA2B,GAE3B,MAAM,0BAA0B,C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E,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,kBAAkB,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC,CAAC,CAAC;AAChG,CAAC","sourcesContent":["import { getToolExecutionUnchangedRetryLimit } from \"@caupulican/pi-ai/tool-repair-registry\";\nimport type { ToolResultMessage } from \"@caupulican/pi-ai/types\";\nimport {\n\tforEachPairedToolResult,\n\tgetToolExecutionKey,\n\tgetToolExecutionKeyHashParts,\n\tgetToolFailureRecordExecutionKey,\n\tisClosedOperationFailureCode,\n\tisPromptScopedFailureCode,\n\treadVisibleToolFailureCode,\n\trestoreToolFailureRecord,\n\tsanitizeToolFailureEvidence,\n\ttype ToolFailureMemoryRecord,\n} from \"./tool-failure-memory.ts\";\nimport type {\n\tAgentMessage,\n\tAgentTool,\n\tAgentToolFailureEvidenceContext,\n\tAgentToolFailureRecoveryAuthority,\n\tAgentToolFailureRecoveryTarget,\n\tAgentToolResult,\n} from \"./types.ts\";\nimport { isAgentToolFailureRecoveryAuthority } from \"./types.ts\";\n\nconst MAX_BLOCKED_REPLAYS_PER_FAILURE = 2;\nconst BASE_FAILURE_EXECUTIONS_PER_OPERATION = 1;\nconst MAX_RECOVERY_PROBES_PER_OPERATION = 1;\nconst MAX_REJECTIONS_PER_OPERATION = 4;\nconst MAX_HOT_RECOVERY_STATES = 64;\nconst SEEN_EXECUTION_FILTER_BYTES = 64 * 1024;\nconst MAX_RECOVERY_TARGETS = 8;\nconst MAX_RECOVERY_ACTIONS = 8;\nconst MAX_TARGET_KIND_CHARS = 64;\nconst MAX_TARGET_SCOPE_CHARS = 32_768;\nconst MAX_ACTION_INSTRUCTION_CHARS = 160;\nconst MAX_RECOVERY_GUIDANCE_CHARS = 320;\nconst TARGET_KIND_PATTERN = /^[a-z0-9][a-z0-9._:-]*$/;\n\nexport interface ToolFailureExecutionReservation {\n\texecutionKey: string;\n}\n\nexport interface ToolFailureRecoveryPlan {\n\ttargets: readonly AgentToolFailureRecoveryTarget[];\n\tguidance: string;\n\tevidence?: string;\n}\n\nexport type ToolFailureRecoveryGateEffect =\n\t| {\n\t\t\tkind: \"failure\";\n\t\t\ttool?: AgentTool<any>;\n\t\t\trecord: ToolFailureMemoryRecord;\n\t\t\targs: unknown;\n\t\t\ttargets?: readonly AgentToolFailureRecoveryTarget[];\n\t\t\treservation?: ToolFailureExecutionReservation;\n\t }\n\t| { kind: \"success\"; tool: AgentTool<any>; args: unknown; evidenceResult: AgentToolResult<any> };\n\nexport type ToolFailureRecoveryAdmission =\n\t| { kind: \"allowed\"; reservation?: ToolFailureExecutionReservation }\n\t| { kind: \"blocked\"; record: ToolFailureMemoryRecord; exhausted: false; diagnostic?: string }\n\t| {\n\t\t\tkind: \"blocked\";\n\t\t\trecord: ToolFailureMemoryRecord;\n\t\t\texhausted: true;\n\t\t\tscope: \"operation\" | \"run\";\n\t\t\tdiagnostic?: string;\n\t };\n\ninterface FailureRecoveryState {\n\trecord: ToolFailureMemoryRecord;\n\trecoveryTargets: readonly AgentToolFailureRecoveryTarget[];\n\treservedExecutions: number;\n\tfailures: number;\n\trecoveryProbes: number;\n\tblockedReplays: number;\n\trecoveryAvailable: boolean;\n\toperationCircuitOpen: boolean;\n}\n\ntype TranscriptRecoveryReduction =\n\t| { kind: \"resolved\" }\n\t| { kind: \"ignored\"; state: FailureRecoveryState | undefined }\n\t| { kind: \"failed\"; state: FailureRecoveryState };\n\ninterface AvailableRecoveryAction {\n\ttoolName: string;\n\tkind: \"correct\" | \"repair\";\n\tinstruction: string;\n}\n\ninterface ParsedRecoveryAction {\n\tkind: \"correct\" | \"repair\";\n\tauthority: AgentToolFailureRecoveryAuthority;\n\ttargetKind: string;\n\tinstruction: string;\n\tgetEvidence?: (params: unknown, result: AgentToolResult<unknown>) => unknown;\n}\n\nexport interface ToolFailureRecoveryHalt {\n\trecord: ToolFailureMemoryRecord;\n\tdiagnostic: string;\n}\n\n/**\n * Bounded negative lookup for exact execution identities.\n *\n * A miss proves the operation has not failed while this gate has been alive. A hit only means\n * \"possibly seen\" and must be verified against the transcript, so collisions can cost a scan but\n * can never deny an execution. Keeping this separate from the hot state cache lets old exact\n * circuits survive eviction without retaining one live object graph per historical operation.\n */\nclass SeenExecutionFilter {\n\tprivate readonly bits = new Uint8Array(SEEN_EXECUTION_FILTER_BYTES);\n\n\tadd(executionKey: string): void {\n\t\tfor (const hash of getToolExecutionKeyHashParts(executionKey)) this.set(hash);\n\t}\n\n\tmightContain(executionKey: string): boolean {\n\t\tfor (const hash of getToolExecutionKeyHashParts(executionKey)) {\n\t\t\tif (!this.has(hash)) return false;\n\t\t}\n\t\treturn true;\n\t}\n\n\tprivate set(hash: number): void {\n\t\tconst bit = (hash >>> 0) % (SEEN_EXECUTION_FILTER_BYTES * 8);\n\t\tthis.bits[bit >>> 3] |= 1 << (bit & 7);\n\t}\n\n\tprivate has(hash: number): boolean {\n\t\tconst bit = (hash >>> 0) % (SEEN_EXECUTION_FILTER_BYTES * 8);\n\t\treturn (this.bits[bit >>> 3] & (1 << (bit & 7))) !== 0;\n\t}\n}\n\n/**\n * Owns execution admission and bounded unresolved-failure budgets.\n *\n * Recovery authority is exact and tool-owned. A failed tool declares opaque backend-specific targets;\n * a loaded recovery tool may teach actions only for the same authority and target kind. Only raw\n * successful repair evidence with byte-exact scope can reopen one probe. Argument text and hooks have\n * no recovery authority.\n *\n * Run-level halt stays on the current run, but admission is never denied because unrelated operations\n * happened to fail. A bounded hot cache carries active per-operation state. A fixed-size negative\n * lookup sends an evicted exact replay back to the transcript for authoritative reconstruction, so\n * cache pressure cannot either stop new work or reopen an already-exhausted operation.\n */\nexport class ToolFailureRecoveryGate {\n\tprivate readonly statesByExecutionKey = new Map<string, FailureRecoveryState>();\n\tprivate readonly seenFailedExecutions = new SeenExecutionFilter();\n\t/** Exact successes not yet present in the transcript snapshot consulted by admission. */\n\tprivate readonly resolvedBeforeTranscriptCommit = new Set<string>();\n\tprivate transcriptMessages: readonly AgentMessage[] = [];\n\tprivate transcriptLength = 0;\n\tprivate transcriptTail: AgentMessage | undefined;\n\tprivate restoredFromTranscript = false;\n\tprivate halted: ToolFailureRecoveryHalt | undefined;\n\n\tisEmpty(): boolean {\n\t\treturn this.statesByExecutionKey.size === 0 && this.halted === undefined;\n\t}\n\n\trestoreFromMessages(messages: readonly AgentMessage[]): void {\n\t\tthis.trackTranscript(messages);\n\t\tif (this.restoredFromTranscript || !this.isEmpty()) return;\n\t\tthis.restoredFromTranscript = true;\n\t\tforEachPairedToolResult(messages, ({ tool, args, executionKey, result }) => {\n\t\t\tconst reduction = this.reduceTranscriptResult(this.statesByExecutionKey.get(executionKey), tool, args, result);\n\t\t\tif (reduction.kind === \"resolved\") {\n\t\t\t\tthis.clearResolvedState(executionKey);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (reduction.kind === \"ignored\") return;\n\t\t\tthis.seenFailedExecutions.add(executionKey);\n\t\t\tthis.retainHotState(executionKey, reduction.state);\n\t\t});\n\t}\n\n\tplanFailure(\n\t\tfailedTool: AgentTool<any>,\n\t\targs: unknown,\n\t\tfailure: AgentToolFailureEvidenceContext,\n\t\tavailableTools: readonly AgentTool<any>[],\n\t\treservation: ToolFailureExecutionReservation | undefined,\n\t): ToolFailureRecoveryPlan {\n\t\tconst targets = readFailureTargets(failedTool, args, failure.failureCode);\n\t\tconst actions = readAvailableRecoveryActions(availableTools, targets);\n\t\tconst unchangedRetryRemaining = this.hasUnchangedRetryRemaining(\n\t\t\tfailedTool,\n\t\t\targs,\n\t\t\tfailure.failureCode,\n\t\t\treservation,\n\t\t);\n\t\tconst evidence = readFailureEvidence(failedTool, args, failure);\n\t\treturn {\n\t\t\ttargets,\n\t\t\tguidance: formatRecoveryGuidance(failure.failureCode, actions, unchangedRetryRemaining),\n\t\t\t...(evidence ? { evidence } : {}),\n\t\t};\n\t}\n\n\tadmit(\n\t\ttool: AgentTool<any>,\n\t\targs: unknown,\n\t\trecord: ToolFailureMemoryRecord | undefined,\n\t\tmessages: readonly AgentMessage[] = this.transcriptMessages,\n\t): ToolFailureRecoveryAdmission {\n\t\tthis.trackTranscript(messages);\n\t\tconst runHalt = this.halted;\n\t\tif (runHalt) {\n\t\t\treturn {\n\t\t\t\tkind: \"blocked\",\n\t\t\t\trecord: runHalt.record,\n\t\t\t\texhausted: true,\n\t\t\t\tscope: \"run\",\n\t\t\t\tdiagnostic: runHalt.diagnostic,\n\t\t\t};\n\t\t}\n\n\t\tconst executionKey = getToolExecutionKey(tool.name, args);\n\t\tif (this.resolvedBeforeTranscriptCommit.has(executionKey)) return { kind: \"allowed\" };\n\t\tlet state = this.getHotState(executionKey);\n\t\tif (!state && this.seenFailedExecutions.mightContain(executionKey)) {\n\t\t\tstate = this.restoreOperationFromTranscript(executionKey);\n\t\t}\n\t\tif (!state && record && getToolFailureRecordExecutionKey(record) === executionKey) {\n\t\t\tstate = this.getOrCreateState(executionKey, record, readFailureTargets(tool, args, record.failureCode));\n\t\t}\n\t\tif (!state) return { kind: \"allowed\" };\n\n\t\tif (record && getToolFailureRecordExecutionKey(record) === executionKey) state.record = record;\n\t\tif (state.operationCircuitOpen) {\n\t\t\tif (state.recoveryAvailable && state.recoveryProbes < MAX_RECOVERY_PROBES_PER_OPERATION) {\n\t\t\t\tstate.operationCircuitOpen = false;\n\t\t\t\tstate.recoveryAvailable = false;\n\t\t\t\tstate.recoveryProbes++;\n\t\t\t\tstate.reservedExecutions++;\n\t\t\t\tstate.blockedReplays = 0;\n\t\t\t\treturn { kind: \"allowed\", reservation: { executionKey } };\n\t\t\t}\n\t\t\tif (usesOperationLocalExhaustion(tool)) {\n\t\t\t\tconst diagnostic = `Operation recovery circuit remains closed after replay of ${state.record.failureCode}.`;\n\t\t\t\treturn { kind: \"blocked\", record: state.record, exhausted: true, scope: \"operation\", diagnostic };\n\t\t\t}\n\t\t\tconst diagnostic = `Run recovery circuit opened after replay of an operation whose local circuit was already open for ${state.record.failureCode}.`;\n\t\t\tthis.halted = { record: state.record, diagnostic };\n\t\t\treturn { kind: \"blocked\", record: state.record, exhausted: true, scope: \"run\", diagnostic };\n\t\t}\n\t\tconst automaticExecutionLimit =\n\t\t\tBASE_FAILURE_EXECUTIONS_PER_OPERATION + getToolExecutionUnchangedRetryLimit(state.record.failureCode);\n\t\tif (state.reservedExecutions < automaticExecutionLimit) {\n\t\t\tstate.reservedExecutions++;\n\t\t\tstate.blockedReplays = 0;\n\t\t\treturn { kind: \"allowed\", reservation: { executionKey } };\n\t\t}\n\t\tif (state.recoveryAvailable && state.recoveryProbes < MAX_RECOVERY_PROBES_PER_OPERATION) {\n\t\t\tstate.recoveryAvailable = false;\n\t\t\tstate.recoveryProbes++;\n\t\t\tstate.reservedExecutions++;\n\t\t\tstate.blockedReplays = 0;\n\t\t\treturn { kind: \"allowed\", reservation: { executionKey } };\n\t\t}\n\n\t\tstate.blockedReplays++;\n\t\tif (state.blockedReplays >= MAX_BLOCKED_REPLAYS_PER_FAILURE) {\n\t\t\tstate.operationCircuitOpen = true;\n\t\t\tconst diagnostic = `Operation recovery circuit opened after ${state.blockedReplays} blocked replays of ${state.record.failureCode}.`;\n\t\t\treturn { kind: \"blocked\", record: state.record, exhausted: true, scope: \"operation\", diagnostic };\n\t\t}\n\t\treturn { kind: \"blocked\", record: state.record, exhausted: false };\n\t}\n\n\tapply(effect: ToolFailureRecoveryGateEffect | undefined): ToolFailureRecoveryHalt | undefined {\n\t\tif (!effect || this.halted) return undefined;\n\t\tif (effect.kind === \"success\") {\n\t\t\tthis.observeSuccess(effect.tool, effect.args, effect.evidenceResult);\n\t\t\treturn undefined;\n\t\t}\n\t\tthis.observeFailure(effect.tool, effect.record, effect.args, effect.targets ?? [], effect.reservation);\n\t\treturn this.halted;\n\t}\n\n\tisHalted(): boolean {\n\t\treturn this.halted !== undefined;\n\t}\n\n\tgetHalt(): ToolFailureRecoveryHalt | undefined {\n\t\treturn this.halted;\n\t}\n\n\tprivate hasUnchangedRetryRemaining(\n\t\ttool: AgentTool<any>,\n\t\targs: unknown,\n\t\tfailureCode: string,\n\t\treservation: ToolFailureExecutionReservation | undefined,\n\t): boolean {\n\t\tconst retryLimit = getToolExecutionUnchangedRetryLimit(failureCode);\n\t\tif (retryLimit === 0) return false;\n\t\tconst executionKey = getToolExecutionKey(tool.name, args);\n\t\tconst state = this.statesByExecutionKey.get(executionKey);\n\t\tconst executionsIncludingCurrent = state\n\t\t\t? state.reservedExecutions + (reservation?.executionKey === executionKey ? 0 : 1)\n\t\t\t: 1;\n\t\treturn executionsIncludingCurrent < BASE_FAILURE_EXECUTIONS_PER_OPERATION + retryLimit;\n\t}\n\n\tprivate getOrCreateState(\n\t\texecutionKey: string,\n\t\trecord: ToolFailureMemoryRecord,\n\t\ttargets: readonly AgentToolFailureRecoveryTarget[],\n\t): FailureRecoveryState {\n\t\tconst existing = this.getHotState(executionKey);\n\t\tif (existing) return existing;\n\t\tconst state = createFailureRecoveryState(record, targets);\n\t\tthis.retainHotState(executionKey, state);\n\t\treturn state;\n\t}\n\n\tprivate observeFailure(\n\t\ttool: AgentTool<any> | undefined,\n\t\trecord: ToolFailureMemoryRecord,\n\t\targs: unknown,\n\t\ttargets: readonly AgentToolFailureRecoveryTarget[],\n\t\treservation: ToolFailureExecutionReservation | undefined,\n\t): void {\n\t\tconst executionKey = getToolExecutionKey(record.tool, args);\n\t\tthis.resolvedBeforeTranscriptCommit.delete(executionKey);\n\t\tthis.seenFailedExecutions.add(executionKey);\n\t\tconst state = this.getOrCreateState(executionKey, record, targets);\n\t\tif (this.halted) return;\n\t\tstate.record = record;\n\t\tstate.recoveryTargets = targets;\n\t\tstate.recoveryAvailable = false;\n\t\tstate.blockedReplays = 0;\n\t\tif (reservation?.executionKey !== executionKey) state.reservedExecutions++;\n\n\t\tstate.failures++;\n\n\t\tconst operationFailureLimit =\n\t\t\trecord.state === \"failed\"\n\t\t\t\t? BASE_FAILURE_EXECUTIONS_PER_OPERATION +\n\t\t\t\t\tgetToolExecutionUnchangedRetryLimit(record.failureCode) +\n\t\t\t\t\tMAX_RECOVERY_PROBES_PER_OPERATION\n\t\t\t\t: MAX_REJECTIONS_PER_OPERATION;\n\t\tif (state.failures >= operationFailureLimit) {\n\t\t\tif (usesOperationLocalExhaustion(tool)) {\n\t\t\t\tstate.operationCircuitOpen = true;\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tthis.halted = {\n\t\t\t\trecord,\n\t\t\t\tdiagnostic: `Recovery circuit opened after ${state.failures} failed outcomes for one operation.`,\n\t\t\t};\n\t\t}\n\t}\n\n\tprivate observeSuccess(tool: AgentTool<any>, args: unknown, result: AgentToolResult<any>): void {\n\t\tconst successfulExecutionKey = getToolExecutionKey(tool.name, args);\n\t\t// Tool results are appended to the transcript after the current execution batch completes.\n\t\t// Until then the last persisted failure is stale authority: remember the exact success so a\n\t\t// later sequential call in this same batch cannot resurrect that failure from the transcript.\n\t\tthis.resolvedBeforeTranscriptCommit.add(successfulExecutionKey);\n\t\tconst evidenceTargets = readRecoveryEvidenceTargets(tool, args, result);\n\t\tfor (const [executionKey, state] of this.statesByExecutionKey) {\n\t\t\tif (executionKey === successfulExecutionKey) {\n\t\t\t\tthis.clearResolvedState(executionKey);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (\n\t\t\t\tstate.recoveryProbes < MAX_RECOVERY_PROBES_PER_OPERATION &&\n\t\t\t\thasSharedRecoveryTarget(state.recoveryTargets, evidenceTargets)\n\t\t\t) {\n\t\t\t\tstate.recoveryAvailable = true;\n\t\t\t\tstate.blockedReplays = 0;\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate clearResolvedState(executionKey: string): void {\n\t\tthis.statesByExecutionKey.delete(executionKey);\n\t}\n\n\tprivate trackTranscript(messages: readonly AgentMessage[]): void {\n\t\tconst tail = messages[messages.length - 1];\n\t\tif (\n\t\t\tmessages !== this.transcriptMessages ||\n\t\t\tmessages.length !== this.transcriptLength ||\n\t\t\ttail !== this.transcriptTail\n\t\t) {\n\t\t\t// An advanced transcript now authoritatively records completed results. The temporary\n\t\t\t// exact-success overlay is bounded to one uncommitted execution batch.\n\t\t\tthis.resolvedBeforeTranscriptCommit.clear();\n\t\t}\n\t\tthis.transcriptMessages = messages;\n\t\tthis.transcriptLength = messages.length;\n\t\tthis.transcriptTail = tail;\n\t}\n\n\tprivate getHotState(executionKey: string): FailureRecoveryState | undefined {\n\t\tconst state = this.statesByExecutionKey.get(executionKey);\n\t\tif (!state) return undefined;\n\t\tthis.statesByExecutionKey.delete(executionKey);\n\t\tthis.statesByExecutionKey.set(executionKey, state);\n\t\treturn state;\n\t}\n\n\tprivate retainHotState(executionKey: string, state: FailureRecoveryState): void {\n\t\tthis.statesByExecutionKey.delete(executionKey);\n\t\tthis.statesByExecutionKey.set(executionKey, state);\n\t\twhile (this.statesByExecutionKey.size > MAX_HOT_RECOVERY_STATES) {\n\t\t\tconst oldest = this.statesByExecutionKey.keys().next().value;\n\t\t\tif (oldest === undefined) break;\n\t\t\tthis.statesByExecutionKey.delete(oldest);\n\t\t}\n\t}\n\n\tprivate restoreOperationFromTranscript(executionKey: string): FailureRecoveryState | undefined {\n\t\tlet restoredState: FailureRecoveryState | undefined;\n\t\tforEachPairedToolResult(this.transcriptMessages, ({ tool, args, executionKey: candidateKey, result }) => {\n\t\t\tif (candidateKey !== executionKey) return;\n\t\t\tconst reduction = this.reduceTranscriptResult(restoredState, tool, args, result);\n\t\t\tif (reduction.kind === \"resolved\") {\n\t\t\t\trestoredState = undefined;\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (reduction.kind === \"failed\") restoredState = reduction.state;\n\t\t});\n\t\tif (restoredState) this.retainHotState(executionKey, restoredState);\n\t\treturn restoredState;\n\t}\n\n\tprivate reduceTranscriptResult(\n\t\tstate: FailureRecoveryState | undefined,\n\t\ttool: string,\n\t\targs: unknown,\n\t\tresult: ToolResultMessage,\n\t): TranscriptRecoveryReduction {\n\t\tif (!result.isError) return { kind: \"resolved\" };\n\t\tconst record = restoreToolFailureRecord(result, tool, args);\n\t\tconst visibleCode = readVisibleToolFailureCode(result);\n\t\tif (isPromptScopedFailureCode(visibleCode) || isPromptScopedFailureCode(record.failureCode)) {\n\t\t\treturn { kind: \"ignored\", state };\n\t\t}\n\t\tconst next = state ?? createFailureRecoveryState(record, []);\n\t\tnext.record = record;\n\t\tif (isClosedOperationFailureCode(visibleCode)) {\n\t\t\tnext.operationCircuitOpen = true;\n\t\t\tnext.blockedReplays = MAX_BLOCKED_REPLAYS_PER_FAILURE;\n\t\t\tnext.recoveryAvailable = false;\n\t\t\treturn { kind: \"failed\", state: next };\n\t\t}\n\t\tif (visibleCode === \"repeated_failed_operation\") {\n\t\t\tnext.blockedReplays++;\n\t\t\treturn { kind: \"failed\", state: next };\n\t\t}\n\t\tnext.reservedExecutions++;\n\t\tnext.failures++;\n\t\treturn { kind: \"failed\", state: next };\n\t}\n}\n\nfunction usesOperationLocalExhaustion(tool: AgentTool<any> | undefined): boolean {\n\treturn tool?.failureRecovery?.exhaustionScope === \"operation\";\n}\n\nfunction readFailureEvidence(\n\ttool: AgentTool<any>,\n\targs: unknown,\n\tfailure: AgentToolFailureEvidenceContext,\n): string | undefined {\n\ttry {\n\t\tconst contract = tool.failureRecovery;\n\t\tconst getEvidence = contract?.getFailureEvidence;\n\t\tif (!getEvidence) return undefined;\n\t\tconst evidence = Reflect.apply(getEvidence, contract, [args, failure]);\n\t\treturn sanitizeToolFailureEvidence(evidence);\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n\nfunction createFailureRecoveryState(\n\trecord: ToolFailureMemoryRecord,\n\trecoveryTargets: readonly AgentToolFailureRecoveryTarget[],\n): FailureRecoveryState {\n\treturn {\n\t\trecord,\n\t\trecoveryTargets,\n\t\treservedExecutions: 0,\n\t\tfailures: 0,\n\t\trecoveryProbes: 0,\n\t\tblockedReplays: 0,\n\t\trecoveryAvailable: false,\n\t\toperationCircuitOpen: false,\n\t};\n}\n\nfunction readFailureTargets(\n\ttool: AgentTool<any>,\n\targs: unknown,\n\tfailureCode: string,\n): readonly AgentToolFailureRecoveryTarget[] {\n\ttry {\n\t\tconst contract = tool.failureRecovery;\n\t\tconst getTargets = contract?.getFailureTargets;\n\t\tif (!getTargets) return [];\n\t\tconst targets = Reflect.apply(getTargets, contract, [args, { failureCode }]);\n\t\treturn sanitizeRecoveryTargets(targets);\n\t} catch {\n\t\treturn [];\n\t}\n}\n\nfunction sanitizeRecoveryTargets(value: unknown): readonly AgentToolFailureRecoveryTarget[] {\n\tif (!Array.isArray(value)) return [];\n\tconst targets: AgentToolFailureRecoveryTarget[] = [];\n\tfor (const candidate of value) {\n\t\tif (targets.length >= MAX_RECOVERY_TARGETS) break;\n\t\tif (!candidate || typeof candidate !== \"object\" || Array.isArray(candidate)) continue;\n\t\tconst { authority, kind, scope } = candidate as { authority?: unknown; kind?: unknown; scope?: unknown };\n\t\tif (!isAgentToolFailureRecoveryAuthority(authority) || !validTargetKind(kind) || !validTargetScope(scope)) {\n\t\t\tcontinue;\n\t\t}\n\t\tif (targets.some((target) => sameRecoveryTarget(target, { authority, kind, scope }))) continue;\n\t\ttargets.push({ authority, kind, scope });\n\t}\n\treturn targets;\n}\n\nfunction validTargetKind(value: unknown): value is string {\n\treturn (\n\t\ttypeof value === \"string\" &&\n\t\tvalue.length > 0 &&\n\t\tvalue.length <= MAX_TARGET_KIND_CHARS &&\n\t\tTARGET_KIND_PATTERN.test(value)\n\t);\n}\n\nfunction validTargetScope(value: unknown): value is string {\n\treturn (\n\t\ttypeof value === \"string\" && value.length > 0 && value.length <= MAX_TARGET_SCOPE_CHARS && !value.includes(\"\\0\")\n\t);\n}\n\nfunction readAvailableRecoveryActions(\n\ttools: readonly AgentTool<any>[],\n\ttargets: readonly AgentToolFailureRecoveryTarget[],\n): readonly AvailableRecoveryAction[] {\n\tif (targets.length === 0) return [];\n\tconst actions: AvailableRecoveryAction[] = [];\n\tconst seen = new Set<string>();\n\tfor (const tool of tools) {\n\t\tfor (const candidate of readDeclaredRecoveryActions(tool)) {\n\t\t\tif (actions.length >= MAX_RECOVERY_ACTIONS) return actions;\n\t\t\tconst action = parseRecoveryAction(candidate);\n\t\t\tif (\n\t\t\t\t!action ||\n\t\t\t\t!targets.some((target) => target.authority === action.authority && target.kind === action.targetKind)\n\t\t\t) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tconst instruction = truncate(action.instruction.trim(), MAX_ACTION_INSTRUCTION_CHARS);\n\t\t\tif (!instruction) continue;\n\t\t\tconst key = `${tool.name}\\0${action.kind}\\0${instruction}`;\n\t\t\tif (seen.has(key)) continue;\n\t\t\tseen.add(key);\n\t\t\tactions.push({ toolName: tool.name, kind: action.kind, instruction });\n\t\t}\n\t}\n\treturn actions;\n}\n\nfunction readDeclaredRecoveryActions(tool: AgentTool<any>): readonly unknown[] {\n\ttry {\n\t\tconst declared = tool.failureRecovery?.actions;\n\t\tif (!Array.isArray(declared)) return [];\n\t\tconst actions: unknown[] = [];\n\t\tconst count = Math.min(declared.length, MAX_RECOVERY_ACTIONS);\n\t\tfor (let index = 0; index < count; index++) actions.push(declared[index]);\n\t\treturn actions;\n\t} catch {\n\t\treturn [];\n\t}\n}\n\nfunction parseRecoveryAction(value: unknown): ParsedRecoveryAction | undefined {\n\ttry {\n\t\tif (!value || typeof value !== \"object\" || Array.isArray(value)) return undefined;\n\t\tconst candidate = value as {\n\t\t\tkind?: unknown;\n\t\t\tauthority?: unknown;\n\t\t\ttargetKind?: unknown;\n\t\t\tinstruction?: unknown;\n\t\t\tgetEvidence?: unknown;\n\t\t};\n\t\tif (\n\t\t\t!isAgentToolFailureRecoveryAuthority(candidate.authority) ||\n\t\t\t!validTargetKind(candidate.targetKind) ||\n\t\t\ttypeof candidate.instruction !== \"string\"\n\t\t) {\n\t\t\treturn undefined;\n\t\t}\n\t\tif (candidate.kind === \"correct\") {\n\t\t\treturn {\n\t\t\t\tkind: candidate.kind,\n\t\t\t\tauthority: candidate.authority,\n\t\t\t\ttargetKind: candidate.targetKind,\n\t\t\t\tinstruction: candidate.instruction,\n\t\t\t};\n\t\t}\n\t\tif (candidate.kind !== \"repair\" || typeof candidate.getEvidence !== \"function\") return undefined;\n\t\tconst getEvidence = candidate.getEvidence;\n\t\treturn {\n\t\t\tkind: candidate.kind,\n\t\t\tauthority: candidate.authority,\n\t\t\ttargetKind: candidate.targetKind,\n\t\t\tinstruction: candidate.instruction,\n\t\t\tgetEvidence: (params, result) => Reflect.apply(getEvidence, value, [params, result]),\n\t\t};\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n\nfunction readRecoveryEvidenceTargets(\n\ttool: AgentTool<any>,\n\targs: unknown,\n\tresult: AgentToolResult<any>,\n): readonly AgentToolFailureRecoveryTarget[] {\n\tconst targets: AgentToolFailureRecoveryTarget[] = [];\n\tfor (const candidate of readDeclaredRecoveryActions(tool)) {\n\t\tconst action = parseRecoveryAction(candidate);\n\t\tif (targets.length >= MAX_RECOVERY_TARGETS || !action || action.kind !== \"repair\" || !action.getEvidence) {\n\t\t\tcontinue;\n\t\t}\n\t\tlet scopes: unknown;\n\t\ttry {\n\t\t\tscopes = action.getEvidence(args, result);\n\t\t} catch {\n\t\t\tcontinue;\n\t\t}\n\t\tif (!Array.isArray(scopes)) continue;\n\t\tfor (const scope of scopes) {\n\t\t\tif (targets.length >= MAX_RECOVERY_TARGETS) break;\n\t\t\tif (!validTargetScope(scope)) continue;\n\t\t\tconst target = { authority: action.authority, kind: action.targetKind, scope };\n\t\t\tif (!targets.some((candidate) => sameRecoveryTarget(candidate, target))) targets.push(target);\n\t\t}\n\t}\n\treturn targets;\n}\n\nfunction formatRecoveryGuidance(\n\tfailureCode: string,\n\tactions: readonly AvailableRecoveryAction[],\n\tunchangedRetryRemaining: boolean,\n): string {\n\tconst hasTimeoutRetryPolicy = getToolExecutionUnchangedRetryLimit(failureCode) > 0;\n\tconst timeoutPolicy = hasTimeoutRetryPolicy\n\t\t? unchangedRetryRemaining\n\t\t\t? \"Timeout policy allows 1 unchanged retry; if it fails, never retry unchanged.\"\n\t\t\t: \"Timeout unchanged retry exhausted; never retry unchanged.\"\n\t\t: undefined;\n\tif (actions.length === 0) {\n\t\tif (timeoutPolicy) return `${timeoutPolicy} Change/narrow operation, or report blocker.`;\n\t\treturn \"No loaded tool declares recovery. Never retry unchanged. Use materially different operation justified by diagnostic/schema, or report blocker.\";\n\t}\n\tconst available = actions.map((action) => `${action.toolName} ${action.kind}: ${action.instruction}`).join(\" \");\n\tconst hasRepair = actions.some((action) => action.kind === \"repair\");\n\tconst authority = hasRepair\n\t\t? \"Only exact matching repair evidence grants 1 probe; else change operation.\"\n\t\t: \"Actions require changed operation; unchanged remains blocked.\";\n\treturn truncate(\n\t\t`${timeoutPolicy ? `${timeoutPolicy} ` : \"\"}Loaded actions: ${available} ${authority}`,\n\t\tMAX_RECOVERY_GUIDANCE_CHARS,\n\t);\n}\n\nfunction truncate(value: string, maxChars: number): string {\n\tif (value.length <= maxChars) return value;\n\treturn `${value.slice(0, maxChars - 1)}…`;\n}\n\nfunction sameRecoveryTarget(left: AgentToolFailureRecoveryTarget, right: AgentToolFailureRecoveryTarget): boolean {\n\treturn left.authority === right.authority && left.kind === right.kind && left.scope === right.scope;\n}\n\nfunction hasSharedRecoveryTarget(\n\tleft: readonly AgentToolFailureRecoveryTarget[],\n\tright: readonly AgentToolFailureRecoveryTarget[],\n): boolean {\n\tif (left.length > right.length) return hasSharedRecoveryTarget(right, left);\n\treturn left.some((target) => right.some((candidate) => sameRecoveryTarget(target, candidate)));\n}\n"]}
|
|
1
|
+
{"version":3,"file":"tool-failure-recovery-gate.js","sourceRoot":"","sources":["../src/tool-failure-recovery-gate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mCAAmC,EAAE,MAAM,wCAAwC,CAAC;AAC7F,OAAO,EACN,mBAAmB,EACnB,4BAA4B,EAC5B,gCAAgC,EAChC,yBAAyB,EACzB,0BAA0B,EAC1B,wBAAwB,EACxB,2BAA2B,GAE3B,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,6BAA6B,EAAE,MAAM,qCAAqC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ecutionKeyHashParts,\n\tgetToolFailureRecordExecutionKey,\n\tisPromptScopedFailureCode,\n\treadVisibleToolFailureCode,\n\trestoreToolFailureRecord,\n\tsanitizeToolFailureEvidence,\n\ttype ToolFailureMemoryRecord,\n} from \"./tool-failure-memory.ts\";\nimport { TOOL_FAILURE_READMISSION_RULE } from \"./tool-failure-recovery-protocol.ts\";\nimport type {\n\tAgentMessage,\n\tAgentTool,\n\tAgentToolFailureEvidenceContext,\n\tAgentToolFailureRecoveryAction,\n\tAgentToolFailureRecoveryTarget,\n} from \"./types.ts\";\nimport { isAgentToolFailureRecoveryAuthority } from \"./types.ts\";\n\nconst MAX_TRACKED_OPERATIONS = 64;\nconst SEEN_EXECUTION_FILTER_BYTES = 64 * 1024;\nconst MAX_RECOVERY_TARGETS = 8;\nconst MAX_RECOVERY_ACTIONS = 8;\nconst MAX_TARGET_KIND_CHARS = 64;\nconst MAX_TARGET_SCOPE_CHARS = 32_768;\nconst MAX_ACTION_INSTRUCTION_CHARS = 160;\nconst MAX_RECOVERY_GUIDANCE_CHARS = 320;\nconst TARGET_KIND_PATTERN = /^[a-z0-9][a-z0-9._:-]*$/;\n\nexport interface ToolFailureRecoveryPlan {\n\ttargets: readonly AgentToolFailureRecoveryTarget[];\n\tguidance: string;\n\tevidence?: string;\n}\n\nexport type ToolFailureRecoveryGateEffect =\n\t| {\n\t\t\tkind: \"unproductive\";\n\t\t\ttool?: AgentTool<any>;\n\t\t\trecord: ToolFailureMemoryRecord;\n\t\t\targs: unknown;\n\t }\n\t| { kind: \"success\"; tool: AgentTool<any>; args: unknown };\n\nexport type ToolFailureRecoveryAdmission = { kind: \"allowed\" } | { kind: \"blocked\"; record: ToolFailureMemoryRecord };\n\n/**\n * What is known about one exact operation the last time it ran to completion.\n *\n * `unproductive` marks an execution that produced nothing the agent can build on — the tool failed,\n * or it completed and reported a negative operation status. Either way, running the identical\n * operation again before anything else has changed cannot yield different information.\n */\ninterface OperationState {\n\trecord: ToolFailureMemoryRecord;\n\tworldCursorAtLastExecution: number;\n\t/**\n\t * Immediate identical retries this failure class still allows, from the execution-error catalogue.\n\t * Some classes are transient by nature — a timeout, a throttled backend — and repeating the exact\n\t * call really can return something new. Spending these does not depend on the world moving.\n\t */\n\tunchangedRetriesRemaining: number;\n}\n\ninterface AvailableRecoveryAction {\n\ttoolName: string;\n\tkind: \"correct\" | \"repair\";\n\tinstruction: string;\n}\n\n/**\n * Bounded negative lookup for exact execution identities.\n *\n * A miss proves the operation has not been unproductive while this gate has been alive. A hit only\n * means \"possibly seen\" and must be verified against the transcript, so collisions can cost a scan\n * but can never deny an execution. Keeping this separate from the hot state cache lets old\n * operations survive eviction without retaining one live object graph per historical operation.\n */\nclass SeenExecutionFilter {\n\tprivate readonly bits = new Uint8Array(SEEN_EXECUTION_FILTER_BYTES);\n\n\tadd(executionKey: string): void {\n\t\tfor (const hash of getToolExecutionKeyHashParts(executionKey)) this.set(hash);\n\t}\n\n\tmightContain(executionKey: string): boolean {\n\t\tfor (const hash of getToolExecutionKeyHashParts(executionKey)) {\n\t\t\tif (!this.has(hash)) return false;\n\t\t}\n\t\treturn true;\n\t}\n\n\tprivate set(hash: number): void {\n\t\tconst bit = (hash >>> 0) % (SEEN_EXECUTION_FILTER_BYTES * 8);\n\t\tthis.bits[bit >>> 3] |= 1 << (bit & 7);\n\t}\n\n\tprivate has(hash: number): boolean {\n\t\tconst bit = (hash >>> 0) % (SEEN_EXECUTION_FILTER_BYTES * 8);\n\t\treturn (this.bits[bit >>> 3] & (1 << (bit & 7))) !== 0;\n\t}\n}\n\n/**\n * Admission governor for exact tool operations.\n *\n * It answers exactly one question: can repeating this identical operation, right now, tell the agent\n * anything it does not already know? An operation whose last execution was unproductive is admitted\n * again once the world has moved — that is, once any tool has succeeded, or the user has spoken,\n * since that operation last ran. Until then the replay is refused, because its result is already in\n * the transcript.\n *\n * The world cursor is the whole budget. There are no per-operation attempt counts, no probe quotas,\n * and no circuits that stay open for the rest of the session: correct repair work always re-admits\n * the operation it repaired, however many times the agent needs it.\n *\n * Refusal is always local to one operation. This gate cannot deny an unrelated tool, cannot\n * terminate a tool batch, and cannot end a run — a stuck agent is the runaway-loop backstop's\n * problem (`maxStallTurns`), and reporting a dead end is the model's own job.\n */\nexport class ToolFailureRecoveryGate {\n\tprivate readonly statesByExecutionKey = new Map<string, OperationState>();\n\tprivate readonly seenUnproductiveExecutions = new SeenExecutionFilter();\n\t/** Exact successes not yet present in the transcript snapshot consulted by admission. */\n\tprivate readonly resolvedBeforeTranscriptCommit = new Set<string>();\n\tprivate transcriptMessages: readonly AgentMessage[] = [];\n\tprivate transcriptLength = 0;\n\tprivate transcriptTail: AgentMessage | undefined;\n\tprivate restoredFromTranscript = false;\n\tprivate worldCursor = 0;\n\n\tisEmpty(): boolean {\n\t\treturn this.statesByExecutionKey.size === 0;\n\t}\n\n\trestoreFromMessages(messages: readonly AgentMessage[]): void {\n\t\tthis.trackTranscript(messages);\n\t\tif (this.restoredFromTranscript || !this.isEmpty()) return;\n\t\tthis.restoredFromTranscript = true;\n\t\tthis.worldCursor = walkTranscript(messages, (event) => {\n\t\t\tif (event.kind === \"resolved\") {\n\t\t\t\tthis.statesByExecutionKey.delete(event.executionKey);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tthis.seenUnproductiveExecutions.add(event.executionKey);\n\t\t\t// A restored state starts with no transient-retry allowance: the transcript already shows the\n\t\t\t// attempts that were made, and the new user turn that triggers a restore has itself moved the\n\t\t\t// world, which is the broader permission anyway.\n\t\t\tthis.retainState(event.executionKey, {\n\t\t\t\trecord: event.record,\n\t\t\t\tworldCursorAtLastExecution: event.worldCursor,\n\t\t\t\tunchangedRetriesRemaining: 0,\n\t\t\t});\n\t\t});\n\t}\n\n\t/**\n\t * Record that the world moved for a reason other than a tool result — a new user turn. Authority,\n\t * intent, and files can all change across one, so every operation becomes worth attempting again.\n\t */\n\tnoteWorldAdvance(): void {\n\t\tthis.worldCursor++;\n\t}\n\n\tplanFailure(\n\t\tfailedTool: AgentTool<any>,\n\t\targs: unknown,\n\t\tfailure: AgentToolFailureEvidenceContext,\n\t\tavailableTools: readonly AgentTool<any>[],\n\t): ToolFailureRecoveryPlan {\n\t\tconst targets = readFailureTargets(failedTool, args, failure.failureCode);\n\t\tconst actions = readAvailableRecoveryActions(availableTools, targets);\n\t\tconst evidence = readFailureEvidence(failedTool, args, failure);\n\t\treturn {\n\t\t\ttargets,\n\t\t\tguidance: formatRecoveryGuidance(\n\t\t\t\tactions,\n\t\t\t\tthis.transientRetryStanding(getToolExecutionKey(failedTool.name, args), failure.failureCode),\n\t\t\t),\n\t\t\t...(evidence ? { evidence } : {}),\n\t\t};\n\t}\n\n\t/**\n\t * Whether this failure class allows an immediate identical retry, and whether one survives the\n\t * failure about to be recorded. Read before that failure is observed, so it mirrors exactly what\n\t * `observeUnproductive` is about to leave behind.\n\t */\n\tprivate transientRetryStanding(executionKey: string, failureCode: string): TransientRetryStanding {\n\t\tconst retryLimit = getToolExecutionUnchangedRetryLimit(failureCode);\n\t\tif (retryLimit === 0) return \"none\";\n\t\tconst state = this.statesByExecutionKey.get(executionKey);\n\t\tconst remaining =\n\t\t\t!state || state.worldCursorAtLastExecution !== this.worldCursor ? retryLimit : state.unchangedRetriesRemaining;\n\t\treturn remaining > 0 ? \"available\" : \"spent\";\n\t}\n\n\tadmit(\n\t\ttool: AgentTool<any>,\n\t\targs: unknown,\n\t\trecord: ToolFailureMemoryRecord | undefined,\n\t\tmessages: readonly AgentMessage[] = this.transcriptMessages,\n\t): ToolFailureRecoveryAdmission {\n\t\tthis.trackTranscript(messages);\n\t\tconst executionKey = getToolExecutionKey(tool.name, args);\n\t\tif (this.resolvedBeforeTranscriptCommit.has(executionKey)) return { kind: \"allowed\" };\n\t\tlet state = this.getHotState(executionKey);\n\t\tif (!state && this.seenUnproductiveExecutions.mightContain(executionKey)) {\n\t\t\tstate = this.restoreOperationFromTranscript(executionKey);\n\t\t}\n\t\tif (\n\t\t\t!state &&\n\t\t\trecord &&\n\t\t\tgetToolFailureRecordExecutionKey(record) === executionKey &&\n\t\t\t// A prompt-scoped block is cleared by a new owner prompt, never by the agent. It is not a\n\t\t\t// repetition state, so it must not become one through the caller's failure memory either.\n\t\t\t!isPromptScopedFailureCode(record.failureCode)\n\t\t) {\n\t\t\tstate = { record, worldCursorAtLastExecution: this.worldCursor, unchangedRetriesRemaining: 0 };\n\t\t\tthis.retainState(executionKey, state);\n\t\t}\n\t\tif (!state) return { kind: \"allowed\" };\n\t\tif (record && getToolFailureRecordExecutionKey(record) === executionKey) state.record = record;\n\t\tif (this.worldCursor > state.worldCursorAtLastExecution) return { kind: \"allowed\" };\n\t\tif (state.unchangedRetriesRemaining > 0) {\n\t\t\tstate.unchangedRetriesRemaining--;\n\t\t\treturn { kind: \"allowed\" };\n\t\t}\n\t\treturn { kind: \"blocked\", record: state.record };\n\t}\n\n\tapply(effect: ToolFailureRecoveryGateEffect | undefined): void {\n\t\tif (!effect) return;\n\t\tif (effect.kind === \"success\") {\n\t\t\tthis.observeSuccess(effect.tool, effect.args);\n\t\t\treturn;\n\t\t}\n\t\tthis.observeUnproductive(effect.record, effect.args);\n\t}\n\n\tprivate observeUnproductive(record: ToolFailureMemoryRecord, args: unknown): void {\n\t\tconst executionKey = getToolExecutionKey(record.tool, args);\n\t\tthis.resolvedBeforeTranscriptCommit.delete(executionKey);\n\t\tthis.seenUnproductiveExecutions.add(executionKey);\n\t\tconst previous = this.statesByExecutionKey.get(executionKey);\n\t\t// The transient-retry allowance belongs to one episode: it refills when the world has moved\n\t\t// since this operation last ran, and is otherwise spent down so a transient class cannot\n\t\t// bankroll an unbounded run of identical calls.\n\t\tconst startsFreshEpisode = !previous || previous.worldCursorAtLastExecution !== this.worldCursor;\n\t\tthis.retainState(executionKey, {\n\t\t\trecord,\n\t\t\tworldCursorAtLastExecution: this.worldCursor,\n\t\t\tunchangedRetriesRemaining: startsFreshEpisode\n\t\t\t\t? getToolExecutionUnchangedRetryLimit(record.failureCode)\n\t\t\t\t: previous.unchangedRetriesRemaining,\n\t\t});\n\t}\n\n\tprivate observeSuccess(tool: AgentTool<any>, args: unknown): void {\n\t\tconst executionKey = getToolExecutionKey(tool.name, args);\n\t\t// Tool results are appended to the transcript after the current execution batch completes.\n\t\t// Until then the last persisted failure is stale authority: remember the exact success so a\n\t\t// later sequential call in this same batch cannot resurrect that failure from the transcript.\n\t\tthis.resolvedBeforeTranscriptCommit.add(executionKey);\n\t\tthis.statesByExecutionKey.delete(executionKey);\n\t\tthis.worldCursor++;\n\t}\n\n\tprivate trackTranscript(messages: readonly AgentMessage[]): void {\n\t\tconst tail = messages[messages.length - 1];\n\t\tif (\n\t\t\tmessages !== this.transcriptMessages ||\n\t\t\tmessages.length !== this.transcriptLength ||\n\t\t\ttail !== this.transcriptTail\n\t\t) {\n\t\t\t// An advanced transcript now authoritatively records completed results. The temporary\n\t\t\t// exact-success overlay is bounded to one uncommitted execution batch.\n\t\t\tthis.resolvedBeforeTranscriptCommit.clear();\n\t\t}\n\t\tthis.transcriptMessages = messages;\n\t\tthis.transcriptLength = messages.length;\n\t\tthis.transcriptTail = tail;\n\t}\n\n\tprivate getHotState(executionKey: string): OperationState | undefined {\n\t\tconst state = this.statesByExecutionKey.get(executionKey);\n\t\tif (!state) return undefined;\n\t\tthis.statesByExecutionKey.delete(executionKey);\n\t\tthis.statesByExecutionKey.set(executionKey, state);\n\t\treturn state;\n\t}\n\n\tprivate retainState(executionKey: string, state: OperationState): void {\n\t\tthis.statesByExecutionKey.delete(executionKey);\n\t\tthis.statesByExecutionKey.set(executionKey, state);\n\t\twhile (this.statesByExecutionKey.size > MAX_TRACKED_OPERATIONS) {\n\t\t\tconst oldest = this.statesByExecutionKey.keys().next().value;\n\t\t\tif (oldest === undefined) break;\n\t\t\tthis.statesByExecutionKey.delete(oldest);\n\t\t}\n\t}\n\n\tprivate restoreOperationFromTranscript(executionKey: string): OperationState | undefined {\n\t\tlet restored: OperationState | undefined;\n\t\twalkTranscript(this.transcriptMessages, (event) => {\n\t\t\tif (event.executionKey !== executionKey) return;\n\t\t\trestored =\n\t\t\t\tevent.kind === \"resolved\"\n\t\t\t\t\t? undefined\n\t\t\t\t\t: { record: event.record, worldCursorAtLastExecution: event.worldCursor, unchangedRetriesRemaining: 0 };\n\t\t});\n\t\tif (restored) this.retainState(executionKey, restored);\n\t\treturn restored;\n\t}\n}\n\ntype TranscriptEvent =\n\t| { kind: \"resolved\"; executionKey: string; worldCursor: number }\n\t| { kind: \"unproductive\"; executionKey: string; worldCursor: number; record: ToolFailureMemoryRecord };\n\n/**\n * Replay a transcript's world advances in order, reporting each completed operation with the cursor\n * value that was current when it ran. Advances are counted exactly as the live gate counts them —\n * every successful tool result, plus every user turn — so a resumed session admits precisely what an\n * uninterrupted one would. Returns the final cursor.\n */\nfunction walkTranscript(messages: readonly AgentMessage[], visit: (event: TranscriptEvent) => void): number {\n\tconst callsById = new Map<string, { name: string; args: unknown }>();\n\tlet worldCursor = 0;\n\tfor (const message of messages) {\n\t\tif (message.role === \"user\") {\n\t\t\tworldCursor++;\n\t\t\tcontinue;\n\t\t}\n\t\tif (message.role === \"assistant\") {\n\t\t\tfor (const block of message.content) {\n\t\t\t\tif (block.type === \"toolCall\") callsById.set(block.id, { name: block.name, args: block.arguments });\n\t\t\t}\n\t\t\tcontinue;\n\t\t}\n\t\tif (message.role !== \"toolResult\") continue;\n\t\tconst call = callsById.get(message.toolCallId);\n\t\tif (!call) continue;\n\t\tcallsById.delete(message.toolCallId);\n\t\tconst executionKey = getToolExecutionKey(call.name, call.args);\n\t\tif (!message.isError) {\n\t\t\tworldCursor++;\n\t\t\tvisit({ kind: \"resolved\", executionKey, worldCursor });\n\t\t\tcontinue;\n\t\t}\n\t\tconst record = restoreToolFailureRecord(message, call.name, call.args);\n\t\t// A prompt-scoped block is cleared by a new owner prompt, not by anything the agent can do, so\n\t\t// it never becomes a repetition state.\n\t\tif (\n\t\t\tisPromptScopedFailureCode(readVisibleToolFailureCode(message)) ||\n\t\t\tisPromptScopedFailureCode(record.failureCode)\n\t\t) {\n\t\t\tcontinue;\n\t\t}\n\t\tvisit({ kind: \"unproductive\", executionKey, worldCursor, record });\n\t}\n\treturn worldCursor;\n}\n\nfunction readFailureEvidence(\n\ttool: AgentTool<any>,\n\targs: unknown,\n\tfailure: AgentToolFailureEvidenceContext,\n): string | undefined {\n\ttry {\n\t\tconst contract = tool.failureRecovery;\n\t\tconst getEvidence = contract?.getFailureEvidence;\n\t\tif (!getEvidence) return undefined;\n\t\tconst evidence = Reflect.apply(getEvidence, contract, [args, failure]);\n\t\treturn sanitizeToolFailureEvidence(evidence);\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n\nfunction readFailureTargets(\n\ttool: AgentTool<any>,\n\targs: unknown,\n\tfailureCode: string,\n): readonly AgentToolFailureRecoveryTarget[] {\n\ttry {\n\t\tconst contract = tool.failureRecovery;\n\t\tconst getTargets = contract?.getFailureTargets;\n\t\tif (!getTargets) return [];\n\t\tconst targets = Reflect.apply(getTargets, contract, [args, { failureCode }]);\n\t\treturn sanitizeRecoveryTargets(targets);\n\t} catch {\n\t\treturn [];\n\t}\n}\n\nfunction sanitizeRecoveryTargets(value: unknown): readonly AgentToolFailureRecoveryTarget[] {\n\tif (!Array.isArray(value)) return [];\n\tconst targets: AgentToolFailureRecoveryTarget[] = [];\n\tfor (const candidate of value) {\n\t\tif (targets.length >= MAX_RECOVERY_TARGETS) break;\n\t\tif (!candidate || typeof candidate !== \"object\" || Array.isArray(candidate)) continue;\n\t\tconst { authority, kind, scope } = candidate as { authority?: unknown; kind?: unknown; scope?: unknown };\n\t\tif (!isAgentToolFailureRecoveryAuthority(authority) || !validTargetKind(kind) || !validTargetScope(scope)) {\n\t\t\tcontinue;\n\t\t}\n\t\tif (targets.some((target) => sameRecoveryTarget(target, { authority, kind, scope }))) continue;\n\t\ttargets.push({ authority, kind, scope });\n\t}\n\treturn targets;\n}\n\nfunction validTargetKind(value: unknown): value is string {\n\treturn (\n\t\ttypeof value === \"string\" &&\n\t\tvalue.length > 0 &&\n\t\tvalue.length <= MAX_TARGET_KIND_CHARS &&\n\t\tTARGET_KIND_PATTERN.test(value)\n\t);\n}\n\nfunction validTargetScope(value: unknown): value is string {\n\treturn (\n\t\ttypeof value === \"string\" && value.length > 0 && value.length <= MAX_TARGET_SCOPE_CHARS && !value.includes(\"\\0\")\n\t);\n}\n\nfunction readAvailableRecoveryActions(\n\ttools: readonly AgentTool<any>[],\n\ttargets: readonly AgentToolFailureRecoveryTarget[],\n): readonly AvailableRecoveryAction[] {\n\tif (targets.length === 0) return [];\n\tconst actions: AvailableRecoveryAction[] = [];\n\tconst seen = new Set<string>();\n\tfor (const tool of tools) {\n\t\tfor (const candidate of readDeclaredRecoveryActions(tool)) {\n\t\t\tif (actions.length >= MAX_RECOVERY_ACTIONS) return actions;\n\t\t\tconst action = parseRecoveryAction(candidate);\n\t\t\tif (\n\t\t\t\t!action ||\n\t\t\t\t!targets.some((target) => target.authority === action.authority && target.kind === action.targetKind)\n\t\t\t) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tconst instruction = truncate(action.instruction.trim(), MAX_ACTION_INSTRUCTION_CHARS);\n\t\t\tif (!instruction) continue;\n\t\t\tconst key = `${tool.name}\\0${action.kind}\\0${instruction}`;\n\t\t\tif (seen.has(key)) continue;\n\t\t\tseen.add(key);\n\t\t\tactions.push({ toolName: tool.name, kind: action.kind, instruction });\n\t\t}\n\t}\n\treturn actions;\n}\n\nfunction readDeclaredRecoveryActions(tool: AgentTool<any>): readonly unknown[] {\n\ttry {\n\t\tconst declared = tool.failureRecovery?.actions;\n\t\tif (!Array.isArray(declared)) return [];\n\t\tconst actions: unknown[] = [];\n\t\tconst count = Math.min(declared.length, MAX_RECOVERY_ACTIONS);\n\t\tfor (let index = 0; index < count; index++) actions.push(declared[index]);\n\t\treturn actions;\n\t} catch {\n\t\treturn [];\n\t}\n}\n\nfunction parseRecoveryAction(value: unknown): AgentToolFailureRecoveryAction | undefined {\n\ttry {\n\t\tif (!value || typeof value !== \"object\" || Array.isArray(value)) return undefined;\n\t\tconst candidate = value as {\n\t\t\tkind?: unknown;\n\t\t\tauthority?: unknown;\n\t\t\ttargetKind?: unknown;\n\t\t\tinstruction?: unknown;\n\t\t};\n\t\tif (\n\t\t\t(candidate.kind !== \"correct\" && candidate.kind !== \"repair\") ||\n\t\t\t!isAgentToolFailureRecoveryAuthority(candidate.authority) ||\n\t\t\t!validTargetKind(candidate.targetKind) ||\n\t\t\ttypeof candidate.instruction !== \"string\"\n\t\t) {\n\t\t\treturn undefined;\n\t\t}\n\t\treturn {\n\t\t\tkind: candidate.kind,\n\t\t\tauthority: candidate.authority,\n\t\t\ttargetKind: candidate.targetKind,\n\t\t\tinstruction: candidate.instruction,\n\t\t};\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n\ntype TransientRetryStanding = \"none\" | \"available\" | \"spent\";\n\n/**\n * The admission rule comes first and is never the part that truncates: a model that reads only the\n * opening clause still learns exactly what makes this operation runnable again.\n */\nfunction formatRecoveryGuidance(\n\tactions: readonly AvailableRecoveryAction[],\n\ttransientRetry: TransientRetryStanding,\n): string {\n\tconst rule =\n\t\ttransientRetry === \"available\"\n\t\t\t? `This failure class allows 1 immediate unchanged retry. ${TOOL_FAILURE_READMISSION_RULE}`\n\t\t\t: transientRetry === \"spent\"\n\t\t\t\t? `Unchanged retry spent. ${TOOL_FAILURE_READMISSION_RULE}`\n\t\t\t\t: TOOL_FAILURE_READMISSION_RULE;\n\tif (actions.length === 0) {\n\t\treturn `${rule} Do the corrective work first, or use a materially different operation justified by the diagnostic.`;\n\t}\n\tconst available = actions.map((action) => `${action.toolName} ${action.kind}: ${action.instruction}`).join(\" \");\n\treturn truncate(`${rule} Loaded actions: ${available}`, MAX_RECOVERY_GUIDANCE_CHARS);\n}\n\nfunction truncate(value: string, maxChars: number): string {\n\tif (value.length <= maxChars) return value;\n\treturn `${value.slice(0, maxChars - 1)}…`;\n}\n\nfunction sameRecoveryTarget(left: AgentToolFailureRecoveryTarget, right: AgentToolFailureRecoveryTarget): boolean {\n\treturn left.authority === right.authority && left.kind === right.kind && left.scope === right.scope;\n}\n"]}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
export declare const TOOL_FAILURE_RECOVERY_PROTOCOL_NAME = "mandatory_tool_failure_recovery";
|
|
2
2
|
export declare const TOOL_FAILURE_RECOVERY_PROTOCOL_VERSION = 1;
|
|
3
3
|
export declare const MANDATORY_TOOL_FAILURE_RECOVERY_RULE = "MANDATORY AND NON-NEGOTIABLE.";
|
|
4
|
+
export declare const TOOL_FAILURE_READMISSION_RULE = "The operation is readmitted after another tool succeeds or a new user turn.";
|
|
5
|
+
export declare const TOOL_FAILURE_RETRY_MODEL_RULE = "Retry unchanged only after any other tool succeeds or a new user turn.";
|
|
4
6
|
export declare function mandatoryToolFailureRecoveryMetadata(): {
|
|
5
7
|
MUST: true;
|
|
6
8
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tool-failure-recovery-protocol.d.ts","sourceRoot":"","sources":["../src/tool-failure-recovery-protocol.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,mCAAmC,oCAAoC,CAAC;AACrF,eAAO,MAAM,sCAAsC,IAAI,CAAC;AACxD,eAAO,MAAM,oCAAoC,kCAAkC,CAAC;
|
|
1
|
+
{"version":3,"file":"tool-failure-recovery-protocol.d.ts","sourceRoot":"","sources":["../src/tool-failure-recovery-protocol.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,mCAAmC,oCAAoC,CAAC;AACrF,eAAO,MAAM,sCAAsC,IAAI,CAAC;AACxD,eAAO,MAAM,oCAAoC,kCAAkC,CAAC;AACpF,eAAO,MAAM,6BAA6B,gFACoC,CAAC;AAC/E,eAAO,MAAM,6BAA6B,2EAA2E,CAAC;AAEtH,wBAAgB,oCAAoC,IAAI;IACvD,IAAI,EAAE,IAAI,CAAC;CACX,CAIA;AAED,eAAO,MAAM,+CAA+C,QAQhD,CAAC"}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
export const TOOL_FAILURE_RECOVERY_PROTOCOL_NAME = "mandatory_tool_failure_recovery";
|
|
2
2
|
export const TOOL_FAILURE_RECOVERY_PROTOCOL_VERSION = 1;
|
|
3
3
|
export const MANDATORY_TOOL_FAILURE_RECOVERY_RULE = "MANDATORY AND NON-NEGOTIABLE.";
|
|
4
|
+
export const TOOL_FAILURE_READMISSION_RULE = "The operation is readmitted after another tool succeeds or a new user turn.";
|
|
5
|
+
export const TOOL_FAILURE_RETRY_MODEL_RULE = "Retry unchanged only after any other tool succeeds or a new user turn.";
|
|
4
6
|
export function mandatoryToolFailureRecoveryMetadata() {
|
|
5
7
|
return {
|
|
6
8
|
MUST: true,
|
|
@@ -9,11 +11,10 @@ export function mandatoryToolFailureRecoveryMetadata() {
|
|
|
9
11
|
export const MANDATORY_TOOL_FAILURE_RECOVERY_PROTOCOL_PROMPT = [
|
|
10
12
|
`MANDATORY TOOL FAILURE RECOVERY v${TOOL_FAILURE_RECOVERY_PROTOCOL_VERSION}`,
|
|
11
13
|
MANDATORY_TOOL_FAILURE_RECOVERY_RULE,
|
|
12
|
-
"
|
|
13
|
-
|
|
14
|
-
"-
|
|
15
|
-
"-
|
|
16
|
-
"-
|
|
17
|
-
"- Operation exhaustion closes that operation; use different tools/work. Replaying it or run exhaustion ends the run with a local diagnostic.",
|
|
14
|
+
"MANDATORY: blocked/rejected means not executed.",
|
|
15
|
+
`- MUST:true: ${TOOL_FAILURE_RETRY_MODEL_RULE}`,
|
|
16
|
+
"- Apply repair/next_action first; other tools stay available.",
|
|
17
|
+
"- Irrelevant argument changes do not recover it; refusal keeps tool-result pairing and runs no hooks/tools.",
|
|
18
|
+
"- Only that operation is refused; tools and run continue.",
|
|
18
19
|
].join("\n");
|
|
19
20
|
//# sourceMappingURL=tool-failure-recovery-protocol.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tool-failure-recovery-protocol.js","sourceRoot":"","sources":["../src/tool-failure-recovery-protocol.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,mCAAmC,GAAG,iCAAiC,CAAC;AACrF,MAAM,CAAC,MAAM,sCAAsC,GAAG,CAAC,CAAC;AACxD,MAAM,CAAC,MAAM,oCAAoC,GAAG,+BAA+B,CAAC;
|
|
1
|
+
{"version":3,"file":"tool-failure-recovery-protocol.js","sourceRoot":"","sources":["../src/tool-failure-recovery-protocol.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,mCAAmC,GAAG,iCAAiC,CAAC;AACrF,MAAM,CAAC,MAAM,sCAAsC,GAAG,CAAC,CAAC;AACxD,MAAM,CAAC,MAAM,oCAAoC,GAAG,+BAA+B,CAAC;AACpF,MAAM,CAAC,MAAM,6BAA6B,GACzC,6EAA6E,CAAC;AAC/E,MAAM,CAAC,MAAM,6BAA6B,GAAG,wEAAwE,CAAC;AAEtH,MAAM,UAAU,oCAAoC;IAGnD,OAAO;QACN,IAAI,EAAE,IAAI;KACV,CAAC;AACH,CAAC;AAED,MAAM,CAAC,MAAM,+CAA+C,GAAG;IAC9D,oCAAoC,sCAAsC,EAAE;IAC5E,oCAAoC;IACpC,iDAAiD;IACjD,gBAAgB,6BAA6B,EAAE;IAC/C,+DAA+D;IAC/D,6GAA6G;IAC7G,2DAA2D;CAC3D,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC","sourcesContent":["export const TOOL_FAILURE_RECOVERY_PROTOCOL_NAME = \"mandatory_tool_failure_recovery\";\nexport const TOOL_FAILURE_RECOVERY_PROTOCOL_VERSION = 1;\nexport const MANDATORY_TOOL_FAILURE_RECOVERY_RULE = \"MANDATORY AND NON-NEGOTIABLE.\";\nexport const TOOL_FAILURE_READMISSION_RULE =\n\t\"The operation is readmitted after another tool succeeds or a new user turn.\";\nexport const TOOL_FAILURE_RETRY_MODEL_RULE = \"Retry unchanged only after any other tool succeeds or a new user turn.\";\n\nexport function mandatoryToolFailureRecoveryMetadata(): {\n\tMUST: true;\n} {\n\treturn {\n\t\tMUST: true,\n\t};\n}\n\nexport const MANDATORY_TOOL_FAILURE_RECOVERY_PROTOCOL_PROMPT = [\n\t`MANDATORY TOOL FAILURE RECOVERY v${TOOL_FAILURE_RECOVERY_PROTOCOL_VERSION}`,\n\tMANDATORY_TOOL_FAILURE_RECOVERY_RULE,\n\t\"MANDATORY: blocked/rejected means not executed.\",\n\t`- MUST:true: ${TOOL_FAILURE_RETRY_MODEL_RULE}`,\n\t\"- Apply repair/next_action first; other tools stay available.\",\n\t\"- Irrelevant argument changes do not recover it; refusal keeps tool-result pairing and runs no hooks/tools.\",\n\t\"- Only that operation is refused; tools and run continue.\",\n].join(\"\\n\");\n"]}
|
|
@@ -1,10 +1,19 @@
|
|
|
1
1
|
import type { AssistantMessage } from "@caupulican/pi-ai/types";
|
|
2
2
|
import type { AgentTool } from "./types.ts";
|
|
3
3
|
export declare const NATIVE_TOOL_PROTOCOL_RESIDUE_ERROR = "native_tool_protocol_residue";
|
|
4
|
+
export declare const TOOL_FREE_RESPONSE_TOOL_CALL_ERROR = "tool_free_response_tool_call";
|
|
4
5
|
/**
|
|
5
6
|
* Refuse provider-internal native tool markup that escaped as assistant text. The detector is
|
|
6
7
|
* intentionally narrow: a loaded tool name, a standalone unfenced marker, and an adjacent JSON
|
|
7
8
|
* payload are all required. Nothing is parsed or executed from the rendered text.
|
|
8
9
|
*/
|
|
9
10
|
export declare function rejectNativeToolProtocolResidue(message: AssistantMessage, tools: readonly AgentTool[], textToolProtocolActive: boolean): AssistantMessage;
|
|
11
|
+
/**
|
|
12
|
+
* A provider request with no tools must never leave a tool call in the transcript. Providers can
|
|
13
|
+
* still return a native call or render their internal call syntax despite the empty tool surface,
|
|
14
|
+
* so validate both shapes regardless of whether that tool was loaded in the surrounding run. The
|
|
15
|
+
* provider response is retained as an explicit protocol error with no synthetic prose and no
|
|
16
|
+
* executable call block.
|
|
17
|
+
*/
|
|
18
|
+
export declare function rejectToolCallsFromToolFreeResponse(message: AssistantMessage): AssistantMessage;
|
|
10
19
|
//# sourceMappingURL=tool-protocol-residue.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tool-protocol-residue.d.ts","sourceRoot":"","sources":["../src/tool-protocol-residue.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAChE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAE5C,eAAO,MAAM,kCAAkC,iCAAiC,CAAC;AAkEjF;;;;GAIG;AACH,wBAAgB,+BAA+B,CAC9C,OAAO,EAAE,gBAAgB,EACzB,KAAK,EAAE,SAAS,SAAS,EAAE,EAC3B,sBAAsB,EAAE,OAAO,GAC7B,gBAAgB,CA2BlB"}
|
|
1
|
+
{"version":3,"file":"tool-protocol-residue.d.ts","sourceRoot":"","sources":["../src/tool-protocol-residue.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAChE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAE5C,eAAO,MAAM,kCAAkC,iCAAiC,CAAC;AACjF,eAAO,MAAM,kCAAkC,iCAAiC,CAAC;AAkEjF;;;;GAIG;AACH,wBAAgB,+BAA+B,CAC9C,OAAO,EAAE,gBAAgB,EACzB,KAAK,EAAE,SAAS,SAAS,EAAE,EAC3B,sBAAsB,EAAE,OAAO,GAC7B,gBAAgB,CA2BlB;AAED;;;;;;GAMG;AACH,wBAAgB,mCAAmC,CAAC,OAAO,EAAE,gBAAgB,GAAG,gBAAgB,CAgB/F"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export const NATIVE_TOOL_PROTOCOL_RESIDUE_ERROR = "native_tool_protocol_residue";
|
|
2
|
+
export const TOOL_FREE_RESPONSE_TOOL_CALL_ERROR = "tool_free_response_tool_call";
|
|
2
3
|
/**
|
|
3
4
|
* Marks which lines fall inside a genuinely closed ```/~~~ fence (open and matching close both
|
|
4
5
|
* present). A fence that never closes does not suppress anything: it is not treated as covering
|
|
@@ -46,7 +47,7 @@ function findRenderedToolMarker(text, toolNames) {
|
|
|
46
47
|
continue;
|
|
47
48
|
const match = /^to=functions\.([A-Za-z][A-Za-z0-9_-]{0,63})\s+code$/.exec(trimmed);
|
|
48
49
|
const toolName = match?.[1];
|
|
49
|
-
if (!toolName || !toolNames.has(toolName))
|
|
50
|
+
if (!toolName || (toolNames && !toolNames.has(toolName)))
|
|
50
51
|
continue;
|
|
51
52
|
let payloadIndex = index + 1;
|
|
52
53
|
while (payloadIndex < lines.length && lines[payloadIndex].trim() === "")
|
|
@@ -102,4 +103,30 @@ export function rejectNativeToolProtocolResidue(message, tools, textToolProtocol
|
|
|
102
103
|
errorMessage: `${NATIVE_TOOL_PROTOCOL_RESIDUE_ERROR}: functions.${toolName} was rendered as text`,
|
|
103
104
|
};
|
|
104
105
|
}
|
|
106
|
+
/**
|
|
107
|
+
* A provider request with no tools must never leave a tool call in the transcript. Providers can
|
|
108
|
+
* still return a native call or render their internal call syntax despite the empty tool surface,
|
|
109
|
+
* so validate both shapes regardless of whether that tool was loaded in the surrounding run. The
|
|
110
|
+
* provider response is retained as an explicit protocol error with no synthetic prose and no
|
|
111
|
+
* executable call block.
|
|
112
|
+
*/
|
|
113
|
+
export function rejectToolCallsFromToolFreeResponse(message) {
|
|
114
|
+
if (message.stopReason === "error" || message.stopReason === "aborted")
|
|
115
|
+
return message;
|
|
116
|
+
const nativeToolCall = message.content.find((block) => block.type === "toolCall");
|
|
117
|
+
const text = message.content
|
|
118
|
+
.filter((block) => block.type === "text")
|
|
119
|
+
.map((block) => block.text)
|
|
120
|
+
.join("\n");
|
|
121
|
+
const renderedToolName = text ? findRenderedToolMarker(text) : undefined;
|
|
122
|
+
const toolName = nativeToolCall?.name ?? renderedToolName;
|
|
123
|
+
if (!toolName)
|
|
124
|
+
return message;
|
|
125
|
+
return {
|
|
126
|
+
...message,
|
|
127
|
+
content: [{ type: "text", text: "" }],
|
|
128
|
+
stopReason: "error",
|
|
129
|
+
errorMessage: `${TOOL_FREE_RESPONSE_TOOL_CALL_ERROR}: provider returned ${toolName} while tools were disabled`,
|
|
130
|
+
};
|
|
131
|
+
}
|
|
105
132
|
//# sourceMappingURL=tool-protocol-residue.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tool-protocol-residue.js","sourceRoot":"","sources":["../src/tool-protocol-residue.ts"],"names":[],"mappings":"AAGA,MAAM,CAAC,MAAM,kCAAkC,GAAG,8BAA8B,CAAC;AAEjF;;;;GAIG;AACH,SAAS,kBAAkB,CAAC,KAAwB;IACnD,MAAM,MAAM,GAAG,IAAI,KAAK,CAAU,KAAK,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAC5D,IAAI,UAAqC,CAAC;IAC1C,IAAI,SAAS,GAAG,CAAC,CAAC,CAAC;IACnB,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,KAAK,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE,CAAC;QACnD,MAAM,OAAO,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC,IAAI,EAAE,CAAC;QACpC,IAAI,CAAC,CAAC,OAAO,CAAC,UAAU,CAAC,KAAK,CAAC,IAAI,OAAO,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;YAAE,SAAS;QACxE,MAAM,MAAM,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAkB,CAAC;QACpD,IAAI,CAAC,UAAU,EAAE,CAAC;YACjB,UAAU,GAAG,MAAM,CAAC;YACpB,SAAS,GAAG,KAAK,CAAC;QACnB,CAAC;aAAM,IAAI,UAAU,KAAK,MAAM,EAAE,CAAC;YAClC,KAAK,IAAI,CAAC,GAAG,SAAS,EAAE,CAAC,IAAI,KAAK,EAAE,CAAC,EAAE;gBAAE,MAAM,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC;YAC1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AC,IAAI,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IACzE,MAAM,QAAQ,GAAG,cAAc,EAAE,IAAI,IAAI,gBAAgB,CAAC;IAC1D,IAAI,CAAC,QAAQ;QAAE,OAAO,OAAO,CAAC;IAC9B,OAAO;QACN,GAAG,OAAO;QACV,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC;QACrC,UAAU,EAAE,OAAO;QACnB,YAAY,EAAE,GAAG,kCAAkC,uBAAuB,QAAQ,4BAA4B;KAC9G,CAAC;AACH,CAAC","sourcesContent":["import type { AssistantMessage } from \"@caupulican/pi-ai/types\";\nimport type { AgentTool } from \"./types.ts\";\n\nexport const NATIVE_TOOL_PROTOCOL_RESIDUE_ERROR = \"native_tool_protocol_residue\";\nexport const TOOL_FREE_RESPONSE_TOOL_CALL_ERROR = \"tool_free_response_tool_call\";\n\n/**\n * Marks which lines fall inside a genuinely closed ```/~~~ fence (open and matching close both\n * present). A fence that never closes does not suppress anything: it is not treated as covering\n * the rest of the message, so real residue after malformed/truncated fencing is still scanned.\n */\nfunction computeFencedLines(lines: readonly string[]): boolean[] {\n\tconst fenced = new Array<boolean>(lines.length).fill(false);\n\tlet openMarker: \"```\" | \"~~~\" | undefined;\n\tlet openIndex = -1;\n\tfor (let index = 0; index < lines.length; index++) {\n\t\tconst trimmed = lines[index].trim();\n\t\tif (!(trimmed.startsWith(\"```\") || trimmed.startsWith(\"~~~\"))) continue;\n\t\tconst marker = trimmed.slice(0, 3) as \"```\" | \"~~~\";\n\t\tif (!openMarker) {\n\t\t\topenMarker = marker;\n\t\t\topenIndex = index;\n\t\t} else if (openMarker === marker) {\n\t\t\tfor (let i = openIndex; i <= index; i++) fenced[i] = true;\n\t\t\topenMarker = undefined;\n\t\t\topenIndex = -1;\n\t\t}\n\t}\n\treturn fenced;\n}\n\nfunction isJsonPayload(text: string): boolean {\n\ttry {\n\t\tJSON.parse(text);\n\t\treturn true;\n\t} catch {\n\t\treturn false;\n\t}\n}\n\nfunction findRenderedToolMarker(text: string, toolNames?: ReadonlySet<string>): string | undefined {\n\tconst lines = text.split(/\\r?\\n/);\n\tconst fenced = computeFencedLines(lines);\n\tfor (let index = 0; index < lines.length; index++) {\n\t\tif (fenced[index]) continue;\n\t\tconst trimmed = lines[index].trim();\n\t\tif (trimmed.startsWith(\"```\") || trimmed.startsWith(\"~~~\")) continue;\n\t\tconst match = /^to=functions\\.([A-Za-z][A-Za-z0-9_-]{0,63})\\s+code$/.exec(trimmed);\n\t\tconst toolName = match?.[1];\n\t\tif (!toolName || (toolNames && !toolNames.has(toolName))) continue;\n\n\t\tlet payloadIndex = index + 1;\n\t\twhile (payloadIndex < lines.length && lines[payloadIndex].trim() === \"\") payloadIndex++;\n\t\tconst payload = lines[payloadIndex]?.trim();\n\t\tif (!payload || !(payload.startsWith(\"{\") || payload.startsWith(\"[\"))) continue;\n\t\tif (!isJsonPayload(payload)) continue;\n\n\t\t// Genuine residue is the terminal content of the turn: a provider that rendered a real tool\n\t\t// call as plain text stops right there. Prose that merely quotes the marker syntax (this repo's\n\t\t// own docs/tests discuss it) keeps explaining afterward, so trailing content after the payload\n\t\t// is what tells a documentation example apart from an actual escaped tool call.\n\t\tlet trailingIndex = payloadIndex + 1;\n\t\twhile (trailingIndex < lines.length && lines[trailingIndex].trim() === \"\") trailingIndex++;\n\t\tif (trailingIndex < lines.length) continue;\n\n\t\treturn toolName;\n\t}\n\treturn undefined;\n}\n\n/**\n * Refuse provider-internal native tool markup that escaped as assistant text. The detector is\n * intentionally narrow: a loaded tool name, a standalone unfenced marker, and an adjacent JSON\n * payload are all required. Nothing is parsed or executed from the rendered text.\n */\nexport function rejectNativeToolProtocolResidue(\n\tmessage: AssistantMessage,\n\ttools: readonly AgentTool[],\n\ttextToolProtocolActive: boolean,\n): AssistantMessage {\n\tif (\n\t\ttextToolProtocolActive ||\n\t\tmessage.stopReason === \"error\" ||\n\t\tmessage.stopReason === \"aborted\" ||\n\t\tmessage.content.some((block) => block.type === \"toolCall\")\n\t) {\n\t\treturn message;\n\t}\n\tconst text = message.content\n\t\t.filter((block) => block.type === \"text\")\n\t\t.map((block) => block.text)\n\t\t.join(\"\\n\");\n\tif (!text) return message;\n\tconst toolName = findRenderedToolMarker(text, new Set(tools.map((tool) => tool.name)));\n\tif (!toolName) return message;\n\treturn {\n\t\t...message,\n\t\tcontent: [\n\t\t\t{\n\t\t\t\ttype: \"text\",\n\t\t\t\ttext: `Provider rendered a ${toolName} tool call as plain text. No operation was executed.`,\n\t\t\t},\n\t\t],\n\t\tstopReason: \"error\",\n\t\terrorMessage: `${NATIVE_TOOL_PROTOCOL_RESIDUE_ERROR}: functions.${toolName} was rendered as text`,\n\t};\n}\n\n/**\n * A provider request with no tools must never leave a tool call in the transcript. Providers can\n * still return a native call or render their internal call syntax despite the empty tool surface,\n * so validate both shapes regardless of whether that tool was loaded in the surrounding run. The\n * provider response is retained as an explicit protocol error with no synthetic prose and no\n * executable call block.\n */\nexport function rejectToolCallsFromToolFreeResponse(message: AssistantMessage): AssistantMessage {\n\tif (message.stopReason === \"error\" || message.stopReason === \"aborted\") return message;\n\tconst nativeToolCall = message.content.find((block) => block.type === \"toolCall\");\n\tconst text = message.content\n\t\t.filter((block) => block.type === \"text\")\n\t\t.map((block) => block.text)\n\t\t.join(\"\\n\");\n\tconst renderedToolName = text ? findRenderedToolMarker(text) : undefined;\n\tconst toolName = nativeToolCall?.name ?? renderedToolName;\n\tif (!toolName) return message;\n\treturn {\n\t\t...message,\n\t\tcontent: [{ type: \"text\", text: \"\" }],\n\t\tstopReason: \"error\",\n\t\terrorMessage: `${TOOL_FREE_RESPONSE_TOOL_CALL_ERROR}: provider returned ${toolName} while tools were disabled`,\n\t};\n}\n"]}
|
package/dist/types.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Api, AssistantMessage, AssistantMessageEvent, Context, ImageContent, Message, Model, SimpleStreamOptions, streamSimple, TextContent, Tool, ToolArgumentValidationTelemetryEvent, ToolResultMessage, Usage } from "@caupulican/pi-ai";
|
|
1
|
+
import type { Api, AssistantMessage, AssistantMessageEvent, Context, ImageContent, Message, Model, SimpleStreamOptions, streamSimple, TextContent, Tool, ToolArgumentValidationTelemetryEvent, ToolErrorKind, ToolResultMessage, Usage } from "@caupulican/pi-ai";
|
|
2
2
|
import type { Static, TSchema } from "typebox";
|
|
3
3
|
/**
|
|
4
4
|
* Stream function used by the agent loop.
|
|
@@ -328,8 +328,9 @@ export interface AgentLoopConfig extends SimpleStreamOptions {
|
|
|
328
328
|
/**
|
|
329
329
|
* Optional provider-request fuse for one logical prompt, including host continuations.
|
|
330
330
|
* Unlike {@link maxStallTurns}, this also catches varied tool churn that never repeats an exact
|
|
331
|
-
* signature. The loop
|
|
332
|
-
* values explicitly enable the fuse; `0` disables it. Default:
|
|
331
|
+
* signature. The loop stops before another provider request without fabricating an assistant
|
|
332
|
+
* message. Positive values explicitly enable the fuse; `0` disables it. Default:
|
|
333
|
+
* {@link DEFAULT_MAX_PROVIDER_TURNS}.
|
|
333
334
|
*/
|
|
334
335
|
maxProviderTurns?: number;
|
|
335
336
|
/**
|
|
@@ -494,6 +495,36 @@ export interface AgentState {
|
|
|
494
495
|
}
|
|
495
496
|
/** Provenance marker for messages synthesized by the host instead of a provider transport. */
|
|
496
497
|
export type AgentMessageOrigin = "local";
|
|
498
|
+
/**
|
|
499
|
+
* Why an errored tool result is an error. These are different events and the harness treats them differently.
|
|
500
|
+
*
|
|
501
|
+
* `tool_failure` — the tool could not perform the operation at all: rejected arguments, denied
|
|
502
|
+
* authority, a timeout, a crash. The operation never happened, the harness owns the diagnostic it
|
|
503
|
+
* shows the model, and it replaces the result with a bounded failure record.
|
|
504
|
+
*
|
|
505
|
+
* `operation_outcome` — the tool performed the operation completely and is reporting the
|
|
506
|
+
* operation's own negative status: a process exit code, a search that matched nothing, a predicate
|
|
507
|
+
* that answered false. Nothing failed; this is the observation the agent asked for. The harness
|
|
508
|
+
* leaves the tool's own output exactly as returned and never rewrites it into a failure record.
|
|
509
|
+
*
|
|
510
|
+
* Both are unproductive to repeat while nothing else has changed, so both are observed by the
|
|
511
|
+
* repetition governor in {@link "./tool-failure-recovery-gate.ts"}. Neither may ever end a run.
|
|
512
|
+
*/
|
|
513
|
+
export type AgentToolErrorKind = ToolErrorKind;
|
|
514
|
+
/**
|
|
515
|
+
* Structured execution failure emitted by a tool when recovery identity must not depend on rendered diagnostics.
|
|
516
|
+
*
|
|
517
|
+
* `failureCode` identifies the tool-owned terminal outcome. `outputSignature` identifies the complete raw
|
|
518
|
+
* operation output, including bytes omitted from bounded model-facing previews. `errorKind` says whether the
|
|
519
|
+
* tool failed or completed and reported a negative operation status; it defaults to `tool_failure` so a tool
|
|
520
|
+
* that has not classified itself is never mistaken for a completed operation.
|
|
521
|
+
*/
|
|
522
|
+
export declare class AgentToolExecutionError extends Error {
|
|
523
|
+
readonly failureCode: string;
|
|
524
|
+
readonly outputSignature: string;
|
|
525
|
+
readonly errorKind: AgentToolErrorKind;
|
|
526
|
+
constructor(message: string, failureCode: string, outputSignature: string, errorKind?: AgentToolErrorKind);
|
|
527
|
+
}
|
|
497
528
|
/** Final or partial result produced by a tool. */
|
|
498
529
|
export interface AgentToolResult<T> {
|
|
499
530
|
/** Text or image content returned to the model. */
|
|
@@ -508,6 +539,11 @@ export interface AgentToolResult<T> {
|
|
|
508
539
|
* record. Throwing remains valid for exceptional execution failures.
|
|
509
540
|
*/
|
|
510
541
|
isError?: boolean;
|
|
542
|
+
/**
|
|
543
|
+
* Classifies an errored result. Defaults to `tool_failure`; set `operation_outcome` when the tool
|
|
544
|
+
* ran the operation to completion and `isError` only reports the operation's own negative status.
|
|
545
|
+
*/
|
|
546
|
+
errorKind?: AgentToolErrorKind;
|
|
511
547
|
/** Provider usage spent inside this tool, for durable budget and cost accounting. */
|
|
512
548
|
usage?: Usage;
|
|
513
549
|
/**
|
|
@@ -547,25 +583,21 @@ export interface AgentToolFailureEvidenceContext extends AgentToolFailureRecover
|
|
|
547
583
|
/**
|
|
548
584
|
* One action a tool can actually perform for a declared failure target.
|
|
549
585
|
*
|
|
550
|
-
*
|
|
551
|
-
*
|
|
586
|
+
* Actions are teaching only: they name the corrective work that makes a retry worth attempting. They
|
|
587
|
+
* do not grant execution budget — admission is governed solely by whether anything has succeeded
|
|
588
|
+
* since the operation last ran (see `ToolFailureRecoveryGate`).
|
|
589
|
+
*
|
|
590
|
+
* A `correct` action teaches a materially changed operation. A `repair` action teaches corrective
|
|
591
|
+
* work on the state the failed operation depends on, after which the same operation is worth rerunning.
|
|
552
592
|
*/
|
|
553
|
-
export type AgentToolFailureRecoveryAction
|
|
554
|
-
kind: "correct";
|
|
555
|
-
authority: AgentToolFailureRecoveryAuthority;
|
|
556
|
-
targetKind: string;
|
|
557
|
-
instruction: string;
|
|
558
|
-
} | {
|
|
559
|
-
kind: "repair";
|
|
593
|
+
export type AgentToolFailureRecoveryAction = {
|
|
594
|
+
kind: "correct" | "repair";
|
|
560
595
|
authority: AgentToolFailureRecoveryAuthority;
|
|
561
596
|
targetKind: string;
|
|
562
597
|
instruction: string;
|
|
563
|
-
getEvidence: (params: Static<TParameters>, result: AgentToolResult<TDetails>) => readonly string[];
|
|
564
598
|
};
|
|
565
599
|
/** Tool-owned failure targets and recovery actions. Undeclared behavior has no recovery authority. */
|
|
566
|
-
export interface AgentToolFailureRecoveryContract<TParameters extends TSchema
|
|
567
|
-
/** Keep exhaustion local to this operation when another operation can still correct it. Defaults to run. */
|
|
568
|
-
exhaustionScope?: "operation" | "run";
|
|
600
|
+
export interface AgentToolFailureRecoveryContract<TParameters extends TSchema> {
|
|
569
601
|
/** Derive exact recovery requirements from validated arguments and a classified failure. */
|
|
570
602
|
getFailureTargets?: (params: Static<TParameters>, failure: AgentToolFailureRecoveryContext) => readonly AgentToolFailureRecoveryTarget[];
|
|
571
603
|
/**
|
|
@@ -574,7 +606,7 @@ export interface AgentToolFailureRecoveryContract<TParameters extends TSchema, T
|
|
|
574
606
|
*/
|
|
575
607
|
getFailureEvidence?: (params: Static<TParameters>, failure: AgentToolFailureEvidenceContext) => string | undefined;
|
|
576
608
|
/** Actions this tool can perform when it is present in the active tool surface. */
|
|
577
|
-
actions?: readonly AgentToolFailureRecoveryAction
|
|
609
|
+
actions?: readonly AgentToolFailureRecoveryAction[];
|
|
578
610
|
}
|
|
579
611
|
/** Tool definition used by the agent runtime. */
|
|
580
612
|
export interface AgentTool<TParameters extends TSchema = TSchema, TDetails = any> extends Tool<TParameters> {
|
|
@@ -588,7 +620,7 @@ export interface AgentTool<TParameters extends TSchema = TSchema, TDetails = any
|
|
|
588
620
|
*/
|
|
589
621
|
prepareArguments?: (args: unknown) => Static<TParameters>;
|
|
590
622
|
/** Explicit failure-recovery authority; the agent loop never infers recovery from argument text. */
|
|
591
|
-
failureRecovery?: AgentToolFailureRecoveryContract<TParameters
|
|
623
|
+
failureRecovery?: AgentToolFailureRecoveryContract<TParameters>;
|
|
592
624
|
/**
|
|
593
625
|
* Execute the tool call. Throw for exceptional execution failures, or return
|
|
594
626
|
* `{ isError: true }` with bounded diagnostic content for an expected
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACX,GAAG,EACH,gBAAgB,EAChB,qBAAqB,EACrB,OAAO,EACP,YAAY,EACZ,OAAO,EACP,KAAK,EACL,mBAAmB,EACnB,YAAY,EACZ,WAAW,EACX,IAAI,EACJ,oCAAoC,EACpC,iBAAiB,EACjB,KAAK,EACL,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAE/C;;;;;;;;GAQG;AACH,MAAM,MAAM,QAAQ,GAAG,CACtB,GAAG,IAAI,EAAE,UAAU,CAAC,OAAO,YAAY,CAAC,KACpC,UAAU,CAA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iB,EAAE,CAAA;CAAE,GAE7E;IAAE,IAAI,EAAE,eAAe,CAAC;IAAC,OAAO,EAAE,YAAY,CAAC;IAAC,MAAM,CAAC,EAAE,kBAAkB,CAAA;CAAE,GAE7E;IAAE,IAAI,EAAE,gBAAgB,CAAC;IAAC,OAAO,EAAE,YAAY,CAAC;IAAC,qBAAqB,EAAE,qBAAqB,CAAA;CAAE,GAC/F;IAAE,IAAI,EAAE,aAAa,CAAC;IAAC,OAAO,EAAE,YAAY,CAAC;IAAC,MAAM,CAAC,EAAE,kBAAkB,CAAA;CAAE,GAE3E;IAAE,IAAI,EAAE,sBAAsB,CAAC;IAAC,UAAU,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,GAAG,CAAC;IAAC,MAAM,CAAC,EAAE,kBAAkB,CAAA;CAAE,GAC9G;IACA,IAAI,EAAE,uBAAuB,CAAC;IAC9B,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,GAAG,CAAC;IACV,aAAa,EAAE,GAAG,CAAC;IACnB,MAAM,CAAC,EAAE,kBAAkB,CAAC;CAC3B,GACD;IACA,IAAI,EAAE,oBAAoB,CAAC;IAC3B,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,GAAG,CAAC;IACZ,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,CAAC,EAAE,kBAAkB,CAAC;CAC3B,CAAC"}
|
package/dist/types.js
CHANGED
|
@@ -6,6 +6,23 @@
|
|
|
6
6
|
export const DEFAULT_MAX_STALL_TURNS = 12;
|
|
7
7
|
/** Provider-turn fuse is opt-in; varied productive work has no implicit request-count ceiling. */
|
|
8
8
|
export const DEFAULT_MAX_PROVIDER_TURNS = 0;
|
|
9
|
+
/**
|
|
10
|
+
* Structured execution failure emitted by a tool when recovery identity must not depend on rendered diagnostics.
|
|
11
|
+
*
|
|
12
|
+
* `failureCode` identifies the tool-owned terminal outcome. `outputSignature` identifies the complete raw
|
|
13
|
+
* operation output, including bytes omitted from bounded model-facing previews. `errorKind` says whether the
|
|
14
|
+
* tool failed or completed and reported a negative operation status; it defaults to `tool_failure` so a tool
|
|
15
|
+
* that has not classified itself is never mistaken for a completed operation.
|
|
16
|
+
*/
|
|
17
|
+
export class AgentToolExecutionError extends Error {
|
|
18
|
+
constructor(message, failureCode, outputSignature, errorKind = "tool_failure") {
|
|
19
|
+
super(message);
|
|
20
|
+
this.name = "AgentToolExecutionError";
|
|
21
|
+
this.failureCode = failureCode;
|
|
22
|
+
this.outputSignature = outputSignature;
|
|
23
|
+
this.errorKind = errorKind;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
9
26
|
const AGENT_TOOL_FAILURE_RECOVERY_AUTHORITY = Symbol("AgentToolFailureRecoveryAuthority");
|
|
10
27
|
/** Create an unforgeable, process-local recovery authority for intentionally cooperating tools. */
|
|
11
28
|
export function createAgentToolFailureRecoveryAuthority() {
|