Skip to content

Add max_tokens and documentation to model settings #105

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 1 commit into from
Mar 12, 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
20 changes: 20 additions & 0 deletions src/agents/model_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,34 @@ class ModelSettings:

This class holds optional model configuration parameters (e.g. temperature,
top_p, penalties, truncation, etc.).

Not all models/providers support all of these parameters, so please check the API documentation
for the specific model and provider you are using.
"""

temperature: float | None = None
"""The temperature to use when calling the model."""

top_p: float | None = None
"""The top_p to use when calling the model."""

frequency_penalty: float | None = None
"""The frequency penalty to use when calling the model."""

presence_penalty: float | None = None
"""The presence penalty to use when calling the model."""

tool_choice: Literal["auto", "required", "none"] | str | None = None
"""The tool choice to use when calling the model."""

parallel_tool_calls: bool | None = False
"""Whether to use parallel tool calls when calling the model."""

truncation: Literal["auto", "disabled"] | None = None
"""The truncation strategy to use when calling the model."""

max_tokens: int | None = None
"""The maximum number of output tokens to generate."""

def resolve(self, override: ModelSettings | None) -> ModelSettings:
"""Produce a new ModelSettings by overlaying any non-None values from the
Expand All @@ -33,4 +52,5 @@ def resolve(self, override: ModelSettings | None) -> ModelSettings:
tool_choice=override.tool_choice or self.tool_choice,
parallel_tool_calls=override.parallel_tool_calls or self.parallel_tool_calls,
truncation=override.truncation or self.truncation,
max_tokens=override.max_tokens or self.max_tokens,
)
1 change: 1 addition & 0 deletions src/agents/models/openai_chatcompletions.py
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,7 @@ async def _fetch_response(
top_p=self._non_null_or_not_given(model_settings.top_p),
frequency_penalty=self._non_null_or_not_given(model_settings.frequency_penalty),
presence_penalty=self._non_null_or_not_given(model_settings.presence_penalty),
max_tokens=self._non_null_or_not_given(model_settings.max_tokens),
tool_choice=tool_choice,
response_format=response_format,
parallel_tool_calls=parallel_tool_calls,
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 @@ -235,6 +235,7 @@ async def _fetch_response(
temperature=self._non_null_or_not_given(model_settings.temperature),
top_p=self._non_null_or_not_given(model_settings.top_p),
truncation=self._non_null_or_not_given(model_settings.truncation),
max_output_tokens=self._non_null_or_not_given(model_settings.max_tokens),
tool_choice=tool_choice,
parallel_tool_calls=parallel_tool_calls,
stream=stream,
Expand Down