Skip to content

Commit 242efa1

Browse files
committed
Don't create copy and add test to test_agent_runner.py
1 parent 4bf33f4 commit 242efa1

File tree

2 files changed

+34
-4
lines changed

2 files changed

+34
-4
lines changed

src/agents/model_settings.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ class ModelSettings:
3131
"""The tool choice to use when calling the model."""
3232

3333
parallel_tool_calls: bool | None = None
34-
"""Whether to use parallel tool calls when calling the model."""
34+
"""Whether to use parallel tool calls when calling the model.
35+
Defaults to False if not provided."""
3536

3637
truncation: Literal["auto", "disabled"] | None = None
3738
"""The truncation strategy to use when calling the model."""
@@ -40,7 +41,8 @@ class ModelSettings:
4041
"""The maximum number of output tokens to generate."""
4142

4243
store: bool | None = None
43-
"""Whether to store the generated model response for later retrieval."""
44+
"""Whether to store the generated model response for later retrieval.
45+
Defaults to True if not provided."""
4446

4547
def resolve(self, override: ModelSettings | None) -> ModelSettings:
4648
"""Produce a new ModelSettings by overlaying any non-None values from the
@@ -50,6 +52,6 @@ def resolve(self, override: ModelSettings | None) -> ModelSettings:
5052

5153
new_values = {
5254
k: getattr(override, k) if getattr(override, k) is not None else getattr(self, k)
53-
for k in asdict(self)
55+
for k in self.__dataclass_fields__
5456
}
5557
return ModelSettings(**new_values)

tests/test_agent_runner.py

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
RunContextWrapper,
2020
Runner,
2121
UserError,
22-
handoff,
22+
handoff, ModelSettings, RunConfig,
2323
)
2424
from agents.agent import ToolsToFinalOutputResult
2525
from agents.tool import FunctionToolResult, function_tool
@@ -634,3 +634,31 @@ async def test_tool_use_behavior_custom_function():
634634

635635
assert len(result.raw_responses) == 2, "should have two model responses"
636636
assert result.final_output == "the_final_output", "should have used the custom function"
637+
638+
639+
@pytest.mark.asyncio
640+
async def test_model_settings_override():
641+
model = FakeModel()
642+
agent = Agent(
643+
name="test",
644+
model=model,
645+
model_settings=ModelSettings(temperature=1.0, max_tokens=1000)
646+
)
647+
648+
model.add_multiple_turn_outputs(
649+
[
650+
[
651+
get_text_message("a_message"),
652+
],
653+
]
654+
)
655+
656+
await Runner.run(
657+
agent,
658+
input="user_message",
659+
run_config=RunConfig(model_settings=ModelSettings(0.5)),
660+
)
661+
662+
# temperature is overridden by Runner.run, but max_tokens is not
663+
assert model.last_turn_args["model_settings"].temperature == 0.5
664+
assert model.last_turn_args["model_settings"].max_tokens == 1000

0 commit comments

Comments
 (0)