ZIm/crates/assistant_context_editor/src
Bennet Bo Fenner 4d6cd504e7 agent: Fix issue with Anthropic thinking models (#33317)
cc @osyvokon 

We were seeing a bunch of errors in our backend when people were using
Claude models with thinking enabled.

In the logs we would see
> an error occurred while interacting with the Anthropic API:
invalid_request_error: messages.x.content.0.type: Expected `thinking` or
`redacted_thinking`, but found `text`. When `thinking` is enabled, a
final `assistant` message must start with a thinking block (preceeding
the lastmost set of `tool_use` and `tool_result` blocks). We recommend
you include thinking blocks from previous turns. To avoid this
requirement, disable `thinking`. Please consult our documentation at
https://docs.anthropic.com/en/docs/build-with-claude/extended-thinking

However, this issue did not occur frequently and was not easily
reproducible. Turns out it was triggered by us not correctly handling
[Redacted Thinking
Blocks](https://docs.anthropic.com/en/docs/build-with-claude/extended-thinking#thinking-redaction).

I could constantly reproduce this issue by including this magic string:
`ANTHROPIC_MAGIC_STRING_TRIGGER_REDACTED_THINKING_46C9A13E193C177646C7398A98432ECCCE4C1253D5E2D82641AC0E52CC2876CB
` in the request, which forces `claude-3-7-sonnet` to emit redacted
thinking blocks (confusingly the magic string does not seem to be
working for `claude-sonnet-4`). As soon as we hit a tool call Anthropic
would return an error.

Thanks to @osyvokon for pointing me in the right direction 😄!


Release Notes:

- agent: Fixed an issue where Anthropic models would sometimes return an
error when thinking was enabled
2025-06-24 18:25:06 +02:00
..
context Show progress as the agent locates which range it needs to edit (#31582) 2025-05-28 12:32:54 +00:00
assistant_context_editor.rs agent: Add max mode on text threads (#31361) 2025-05-28 10:12:38 -03:00
context.rs agent: Fix issue with Anthropic thinking models (#33317) 2025-06-24 18:25:06 +02:00
context_editor.rs Standardize on u64 for token counts (#32869) 2025-06-17 10:43:07 -04:00
context_history.rs agent: Rename a number of constructs from Assistant to Agent (#30196) 2025-05-08 01:18:51 +00:00
context_store.rs editor: Improve code completion filtering to provide fewer and more accurate suggestions (#32928) 2025-06-18 16:01:28 +05:30
language_model_selector.rs editor: Improve code completion filtering to provide fewer and more accurate suggestions (#32928) 2025-06-18 16:01:28 +05:30
max_mode_tooltip.rs agent: Add keybinding to toggle Burn Mode (#31630) 2025-05-28 18:08:58 -03:00
slash_command.rs editor: Improve code completion filtering to provide fewer and more accurate suggestions (#32928) 2025-06-18 16:01:28 +05:30
slash_command_picker.rs Use read-only access methods for read-only entity operations (#31479) 2025-05-26 23:04:31 -04:00