Skip to content

Conversation

ihower
Copy link
Contributor

@ihower ihower commented Sep 16, 2025

Issue

When store=False and handoff_filters.remove_all_tools is used during a handoff, the filter currently removes: HandoffCallItem and HandoffOutputItem... But it does not remove the corresponding ReasoningItem.

Since store=False means items are not persisted on the server side, the Responses API fails because the ReasoningItem is still present, but its referenced item has already been removed. This leads to a 404 error:

Error getting response: Error code: 404 - {'error': {'message': "Item with id 'rs_xxxx' not found. Items are not persisted when `store` is set to false. Try again with `store` set to true, or remove this item from your input.", 'type': 'invalid_request_error', 'param': 'input', 'code': None}}.

This PR fixes: #1668

Reproduction Example

from agents import Agent, ModelSettings, Runner, handoff
from agents.extensions import handoff_filters

agent2 = Agent(
    name="Assistant 2",
    model="gpt-5-mini",
    instructions="You always respond politely.",
    model_settings=ModelSettings(store=False),
)

agent = Agent(
    name="Assistant",
    model="gpt-5-mini",
    instructions="Always hand off to the assistant2 agent.",
    model_settings=ModelSettings(store=False),
    handoffs=[handoff(agent2, input_filter=handoff_filters.remove_all_tools)],
)

result = Runner.run_sync(agent, "Tell me something about San Francisco.")
print(result.final_output)

Solution

Updated _remove_tools_from_items(...) to also drop ReasoningItem.
This ensures that reasoning items are removed together with tool/handoff items, preventing API errors.

Note

There is another function in the same file, _remove_tool_types_from_input(...), which is for filtering the input history, and it intentionally does not remove reasoning items.

With store=False, removing it would also work without errors.

However, with store=True, developers often reuse the previous round’s to_input_list() (containing message items that include IDs) and pass it into the Responses API. In this case, the server requires each message to be paired with its corresponding reasoning item. Removing reasoning in this path would cause errors such as: Item 'msg_xxxxx' of type 'message' was provided without its required 'reasoning' item: 'rs_xxxxxx'

For this reason, _remove_tool_types_from_input(...) intentionally keeps reasoning items.

@seratch seratch changed the title Fix remove_all_tools should also drop ReasoningItem (fixes #1668) fixl: #1668 Handoffs with gpt-5* model + store=False + remove_all_tools fails due to 404 error response Sep 17, 2025
@seratch seratch added the bug Something isn't working label Sep 17, 2025
@seratch seratch merged commit 76d637d into openai:main Sep 17, 2025
5 checks passed
@seratch seratch changed the title fixl: #1668 Handoffs with gpt-5* model + store=False + remove_all_tools fails due to 404 error response fix: #1668 Handoffs with gpt-5* model + store=False + remove_all_tools fails due to 404 error response Sep 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working feature:core

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Handoffs with gpt-5* model + store=False + remove_all_tools fails due to 404 error response

2 participants