From 56bc8b567733480091d0f4eb4636d8bd31ded1ac Mon Sep 17 00:00:00 2001 From: nano bot Date: Tue, 17 Feb 2026 03:52:08 +0000 Subject: [PATCH] fix: avoid sending empty content entries in assistant messages --- nanobot/agent/context.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/nanobot/agent/context.py b/nanobot/agent/context.py index f460f2b..bed9e36 100644 --- a/nanobot/agent/context.py +++ b/nanobot/agent/context.py @@ -225,14 +225,20 @@ To recall past events, grep {workspace_path}/memory/HISTORY.md""" Returns: Updated message list. """ - msg: dict[str, Any] = {"role": "assistant", "content": content or ""} - + msg: dict[str, Any] = {"role": "assistant"} + + # Only include the content key when there is non-empty text. + # Some LLM backends reject empty text blocks, so omit the key + # to avoid sending empty content entries. + if content is not None and content != "": + msg["content"] = content + if tool_calls: msg["tool_calls"] = tool_calls - - # Thinking models reject history without this + + # Include reasoning content when provided (required by some thinking models) if reasoning_content: msg["reasoning_content"] = reasoning_content - + messages.append(msg) return messages