Skip to content
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

Add reasoning parameter to ModelSettings #388

Merged
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
7 changes: 7 additions & 0 deletions src/agents/model_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
from dataclasses import dataclass, fields, replace
from typing import Literal

from openai.types.shared import Reasoning


@dataclass
class ModelSettings:
Expand Down Expand Up @@ -40,6 +42,11 @@ class ModelSettings:
max_tokens: int | None = None
"""The maximum number of output tokens to generate."""

reasoning: Reasoning | None = None
"""Configuration options for
[reasoning models](https://platform.openai.com/docs/guides/reasoning).
"""

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

Expand Down
4 changes: 4 additions & 0 deletions src/agents/models/openai_chatcompletions.py
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,8 @@ async def _fetch_response(
# Match the behavior of Responses where store is True when not given
store = model_settings.store if model_settings.store is not None else True

reasoning_effort = model_settings.reasoning.effort if model_settings.reasoning else None

ret = await self._get_client().chat.completions.create(
model=self.model,
messages=converted_messages,
Expand All @@ -536,6 +538,7 @@ async def _fetch_response(
stream=stream,
stream_options={"include_usage": True} if stream else NOT_GIVEN,
store=store,
reasoning_effort=self._non_null_or_not_given(reasoning_effort),
extra_headers=_HEADERS,
metadata=model_settings.metadata,
)
Expand All @@ -556,6 +559,7 @@ async def _fetch_response(
temperature=model_settings.temperature,
tools=[],
parallel_tool_calls=parallel_tool_calls or False,
reasoning=model_settings.reasoning,
)
return response, ret

Expand Down
1 change: 1 addition & 0 deletions src/agents/models/openai_responses.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ async def _fetch_response(
extra_headers=_HEADERS,
text=response_format,
store=self._non_null_or_not_given(model_settings.store),
reasoning=self._non_null_or_not_given(model_settings.reasoning),
metadata=model_settings.metadata,
)

Expand Down