From 33d133b2dafa8a8101ccc7596eed9db2c3f44996 Mon Sep 17 00:00:00 2001 From: Lukas Parsons Date: Tue, 7 Jul 2026 14:36:55 -0400 Subject: [PATCH] fix: add anti-hallucination rule to agent system prompt Both preambles now include a CRITICAL line warning that describing a tool call in prose without the fenced block does nothing. Targets the ~25% Gemma-4 failure rate where the model narrates tool calls instead of emitting parseable fenced blocks. --- src/agent_loop.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/agent_loop.py b/src/agent_loop.py index e3fa1f0b..79efb7e3 100644 --- a/src/agent_loop.py +++ b/src/agent_loop.py @@ -67,7 +67,8 @@ _AGENT_PREAMBLE = """\ You are an AI assistant with tool access. You can run shell commands, execute Python, search the web, \ read/write files, create and edit documents, generate images, manage memories, and more. \ To use a tool, write a fenced code block with the tool name as the language tag. \ -The block executes automatically and you see the output.""" +The block executes automatically and you see the output. \ +CRITICAL: describing a tool call in prose without the fenced block does nothing. Always emit the fenced block for any action.""" _AGENT_RULES = """\ ## Rules @@ -179,7 +180,8 @@ _API_AGENT_RULES = """\ _AGENT_PREAMBLE = """\ You are an AI assistant with tool access. Only the tools listed below are available for this turn. -To use a tool, write a fenced code block with the tool name as the language tag. The block executes automatically and you see the output.""" +To use a tool, write a fenced code block with the tool name as the language tag. The block executes automatically and you see the output. +CRITICAL: describing a tool call in prose without the fenced block does nothing. Always emit the fenced block for any action.""" _AGENT_RULES = """\ ## Base rules