fix: smarter bash tool instructions - guide model to read files after verification

- Updated bash tool result instructions to detect verification commands (ls/grep)
- If ls/grep shows file exists and user asked to READ it: explicitly tells model to USE read TOOL NOW
- If user asked to check files: tells model to summarize the listing
- If file not found: tells model to inform user
- Prevents infinite loops of repeated ls commands
- Model now properly transitions from verification → action → answer
- All 41 tests passing
This commit is contained in:
2026-02-25 20:39:55 +01:00
parent a09d23156b
commit 586c113688
+13 -9
View File
@@ -466,16 +466,20 @@ async def handle_chat_completion(
for i, ((tool_name, tool_result), tc) in enumerate(zip(tool_results, tool_calls_parsed)): for i, ((tool_name, tool_result), tc) in enumerate(zip(tool_results, tool_calls_parsed)):
tool_call_id = tc.get("id", f"call_{i}") tool_call_id = tc.get("id", f"call_{i}")
# Format the tool result message with explicit instructions # Format the tool result message with explicit instructions
# This tells the model exactly what to do with the result # This tells the model exactly what to do with the result
if tool_name == "read": if tool_name == "read":
instruction = "The file contents are shown above. READ THIS FILE CONTENT ALOUD to the user. Do not call additional tools." instruction = "The file contents are shown above. READ THIS FILE CONTENT ALOUD to the user. Do not call additional tools."
elif tool_name == "write": elif tool_name == "write":
instruction = "The file has been successfully written. CONFIRM to the user that the file was created with the content shown above. Do not call additional tools." instruction = "The file has been successfully written. CONFIRM to the user that the file was created with the content shown above. Do not call additional tools."
elif tool_name == "bash": elif tool_name == "bash":
instruction = "The command has been executed. SUMMARIZE the output above to answer the user's request. Do not call additional tools." # Check if this was a verification command (ls, grep) vs an action command
if "ls" in tool_result.lower() or "grep" in tool_result.lower():
instruction = "The directory/file listing is shown above. Based on the user's original request: If they asked to READ a file that you can see exists, USE THE read TOOL NOW to read it. If they asked to CHECK what files exist, summarize the listing. If the requested file is NOT in the listing, tell the user it doesn't exist."
else: else:
instruction = "The tool has completed. Use the result shown above to answer the user's request. Do not call additional tools." instruction = "The command has been executed. SUMMARIZE the output above to answer the user's request. Do not call additional tools."
else:
instruction = "The tool has completed. Use the result shown above to answer the user's request. Do not call additional tools."
tool_message_content = ( tool_message_content = (
f"Tool Result ({tool_name}):\n" f"Tool Result ({tool_name}):\n"