diff --git a/src/agents/_run_impl.py b/src/agents/_run_impl.py index 0272520..df3db42 100644 --- a/src/agents/_run_impl.py +++ b/src/agents/_run_impl.py @@ -216,22 +216,19 @@ class RunImpl: run_config.model_settings and cls._should_reset_tool_choice(run_config.model_settings, tools) ): - # Also update the run_config model settings with a copy + # update the run_config model settings with a copy new_run_config_settings = dataclasses.replace( run_config.model_settings, tool_choice="auto" ) - # Create a new run_config with the new settings run_config = dataclasses.replace(run_config, model_settings=new_run_config_settings) - # Only reset in the problematic scenarios where loops are likely unintentional if cls._should_reset_tool_choice(agent.model_settings, tools): # Create a modified copy instead of modifying the original agent new_model_settings = dataclasses.replace( agent.model_settings, tool_choice="auto" ) - # Create a new internal agent with updated settings agent = dataclasses.replace(agent, model_settings=new_model_settings) # Second, check if there are any handoffs