mirror of
https://github.com/hanzoai/mcp.git
synced 2026-10-29 02:55:49 +00:00
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.
51 lines
1.6 KiB
TypeScript
51 lines
1.6 KiB
TypeScript
/**
|
|
* Recipe 02: Zero-Inference Fast Path Execution
|
|
*
|
|
* Objective: Demonstrate Hanzo Dev's core speed optimization: when a single deterministic
|
|
* Action has satisfied preconditions, execute it in 0ms without invoking Kai inference or LLM calls.
|
|
*/
|
|
|
|
import { createRecipeClient, logRecipe, RecipeResult } from "./helper.js";
|
|
|
|
export async function runRecipe02(): Promise<RecipeResult> {
|
|
const client = await createRecipeClient();
|
|
|
|
const goal = "Fix compiler error in parser/src/number.rs";
|
|
const candidates = [
|
|
{
|
|
action_id: "act_apply_patch",
|
|
tool: "Edit",
|
|
description: "Replace parse_exponent return type with f64 in parser/src/number.rs",
|
|
parameters: { path: "parser/src/number.rs", line: 88, replacement: "Ok(val)" },
|
|
preconditions_satisfied: true
|
|
},
|
|
{
|
|
action_id: "act_read_again",
|
|
tool: "Read",
|
|
description: "Re-read parser/src/number.rs from beginning",
|
|
parameters: { path: "parser/src/number.rs" },
|
|
preconditions_satisfied: false
|
|
}
|
|
];
|
|
|
|
const res = await client.callTool("kai_next_action", {
|
|
goal,
|
|
candidates
|
|
});
|
|
|
|
const result: RecipeResult = {
|
|
recipe: "02: Zero-Inference Fast Path",
|
|
tool: "kai_next_action",
|
|
success: !res.isError && res.data.source === "single" && res.data.action?.preconditions_satisfied === true,
|
|
latency_ms: res.latency_ms,
|
|
output: res.data,
|
|
explanation: "One candidate had its preconditions met, so it was returned as is; the other was dropped. No model call."
|
|
};
|
|
|
|
return result;
|
|
}
|
|
|
|
if (process.argv[1]?.endsWith("02-zero-inference-fast-path.ts")) {
|
|
runRecipe02().then(logRecipe).catch(console.error);
|
|
}
|