Skip to content

Fix #1407 Add reasoning.effort="minimal" and "verbosity" params to ModelSettings #1439

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions examples/basic/simple_gpt_5.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import asyncio

from openai.types.shared import Reasoning

from agents import Agent, ModelSettings, Runner

# If you have a certain reason to use Chat Completions, you can configure the model this way,
# and then you can pass the chat_completions_model to the Agent constructor.
# from openai import AsyncOpenAI
# client = AsyncOpenAI()
# from agents import OpenAIChatCompletionsModel
# chat_completions_model = OpenAIChatCompletionsModel(model="gpt-5", openai_client=client)


async def main():
agent = Agent(
name="Knowledgable GPT-5 Assistant",
instructions="You're a knowledgable assistant. You always provide an interesting answer.",
model="gpt-5",
model_settings=ModelSettings(
reasoning=Reasoning(effort="minimal"), # "minimal", "low", "medium", "high"
verbosity="low", # "low", "medium", "high"
),
)
result = await Runner.run(agent, "Tell me something about recursion in programming.")
print(result.final_output)


if __name__ == "__main__":
asyncio.run(main())
4 changes: 4 additions & 0 deletions src/agents/model_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@ class ModelSettings:
[reasoning models](https://platform.openai.com/docs/guides/reasoning).
"""

verbosity: Literal["low", "medium", "high"] | None = None
"""Constrains the verbosity of the model's response.
"""

metadata: dict[str, str] | None = None
"""Metadata to include with the model response call."""

Expand Down
1 change: 1 addition & 0 deletions src/agents/models/openai_chatcompletions.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@ async def _fetch_response(
stream_options=self._non_null_or_not_given(stream_options),
store=self._non_null_or_not_given(store),
reasoning_effort=self._non_null_or_not_given(reasoning_effort),
verbosity=self._non_null_or_not_given(model_settings.verbosity),
top_logprobs=self._non_null_or_not_given(model_settings.top_logprobs),
extra_headers={**HEADERS, **(model_settings.extra_headers or {})},
extra_query=model_settings.extra_query,
Expand Down
5 changes: 5 additions & 0 deletions src/agents/models/openai_responses.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,11 @@ async def _fetch_response(
extra_args = dict(model_settings.extra_args or {})
if model_settings.top_logprobs is not None:
extra_args["top_logprobs"] = model_settings.top_logprobs
if model_settings.verbosity is not None:
if response_format != NOT_GIVEN:
response_format["verbosity"] = model_settings.verbosity # type: ignore [index]
else:
response_format = {"verbosity": model_settings.verbosity}

return await self._client.responses.create(
previous_response_id=self._non_null_or_not_given(previous_response_id),
Expand Down
1 change: 1 addition & 0 deletions tests/model_settings/test_serialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ def test_all_fields_serialization() -> None:
include_usage=False,
response_include=["reasoning.encrypted_content"],
top_logprobs=1,
verbosity="low",
extra_query={"foo": "bar"},
extra_body={"foo": "bar"},
extra_headers={"foo": "bar"},
Expand Down