From 19cd24c07aa1ee547fb71cd9a70d331ef0bbae65 Mon Sep 17 00:00:00 2001 From: Leivur Djurhuus Date: Thu, 12 Mar 2026 15:29:20 -0500 Subject: [PATCH] fix: Send plain text history to prevent orphaned tool_use block errors MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Claude's API requires every tool_use block to be followed by a matching tool_result. Since tool interactions are fully resolved server-side within a single request, the client should only send plain text in conversation history — never structured content blocks that contain tool_use references. Co-Authored-By: Claude Opus 4.6 --- src/hooks/use-chat.ts | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/hooks/use-chat.ts b/src/hooks/use-chat.ts index d92fce9..876c434 100644 --- a/src/hooks/use-chat.ts +++ b/src/hooks/use-chat.ts @@ -26,8 +26,6 @@ export interface ChatMessage { isLoading?: boolean; /** Tool calls in progress or completed during this assistant turn */ toolCalls?: ToolStatus[]; - /** Structured content blocks for multi-turn context (sent to API) */ - contentBlocks?: any[]; /** Clickable entity suggestions for disambiguation */ suggestions?: EntitySuggestion[]; } @@ -115,10 +113,12 @@ export function useChat(context?: ChatContext) { setIsLoading(true); try { - // Build message history for the API, preserving structured content blocks + // Build message history for the API — send plain text only. + // Tool interactions are resolved server-side within a single request, + // so we never send tool_use/tool_result blocks back in history. const apiMessages = [...messages, userMsg].map((m) => ({ role: m.role, - content: m.contentBlocks || m.content, + content: m.content, })); abortRef.current = new AbortController(); @@ -194,10 +194,6 @@ export function useChat(context?: ChatContext) { provider: data.provider, isLoading: false, suggestions: data.suggestions, - // Store structured blocks for multi-turn context - contentBlocks: data.content - ? [{ type: "text", text: data.content }] - : undefined, } : m )