fix(ai): use "(no tool output)" placeholder for empty tool results without images (#6290)

OpenAI Completions and Responses providers unconditionally replaced empty
tool result text with "(see attached image)", even when the result had no
image content. This caused the model to hallucinate image attachments for
commands that produce no output (e.g. curl -s with SSL errors, grep with
no matches, true/false).

Now matches the Google provider behavior: "(see attached image)" is only
used when images are actually present; empty results get "(no tool output)".

Co-authored-by: tzwm <tzwm@users.noreply.github.com>
Co-authored-by: Mario Zechner <badlogicgames@gmail.com>
This commit is contained in:
Samwise Wang
2026-07-07 03:42:56 +08:00
committed by GitHub
parent 4087346dfd
commit 279f53b098
5 changed files with 108 additions and 2 deletions
+2 -1
View File
@@ -1033,10 +1033,11 @@ export function convertMessages(
// Always send tool result with text (or placeholder if only images)
const hasText = textResult.length > 0;
const toolResultText = hasText ? textResult : hasImages ? "(see attached image)" : "(no tool output)";
// Some providers require the 'name' field in tool results
const toolResultMsg: ChatCompletionToolMessageParam = {
role: "tool",
content: sanitizeSurrogates(hasText ? textResult : "(see attached image)"),
content: sanitizeSurrogates(toolResultText),
tool_call_id: toolMsg.toolCallId,
};
if (compat.requiresToolResultName && toolMsg.toolName) {
@@ -251,7 +251,7 @@ export function convertResponsesMessages<TApi extends Api>(
output = contentParts;
} else {
output = sanitizeSurrogates(hasText ? textResult : "(see attached image)");
output = sanitizeSurrogates(hasText ? textResult : hasImages ? "(see attached image)" : "(no tool output)");
}
messages.push({