You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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 :)
The text was updated successfully, but these errors were encountered:
from agents import (
Agent,
function_tool,
RunContextWrapper,
Runner,
ModelSettings,
)
from dataclasses import dataclass
import asyncio
from agents.extensions.models.litellm_model import LitellmModel
import os
from openai.types import Reasoning
from dotenv import load_dotenv
# Load environment variables from .env file
load_dotenv()
@dataclass
class Count:
count: int
@function_tool
def count(ctx: RunContextWrapper[Count]) -> str:
"""
Increments the count by 1 and returns the count
Returns:
A string with the count
"""
ctx.context.count += 1
return f"Counted to {ctx.context.count}"
count_ctx = Count(count=0)
agent = Agent[Count](
name="Counter Agent",
instructions="Count until the number the user tells you to stop using count tool",
tools=[count],
model=LitellmModel(
model="anthropic/claude-sonnet-4-20250514",
api_key=os.getenv("ANTHROPIC_API_KEY"),
),
model_settings=ModelSettings(
reasoning=Reasoning(effort="high", summary="detailed")
),
)
async def main():
results = await Runner.run(
agent, input="Count to 10", context=count_ctx, max_turns=30
)
print(results)
if __name__ == "__main__":
asyncio.run(main())
Describe the bug
When running the agents SDK with tool calling and a thinking model through LITELLM (e.g. sonnet 4) getting this error
Debug information
Repro steps
Expected behavior
Everything works :)
The text was updated successfully, but these errors were encountered: