fix: explicit tool result instructions to guide model response
- Changed vague 'Provide your final answer now' to specific per-tool instructions - read: 'READ THIS FILE CONTENT ALOUD to the user' - write: 'CONFIRM to the user that the file was created' - bash: 'SUMMARIZE the output above to answer the user's request' - Other tools: 'Use the result shown above to answer the user's request' - Format tool result message with clear 'Tool Result (name):' header and explicit instruction - This should fix models ignoring tool results or giving generic responses - All 41 tests passing
This commit is contained in:
@@ -414,15 +414,22 @@ async def handle_chat_completion(
|
||||
for i, ((tool_name, tool_result), tc) in enumerate(zip(tool_results, tool_calls_parsed)):
|
||||
tool_call_id = tc.get("id", f"call_{i}")
|
||||
|
||||
# For the last tool (or all tools), add instruction to stop
|
||||
if i == len(tool_results) - 1:
|
||||
tool_message_content = (
|
||||
f"{tool_result}\n\n"
|
||||
f"IMPORTANT: You have received the tool result above. "
|
||||
f"DO NOT call any more tools. Provide your final answer now."
|
||||
)
|
||||
# Format the tool result message with explicit instructions
|
||||
# This tells the model exactly what to do with the result
|
||||
if tool_name == "read":
|
||||
instruction = "The file contents are shown above. READ THIS FILE CONTENT ALOUD to the user. Do not call additional tools."
|
||||
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."
|
||||
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."
|
||||
else:
|
||||
tool_message_content = tool_result
|
||||
instruction = "The tool has completed. Use the result shown above to answer the user's request. Do not call additional tools."
|
||||
|
||||
tool_message_content = (
|
||||
f"Tool Result ({tool_name}):\n"
|
||||
f"{tool_result}\n\n"
|
||||
f"INSTRUCTION: {instruction}"
|
||||
)
|
||||
|
||||
messages.append(ChatMessage(
|
||||
role="tool",
|
||||
|
||||
Reference in New Issue
Block a user