Open
Description
Describe the bug
When running the agents SDK with tool calling and a thinking model through LITELLM (e.g. sonnet 4) getting this error
litellm.exceptions.BadRequestError: litellm.BadRequestError: AnthropicException - {"type":"error","error":{"type":"invalid_request_error","message":"messages.1.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"}}
Debug information
- Agents SDK version: 0.0.16
- Python version 3.13
Repro steps
- Run the agents sdk with sonnet 4
- Produce a scenario that requires 2 tool calls or more
- Get the failure above
Expected behavior
Everything works :)
Metadata
Metadata
Assignees
Labels
Type
Projects
Milestone
Relationships
Development
No branches or pull requests
Activity
rm-openai commentedon May 27, 2025
Can you please provide a full working script? Happy to take a look!
gal-checksum commentedon May 28, 2025
@rm-openai see below
Add LiteLLM thinking model message handling and comprehensive tests
Fix LiteLLM thinking models with tool calling across providers
Refactor tests for LiteLLM thinking models to improve readability and…
knowsuchagency commentedon Jun 4, 2025
Root Cause Analysis and Current Status
TLDR: Thinking with tool calling for Anthropic is broken in LiteLLM.
I've investigated this issue thoroughly and determined the root cause is in LiteLLM, not the openai-agents-python SDK.
What's Actually Happening
Current Workarounds
Until LiteLLM fixes this upstream:
Related Issues
Why No Fix in This SDK
I initially created a PR with a workaround, but decided against it because:
gal-checksum commentedon Jun 4, 2025
Thanks! Another workaorund could also be use Anthropic through the OpenAI Responses API Compatibility no?
Haven't tried it but should work
ukayani commentedon Jun 8, 2025
@knowsuchagency The bug you've linked is in the conversion between the responses api and completions api on the LiteLLM side. Although that is a legitimate issue, it isn't the reason why the LiteLLM issue exists. The LiteLLM abstraction in this sdk uses the acompletion api only from LiteLLM. I've tested LiteLLM directly with claude thinking models and the acompletion api preserves thinking blocks. The problem is that this SDK tries to convert completions to the responses api format and in doing so, it drops the specific properties on the LiteLLM models which hold the thinking block details.
See this issue i filed about this: #678
I think the issue you pointed out on the LiteLLM side may help if the openai sdk switches to using the responses api on litellm but currently its using acompletion directly.
Ultimately, i think the responses API types need some additional flexibility, to be able to preserve non-openai specific model provider details. OpenAI's responses api kinda has a reasoning summary but it doesn't expose the full reasoning blocks via api, hence the responses API doesn't really account for them properly. I believe newer claude models are also moving towards reasoning summaries so maybe some sort of consolidation could happen with the types.
While i agree with this somewhat. The counter argument is that if the SDK claims to support third party providers and LiteLLM supports enabling thinking + tools with acompletions for most model providers, then this SDK should at the minimum have support for such a common scenario. You can't claim to support third party providers but then not work with reasoning + tool calls.
Naamsukh commentedon Jun 10, 2025
Yupp tried it via OpenAI Responses API , It works well.
agent.model = OpenAIChatCompletionsModel(model="claude-sonnet-4-20250514", openai_client=AsyncOpenAI(
base_url="https://api.anthropic.com/v1/",
api_key=settings.anthropic_api_key
))
ukayani commentedon Jun 11, 2025
Do you mind giving a full example, with tool calls? From the looks of your snippet, you're using the openai completions api compatibility provided by Anthropic rather than anything to do with the responses api.