fix: #1789 Fix multi-turn handling for conversation_id and previous_response_id: only send new items #1827
+520
−24
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.
This PR fixes incorrect behavior when using
conversation_id
orprevious_response_id
during internal multi-turn calls, i.e. when function calling is involved.It provides better support for the OpenAI Conversation state feature, as described in the https://platform.openai.com/docs/guides/conversation-state?api-mode=responses, aligning with the intended API design.
Resolved: #1789
Problem
previous_response_id
was not updated across internal loops. This led to duplicated items and wasted bandwidth, even though it did not trigger errors currently. On the OpenAI platform dashboard logs, this can be observed as the responses repeatedly forking (based on the initially providedprevious_response_id
) instead of properly chaining.Minimal repro code:
This produces the following error:
Solution
previous_response_id
to the latest server response.test_conversation_id_only_sends_new_items_multi_turn
test_conversation_id_only_sends_new_items_multi_turn_streamed
test_previous_response_id_only_sends_new_items_multi_turn
test_previous_response_id_only_sends_new_items_multi_turn_streamed
test_default_send_all_items
test_default_send_all_items_streamed
previous_response_id
of the last model response.previous_response_id
on each turn, the assertion was modified accordingly.OpenAIConversationsSession
, which does not support passing lists of items containing images or files by default, this approach works out of the box and fully supports such items between turns.