Skip to content

Conversation

@ihower
Copy link
Contributor

@ihower ihower commented Nov 23, 2025

Resolved issue: #2124

Relative Issue: #2020 (comment) (reported in a comment)
Relative PR: #1827

This PR enables previous_response_id chaining during internal function calls inside the first turn, even though no real previous_response_id exists yet.

Only the first turn is special-cased; once the first real response_id is obtained, all subsequent turns behave normally.

Background

Currently, previous_response_id chaining only enables when a real previous response ID is explicitly provided. This works fine for subsequent turns, but it has a limitation:

For the first turn of a brand-new conversation, there is no existing previous_response_id. As a result, there is no way to tell the SDK that internal function calls can use previous_response_id chaining.

Solution

Introduce a special flag value:

previous_response_id = "" # or name it as any other string

Setting "" makes the internal function calls inside the first turn use proper response chaining.

Example usage:

previous_response_id = ""

while True:
    user_input = input()
    result = await Runner.run(
        agent,
        user_input, 
        previous_response_id=previous_response_id
    )
    previous_response_id = result.last_response_id

Alternative solution

"" is just one idea. We can rename it to any other string.

If the empty string is undesirable, an explicit parameter could be added:

previous_response_id = None

while True:
    user_input = input()
    result = await Runner.run(
        agent,
        user_input,
        previous_response_id = previous_response_id,
        enable_internal_previous_response_chaining=True,
    )    
    previous_response_id = result.last_response_id

However, this introduces an extra API parameter solely for this feature and feels a little verbose.
I am open to switching to this approach if preferred.

@ihower ihower changed the title Add previous_response_id=bootstrap to enable chaining for internal calls on the first turn Enable previous_response_id chaining for internal calls on the first turn Nov 23, 2025
@seratch seratch added enhancement New feature or request feature:core labels Nov 24, 2025
@seratch
Copy link
Member

seratch commented Nov 24, 2025

Thanks for sending this. Since I'm on PTOs this week, let me think about solutions for this next week.

@ihower
Copy link
Contributor Author

ihower commented Nov 26, 2025

On second thought, "bootstrap" feels a bit odd, so I changed it to use an empty string "" instead.

@seratch seratch added this to the 0.7.x milestone Dec 2, 2025
@seratch
Copy link
Member

seratch commented Dec 2, 2025

Neither "bootstrap" nor "" sounds intuitive to me. What do you think about auto_previous_response_id=True?

@ihower ihower force-pushed the add-previous-response-id-bootstrap branch from 5467f03 to 4d426e1 Compare December 2, 2025 18:55
@ihower
Copy link
Contributor Author

ihower commented Dec 2, 2025

@seratch Sure, auto_previous_response_id sounds good to me too. I have updated the code accordingly, and also revised the example to use a while loop so it better reflects a real multi-turn conversation.

@seratch seratch merged commit a9d95b4 into openai:main Dec 4, 2025
9 checks passed
@seratch seratch modified the milestones: 0.7.x, 0.6.x Dec 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request feature:core

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants