Skip to content

Tool calling with LiteLLM and thinking models fail #765

Open
@gal-checksum

Description

@gal-checksum

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

  1. Run the agents sdk with sonnet 4
  2. Produce a scenario that requires 2 tool calls or more
  3. Get the failure above

Expected behavior

Everything works :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions