Skip to content

Only 'auto' tool_choice is supported in response API with Harmony. when i build a agent with gpt-oss-120b, if I assign a 'output_type', the tool_choice will be set to 'required', contradicted to the requirement. #2783

@gsu2017

Description

@gsu2017

Initial Checks

Description

I just run the example code in pydantic-ai docs, olympics.py.
and the model is gpt-oss-120b (OpenAIResponsesModel), self-deployed by vllm.

  • if set agent = Agent(model, output_type=CityLocation), then got a error message like this,

{'message': "Only 'auto' tool_choice is supported in response API with Harmony None", 'type': 'BadRequestError', 'param': None, 'code': 400}

  • but if set agent = Agent(model), then it output successfully.

The 2012 Summer Olympic Games were held in **London, United Kingdom**. blahblah...

And I noticed that you said 'Pydantic AI leverages the model's tool calling capability to make it return structured data.', so maybe the tool_choice parameter setting is not compatible for gpt-oss series models.

Example Code

import logging
logging.basicConfig(level=logging.DEBUG)

from pydantic import BaseModel

from pydantic_ai import Agent
try:
    from model import model
except:
    from pydantic_ai.models.openai import OpenAIResponsesModel
    from pydantic_ai.providers.openai import OpenAIProvider
    model = OpenAIResponsesModel(
        model_name='gpt-oss-120b',
        provider=OpenAIProvider(
            base_url='',
            api_key=''
        )
    )

class CityLocation(BaseModel):
    city: str
    country: str


agent = Agent(model)
# agent = Agent(model, output_type=CityLocation)
result = agent.run_sync('Where were the olympics held in 2012?')
print(result.output)
#> city='London' country='United Kingdom'
print(result.usage())
#> Usage(requests=1, request_tokens=57, response_tokens=8, total_tokens=65)

Python, Pydantic AI & LLM client version

python 3.10
pydantic-ai 0.8.0
llm_client openai

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions