From 2a28db528cbc2608e590cc7329786e4465eb6c40 Mon Sep 17 00:00:00 2001 From: bigboateng Date: Mon, 15 Dec 2025 19:15:10 +0100 Subject: [PATCH] chore: update changeset to include both message history fixes --- .changeset/fix-extended-thinking-blocks.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 .changeset/fix-extended-thinking-blocks.md diff --git a/.changeset/fix-extended-thinking-blocks.md b/.changeset/fix-extended-thinking-blocks.md new file mode 100644 index 0000000..49bf02f --- /dev/null +++ b/.changeset/fix-extended-thinking-blocks.md @@ -0,0 +1,17 @@ +--- +"@centralinc/browseragent": patch +--- + +Fix critical message history management issues preventing 400 errors + +**Two Major Fixes:** + +1. **Extended Thinking Block Validation**: When `thinkingBudget` is enabled, the API requires every assistant message to start with a thinking or redacted_thinking block. Added `ensureThinkingBlocksForExtendedThinking()` to filter out assistant messages without thinking blocks and their corresponding user messages to maintain conversation flow. + +2. **Tool Use/Result Pairing**: Fixed "unexpected tool_use_id found in tool_result blocks" error. The API requires each tool_result to have its corresponding tool_use in the IMMEDIATELY PREVIOUS message, not just anywhere in history. Rewrote `cleanMessageHistory()` to validate pairing on a per-message basis. + +**Errors Fixed:** +- `"Expected thinking or redacted_thinking, but found text"` +- `"unexpected tool_use_id found in tool_result blocks: [id]. Each tool_result block must have a corresponding tool_use block in the previous message"` + +**Testing:** Extended thinking test passes with 15+ tool calls across multiple turns without errors.