@@ -662,3 +662,86 @@ async def test_model_settings_override():
662
662
# temperature is overridden by Runner.run, but max_tokens is not
663
663
assert model .last_turn_args ["model_settings" ].temperature == 0.5
664
664
assert model .last_turn_args ["model_settings" ].max_tokens == 1000
665
+
666
+
667
+ @pytest .mark .asyncio
668
+ async def test_previous_response_id_passed_between_runs ():
669
+ """Test that previous_response_id is passed to the model on subsequent runs."""
670
+ model = FakeModel ()
671
+ model .set_next_output ([get_text_message ("done" )])
672
+ agent = Agent (name = "test" , model = model )
673
+
674
+ assert model .last_turn_args .get ("previous_response_id" ) is None
675
+ await Runner .run (agent , input = "test" , previous_response_id = "resp-non-streamed-test" )
676
+ assert model .last_turn_args .get ("previous_response_id" ) == "resp-non-streamed-test"
677
+
678
+
679
+ @pytest .mark .asyncio
680
+ async def test_multi_turn_previous_response_id_passed_between_runs ():
681
+ """Test that previous_response_id is passed to the model on subsequent runs."""
682
+
683
+ model = FakeModel ()
684
+ agent = Agent (
685
+ name = "test" ,
686
+ model = model ,
687
+ tools = [get_function_tool ("foo" , "tool_result" )],
688
+ )
689
+
690
+ model .add_multiple_turn_outputs (
691
+ [
692
+ # First turn: a message and tool call
693
+ [get_text_message ("a_message" ), get_function_tool_call ("foo" , json .dumps ({"a" : "b" }))],
694
+ # Second turn: text message
695
+ [get_text_message ("done" )],
696
+ ]
697
+ )
698
+
699
+ assert model .last_turn_args .get ("previous_response_id" ) is None
700
+ await Runner .run (agent , input = "test" , previous_response_id = "resp-test-123" )
701
+ assert model .last_turn_args .get ("previous_response_id" ) == "resp-test-123"
702
+
703
+
704
+ @pytest .mark .asyncio
705
+ async def test_previous_response_id_passed_between_runs_streamed ():
706
+ """Test that previous_response_id is passed to the model on subsequent streamed runs."""
707
+ model = FakeModel ()
708
+ model .set_next_output ([get_text_message ("done" )])
709
+ agent = Agent (
710
+ name = "test" ,
711
+ model = model ,
712
+ )
713
+
714
+ assert model .last_turn_args .get ("previous_response_id" ) is None
715
+ result = Runner .run_streamed (agent , input = "test" , previous_response_id = "resp-stream-test" )
716
+ async for _ in result .stream_events ():
717
+ pass
718
+
719
+ assert model .last_turn_args .get ("previous_response_id" ) == "resp-stream-test"
720
+
721
+
722
+ @pytest .mark .asyncio
723
+ async def test_previous_response_id_passed_between_runs_streamed_multi_turn ():
724
+ """Test that previous_response_id is passed to the model on subsequent streamed runs."""
725
+
726
+ model = FakeModel ()
727
+ agent = Agent (
728
+ name = "test" ,
729
+ model = model ,
730
+ tools = [get_function_tool ("foo" , "tool_result" )],
731
+ )
732
+
733
+ model .add_multiple_turn_outputs (
734
+ [
735
+ # First turn: a message and tool call
736
+ [get_text_message ("a_message" ), get_function_tool_call ("foo" , json .dumps ({"a" : "b" }))],
737
+ # Second turn: text message
738
+ [get_text_message ("done" )],
739
+ ]
740
+ )
741
+
742
+ assert model .last_turn_args .get ("previous_response_id" ) is None
743
+ result = Runner .run_streamed (agent , input = "test" , previous_response_id = "resp-stream-test" )
744
+ async for _ in result .stream_events ():
745
+ pass
746
+
747
+ assert model .last_turn_args .get ("previous_response_id" ) == "resp-stream-test"
0 commit comments