fix: add text fallback for pure rich content tool results

Providers that only serialize text content (OpenAI, Codex, Anthropic)
would produce no tool output for the model when execute returns only
rich content. Always include a text placeholder so the model sees a
valid tool result.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
jh-block
2026-03-10 17:28:44 +01:00
parent 96b892d8e3
commit fc26afe4b5
@@ -310,7 +310,13 @@ impl CodeExecutionClient {
});
if is_pure_ref && !rich_contents.is_empty() {
Ok(rich_contents)
// Always include a text fallback so providers that only serialize
// text content (OpenAI, Codex, Anthropic) still produce a tool result
// for the model. The rich content carries audience metadata and will
// be filtered by downstream audience logic.
let mut contents = vec![Content::text("Tool returned rich content.")];
contents.extend(rich_contents);
Ok(contents)
} else {
let return_val = serde_json::to_string_pretty(&output.output)
.unwrap_or_else(|_| json!(&output.output).to_string());