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:
@@ -51,6 +51,28 @@ def load_agent_instructions(agents_dir: Optional[str] = None) -> str:
|
||||
return ""
|
||||
|
||||
|
||||
# Tool honesty rules. Field and M0 measurements (2026-11-10, Strata) showed
|
||||
# capable models skipping an available tool and answering anyway: a made-up
|
||||
# "24 degrees and sunny" instead of calling the weather tool, and "timer set"
|
||||
# without calling the timer tool. The rules name both failure shapes (live
|
||||
# facts and actions) instead of listing tools, so they hold for any tool set
|
||||
# and any reply language. Kept as one constant so the M0 kit can measure the
|
||||
# exact production wording (see tests/test_m0_kit.py).
|
||||
TOOL_HONESTY_RULES: str = (
|
||||
"Tool rules (hard): facts that change over time — weather, temperature, rain, news, prices, "
|
||||
"scores, traffic, opening hours, what is on the user's screen — must come from a tool result "
|
||||
"in this turn. Never state such a value from memory, never estimate it, never make it up. "
|
||||
"If one of your tools can fetch it, call that tool first; if none can, say you cannot check "
|
||||
"it right now. When the user asks you to do something — set a timer or reminder, open a "
|
||||
"website, navigate the browser, play or show something on screen, change a setting, send a "
|
||||
"message — and one of your tools can do it, call that tool; saying it is done is never a "
|
||||
"substitute for calling the tool. Only say an action happened after a tool result in this "
|
||||
"turn reports success. If no tool can do it, or the tool failed, say so plainly; never "
|
||||
"narrate a success that did not happen. A message that calls a tool contains only the tool "
|
||||
"call: write no answer or confirmation next to it, and answer after you see the result."
|
||||
)
|
||||
|
||||
|
||||
_SYSTEM_PROMPT_TEMPLATE: str = (
|
||||
"Persona: you are a British butler named {name} — polite, composed, quietly amused, and "
|
||||
"quietly enjoying yourself. Default voice is dry, witty, and lightly sarcastic: you notice "
|
||||
@@ -86,10 +108,7 @@ _SYSTEM_PROMPT_TEMPLATE: str = (
|
||||
"should happen in the on-screen browser — opening a site, searching on a site "
|
||||
"(controlBrowser action 'search' with the right site), clicking, typing — because only "
|
||||
"controlBrowser is visible on the broadcast; webSearch shows nothing on screen. "
|
||||
"Never claim you performed an action — opening a website, navigating the browser, "
|
||||
"playing or showing something on screen, changing a setting, sending a message — unless a "
|
||||
"tool actually did it this turn and reported success. If you have no tool for what was asked, "
|
||||
"or the tool failed, say so plainly; do not narrate a success that did not happen. "
|
||||
"{tool_rules} "
|
||||
"Never answer with a bare greeting like 'Hey there!', 'Hi!', 'Hello, how can I help you?', "
|
||||
"'I hope you have a relaxing time today', or 'I'm here and ready to chat'. Always engage "
|
||||
"with the user's actual prompt, and when the 'Information the user has shared…' section is "
|
||||
@@ -138,6 +157,28 @@ _SYSTEM_PROMPT_TEMPLATE: str = (
|
||||
)
|
||||
|
||||
|
||||
def tool_honesty_reminder(tool_names) -> str:
|
||||
"""End-of-prompt restatement of the tool honesty rules for this turn.
|
||||
|
||||
The rules also sit in the persona, but in a long system prompt a rule in
|
||||
the middle loses to the model's habit of answering straight away (the
|
||||
same "lost in the middle" effect the reply-language lock is repeated
|
||||
for). Naming the turn's real tools gives the model a concrete list to
|
||||
check its answer against, which works for any tool set and language.
|
||||
The engine's sentinels (``stop``, ``toolSearchTool``) are not listed:
|
||||
neither fetches a fact nor performs an action.
|
||||
"""
|
||||
names = [n for n in (tool_names or []) if n not in ("stop", "toolSearchTool")]
|
||||
listed = ", ".join(names) if names else "none"
|
||||
return (
|
||||
"Before you answer: any live fact in your reply, and any action you say you did, "
|
||||
f"must come from a tool call in this turn. Your tools this turn: {listed}. If one of "
|
||||
"them can fetch the fact or do the action, call it now instead of answering. If none "
|
||||
"of them can, say plainly that you cannot check or do that; never say something was "
|
||||
"done unless a tool result in this turn says so."
|
||||
)
|
||||
|
||||
|
||||
def build_system_prompt(
|
||||
assistant_name: str = "Jarvis", output_language: Optional[str] = None
|
||||
) -> str:
|
||||
@@ -153,7 +194,7 @@ def build_system_prompt(
|
||||
query language and leaks the other language back in.
|
||||
"""
|
||||
name = (assistant_name or "Jarvis").strip() or "Jarvis"
|
||||
prompt = _SYSTEM_PROMPT_TEMPLATE.format(name=name)
|
||||
prompt = _SYSTEM_PROMPT_TEMPLATE.format(name=name, tool_rules=TOOL_HONESTY_RULES)
|
||||
lang = (output_language or "").strip()
|
||||
if lang:
|
||||
prompt = prompt.replace("in the user's language", f"in {lang}")
|
||||
|
||||
Reference in New Issue
Block a user