Files
mcp/cookbook/06-failure-loop-breaker.ts
zeekay 56a2b02dcf kai tools: next action, recovery and extraction without guesses; reads linked, not quoted
kai_next_action never returns a candidate whose preconditions are unmet,
returns a single remaining one as is, and picks among several by BM25
against the goal, abstaining on a tie or no shared word; no Kai call (a
Kai choice over candidates read below BM25 for tools). kai_recover maps
each kai_log_triage class to a step (permission asks the user) and keeps
the three-failure switch. kai_extract computes a yes/no field's confidence
from P(true), abstains in Kai's unknown band (.35 to .65), and returns a
score field's level rather than its mean.

Recipes 02, 06, 07, 11, 12 and 14 check what the tools return, including
abstention; the cookbook README and the tools' comments link the research
runs instead of quoting numbers. bench/tools/post.py files each tool's read
(benchmarks, one run an arm, items and cases as artifacts) to /v1/research.
2026-10-14 18:30:09 -07:00

40 lines
1.3 KiB
TypeScript

/**
* Recipe 06: Failure Loop Breaker
*
* Objective: Prevent infinite agent retry loops by fingerprinting failure states and tripping
* a deterministic circuit breaker when an agent repeats identical failing actions 3 times.
*/
import { createRecipeClient, logRecipe, RecipeResult } from "./helper.js";
export async function runRecipe06(): Promise<RecipeResult> {
const client = await createRecipeClient();
const failureFingerprint = {
tool: "Edit",
error_snippet: "mismatched types: expected f64, found Result<f64, ParseFloatError>",
attempt_count: 3,
last_action: "Edit parser/src/number.rs at line 88"
};
const res = await client.callTool("kai_recover", {
error_category: "compile",
failure_fingerprint: failureFingerprint
});
const result: RecipeResult = {
recipe: "06: Failure Loop Breaker",
tool: "kai_recover",
success: !res.isError && res.data.loop_breaker_triggered === true && res.data.strategy === "revert_and_switch_strategy",
latency_ms: res.latency_ms,
output: res.data,
explanation: "Three failures with one fingerprint switch strategy instead of repeating it. No model call."
};
return result;
}
if (process.argv[1]?.endsWith("06-failure-loop-breaker.ts")) {
runRecipe06().then(logRecipe).catch(console.error);
}