From ea5323af26fde35c5fd2151ef1e1e48608358009 Mon Sep 17 00:00:00 2001 From: Tyler Longwell Date: Tue, 12 May 2026 19:32:36 -0400 Subject: [PATCH] fix: use space instead of empty string for Anthropic empty assistant turns MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Anthropic's Messages API rejects text content blocks with empty strings ("messages: text content blocks must be non-empty"). When an assistant turn has no text and no tool calls, the serializer produced text: "" which causes a permanent 400 loop — the session is unrecoverable because every retry sends the same invalid history. Use a single space instead, satisfying both Anthropic constraints: non-empty content array and non-empty text block. --- crates/sprout-agent/src/llm.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/crates/sprout-agent/src/llm.rs b/crates/sprout-agent/src/llm.rs index 3fc8abae..5aa91275 100644 --- a/crates/sprout-agent/src/llm.rs +++ b/crates/sprout-agent/src/llm.rs @@ -127,7 +127,9 @@ fn anthropic_body(cfg: &Config, history: &[HistoryItem], tools: &[ToolDef]) -> V "name": c.name, "input": c.arguments })); } if content.is_empty() { - content.push(json!({ "type": "text", "text": "" })); + // Anthropic requires non-empty content arrays AND rejects + // empty text blocks. A single space satisfies both. + content.push(json!({ "type": "text", "text": " " })); } messages.push(json!({ "role": "assistant", "content": content })); }