Make tool failures actionable with suggestions and scope hints.

Unregistered tools now suggest close matches; MCP insufficient_scope is rewritten with fallbacks so ops agents stop blind-retrying SQL without sql:query.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
oliver 2026-08-10 22:42:37 +08:00
parent 229e8b1368
commit d245e463c0
6 changed files with 159 additions and 4 deletions

View file

@ -95,8 +95,14 @@ class Agent:
t0 = time.perf_counter()
tool = self.tools.get(tc.name)
if not tool:
msg = f"Unregistered tool: {tc.name}" if self.lang.startswith("en") else f"未注册的工具: {tc.name}"
return {"ok": False, "error": msg}, int((time.perf_counter() - t0) * 1000)
from runtime.tools.tool_error_hints import format_unregistered_tool_error
available = [t.name for t in self.tools.list()] if hasattr(self.tools, "list") else []
return format_unregistered_tool_error(
str(tc.name or ""),
available,
lang=str(self.lang or "zh"),
), int((time.perf_counter() - t0) * 1000)
ok, v_err = validate_tool_arguments(tool.parameters, tc.arguments)
if not ok: