refactor: improve comments for clarity in tool_choice reset logic

This commit is contained in:
xianghuijin 2025-03-23 20:41:18 +08:00
parent 0c747af743
commit 07a4af1fe2

View file

@ -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