fix(run): fail fast on incompatible handoff settings with server conversation #2457
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This PR adds an early validation guard for server-managed conversations to prevent unsupported handoff combinations from reaching the model API.
When
conversation_id,previous_response_id, orauto_previous_response_idis used, the SDK now raises aUserErrorif handoff settings require local history/tool-state rewriting that the server-managed flow cannot support.Specifically, it rejects:
nest_handoff_history=True(when no input filter is set on that handoff)remove_all_tools(handoff-local or globalrun_config.handoff_input_filter)Why
Issue:
#2151With server-managed conversation, these handoff options can produce invalid or conflicting assumptions about what is sent to downstream turns. The current behavior fails late. This change fails fast with a clear error message before execution starts.
Changes
validate_server_conversation_handoff_settings(...)inagent_runner_helpers.Agenthandoffs and explicitHandoffentries.Runner.runandRunner.run_streamed:remove_all_toolsrun_config.handoff_input_filter=remove_all_toolsValidation
uv run ruff check src/agents/run_internal/agent_runner_helpers.py src/agents/run.py tests/test_agent_runner.pyuv run mypy src/agents/run_internal/agent_runner_helpers.py src/agents/run.py tests/test_agent_runner.pyenv -u all_proxy -u ALL_PROXY -u http_proxy -u HTTP_PROXY -u https_proxy -u HTTPS_PROXY uv run pytest tests/test_agent_runner.py -k "server_conversation" -qenv -u all_proxy -u ALL_PROXY -u http_proxy -u HTTP_PROXY -u https_proxy -u HTTPS_PROXY uv run pytest tests/test_agent_runner.py -qenv -u all_proxy -u ALL_PROXY -u http_proxy -u HTTP_PROXY -u https_proxy -u HTTPS_PROXY uv run python -m trace --count --coverdir /tmp/openai_agents_2151_trace --module pytest tests/test_agent_runner.py -k "server_conversation" -qTrace output confirms the newly added validation paths in
src/agents/run_internal/agent_runner_helpers.pyand their call sites insrc/agents/run.pyare exercised.