fix(reply): stop models answering past an available tool
M0 on Strata caught both v2 models skipping a tool they had been given: the recommended model made up "24 degrees, sunny" instead of calling the weather tool, and the fast model said "timer set" without calling the timer tool (3 of 3 each). qwen2.5:7b does the same through the engine. - Prompt: TOOL_HONESTY_RULES in the persona (live facts only from a tool result this turn, actions only claimed after a tool reports success, no answer text next to a tool call), restated at the end of the system message by tool_honesty_reminder() with the turn's real tool names. - Engine: skipped-tool guard. When a native-tool model answers before any tool has run and the plan names a callable tool as a concrete call, the answer is dropped and the plan steps are direct-executed, then the model answers from the results. Only literal, schema-valid steps run (regex fast path, no LLM repair); otherwise the held-back answer is delivered. - Planner: the AVAILABLE TOOLS lines now carry argument names (planner_tool_catalog), so concrete steps use the tool's real keys. - Eval evals/test_tool_skip_confabulation.py; on qwen2.5:7b, 3 runs each, available-tool cases went from 0/12 to 9/12 calling the tool. - M0 kit: tools_fast / tools_recommended stages (run_m0_tools.bat) rerun tool calling before and after the fix on the real models, loading the production system_prompt.py and planner.py. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -229,6 +229,30 @@ _PROMPT_TEMPLATE = (
|
||||
)
|
||||
|
||||
|
||||
def planner_tool_catalog(tools_schema: Sequence[dict]) -> List[Tuple[str, str]]:
|
||||
"""(name, one-line description) pairs for the planner's AVAILABLE TOOLS.
|
||||
|
||||
Each description ends with the tool's argument names, e.g.
|
||||
``(args: location)``. Without them the planner guessed keys
|
||||
(``get_weather location=...`` for a ``city`` tool, ``set_timer
|
||||
duration=5minutes`` for ``minutes``), and a step with a guessed key
|
||||
cannot be run as written by the skipped-tool guard.
|
||||
"""
|
||||
out: List[Tuple[str, str]] = []
|
||||
for entry in tools_schema or []:
|
||||
fn = entry.get("function", {}) if isinstance(entry, dict) else {}
|
||||
if not isinstance(fn, dict) or not fn.get("name"):
|
||||
continue
|
||||
desc = (fn.get("description") or "").strip().splitlines()
|
||||
line = desc[0][:120] if desc else ""
|
||||
params = fn.get("parameters") or {}
|
||||
props = params.get("properties") if isinstance(params, dict) else None
|
||||
if isinstance(props, dict) and props:
|
||||
line = f"{line} (args: {', '.join(props)})"
|
||||
out.append((str(fn["name"]), line))
|
||||
return out
|
||||
|
||||
|
||||
def _build_user_message(
|
||||
query: str,
|
||||
dialogue_context: str,
|
||||
@@ -371,6 +395,29 @@ def tool_names_in_plan(
|
||||
return out
|
||||
|
||||
|
||||
def named_tool_steps(
|
||||
plan: Sequence[str], callable_names: Sequence[str],
|
||||
) -> List[str]:
|
||||
"""Plan steps that start with the name of a tool the model may call.
|
||||
|
||||
Unlike ``tool_steps_of`` this does not rely on step position: a planner
|
||||
that emits a lone ``logMeal meal='banana'`` (no synthesis step) or
|
||||
``searchMemory ...`` followed by a single ``getWeather`` still names a
|
||||
tool to run. A step's head token is matched exactly against
|
||||
``callable_names``, so synthesis prose ("Reply to the user.") and
|
||||
hallucinated tool names never match. Used by the engine's skipped-tool
|
||||
guard, which runs these steps when a native-tool model answers without
|
||||
calling any tool.
|
||||
"""
|
||||
known = set(callable_names)
|
||||
out: List[str] = []
|
||||
for step in strip_memory_directives(plan):
|
||||
m = _TOOL_NAME_HEAD_RE.match(step)
|
||||
if m and m.group(1) in known:
|
||||
out.append(step)
|
||||
return out
|
||||
|
||||
|
||||
def plan_has_unresolved_tool_steps(
|
||||
plan: Sequence[str], known_names: Sequence[str],
|
||||
) -> bool:
|
||||
@@ -625,6 +672,30 @@ def _parse_plan_step_concrete(
|
||||
return name, _normalise_url_args(args)
|
||||
|
||||
|
||||
def parse_concrete_tool_step(
|
||||
step_text: str, tools_schema: Sequence[dict],
|
||||
) -> Optional[Tuple[str, dict]]:
|
||||
"""Parse a fully concrete plan step against a tools schema, never via an LLM.
|
||||
|
||||
The skipped-tool guard overrides the chat model's own decision not to
|
||||
call a tool, so it only runs what the planner literally wrote: a known
|
||||
tool name with ``key='value'`` arguments the tool declares (or no
|
||||
arguments). An LLM resolver could "repair" a wrong step into a valid but
|
||||
unwanted call (a timer request remapped to starting the broadcast), so
|
||||
prose-shaped or placeholder steps return ``None`` here.
|
||||
"""
|
||||
allowed_props: dict = {}
|
||||
for entry in tools_schema or []:
|
||||
fn = entry.get("function", {}) if isinstance(entry, dict) else {}
|
||||
name = fn.get("name") if isinstance(fn, dict) else None
|
||||
if not name:
|
||||
continue
|
||||
params = fn.get("parameters") or {}
|
||||
props = params.get("properties") if isinstance(params, dict) else None
|
||||
allowed_props[str(name)] = set(props.keys()) if isinstance(props, dict) else set()
|
||||
return _parse_plan_step_concrete(step_text or "", list(allowed_props), allowed_props)
|
||||
|
||||
|
||||
def resolve_next_tool_call(
|
||||
cfg,
|
||||
next_step_text: str,
|
||||
|
||||
Reference in New Issue
Block a user