-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Open
Labels
bugSomething isn't workingSomething isn't working
Description
Initial Checks
- I confirm that I'm using the latest version of Pydantic AI
- I confirm that I searched for my issue in https://github.com/pydantic/pydantic-ai/issues before opening this issue
Description
GPT-5 does not support tool_choice = "required"
ModelHTTPError: status_code: 400, model_name: gpt-5, body: {'message': "Tool choices other than 'auto' are not supported with model 'gpt-5' and the following tool types: 'web_search_preview'.", 'type': 'invalid_request_error', 'param': 'tool_choice', 'code': None}
Running a multi-agent setup where one of the called agents also attempts to use the OpenAI built-in websearch tool always yields this error.
Example Code
from pydantic_ai import Agent, RunContext
from pydantic_ai.models.openai import OpenAIResponsesModel, OpenAIResponsesModelSettings
from openai.types.responses import WebSearchToolParam
from pydantic_ai.usage import UsageLimits
openai_model = OpenAIResponsesModel('gpt-5')
openai_model_settings = OpenAIResponsesModelSettings(
openai_builtin_tools=[WebSearchToolParam(type='web_search_preview')],
)
joke_selection_agent = Agent(
model=openai_model,
system_prompt=(
'Use the `joke_factory` to generate some jokes, then choose the best. '
'You must return just a single joke.'
),
)
joke_generation_agent = Agent(
model=openai_model,
model_settings=openai_model_settings,
output_type=list[str]
)
@joke_selection_agent.tool
async def joke_factory(ctx: RunContext[None], count: int) -> list[str]:
r = await joke_generation_agent.run(
f'Please generate {count} jokes. Search the web for the best jokes.',
usage=ctx.usage,
)
return r.output
result = joke_selection_agent.run_sync(
'Tell me a joke.',
usage_limits=UsageLimits(request_limit=5, total_tokens_limit=90000),
)
print(result.output)
#> Did you hear about the toothpaste scandal? They called it Colgate.
print(result.usage())
#> Usage(requests=3, request_tokens=204, response_tokens=24, total_tokens=228)
Python, Pydantic AI & LLM client version
Python 13.12.2
Pydantic 0.6.2
LLM OpenAI Responses Api
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working