@@ -117,6 +117,7 @@ async def run(
117117 max_turns : int = DEFAULT_MAX_TURNS ,
118118 hooks : RunHooks [TContext ] | None = None ,
119119 run_config : RunConfig | None = None ,
120+ previous_response_id : str | None = None ,
120121 ) -> RunResult :
121122 """Run a workflow starting at the given agent. The agent will run in a loop until a final
122123 output is generated. The loop runs like so:
@@ -141,6 +142,8 @@ async def run(
141142 AI invocation (including any tool calls that might occur).
142143 hooks: An object that receives callbacks on various lifecycle events.
143144 run_config: Global settings for the entire agent run.
145+ previous_response_id: The ID of the previous response, if using OpenAI models via the
146+ Responses API, this allows you to skip passing in input from the previous turn.
144147
145148 Returns:
146149 A run result containing all the inputs, guardrail results and the output of the last
@@ -230,6 +233,7 @@ async def run(
230233 run_config = run_config ,
231234 should_run_agent_start_hooks = should_run_agent_start_hooks ,
232235 tool_use_tracker = tool_use_tracker ,
236+ previous_response_id = previous_response_id ,
233237 ),
234238 )
235239 else :
@@ -243,6 +247,7 @@ async def run(
243247 run_config = run_config ,
244248 should_run_agent_start_hooks = should_run_agent_start_hooks ,
245249 tool_use_tracker = tool_use_tracker ,
250+ previous_response_id = previous_response_id ,
246251 )
247252 should_run_agent_start_hooks = False
248253
@@ -291,6 +296,7 @@ def run_sync(
291296 max_turns : int = DEFAULT_MAX_TURNS ,
292297 hooks : RunHooks [TContext ] | None = None ,
293298 run_config : RunConfig | None = None ,
299+ previous_response_id : str | None = None ,
294300 ) -> RunResult :
295301 """Run a workflow synchronously, starting at the given agent. Note that this just wraps the
296302 `run` method, so it will not work if there's already an event loop (e.g. inside an async
@@ -319,6 +325,8 @@ def run_sync(
319325 AI invocation (including any tool calls that might occur).
320326 hooks: An object that receives callbacks on various lifecycle events.
321327 run_config: Global settings for the entire agent run.
328+ previous_response_id: The ID of the previous response, if using OpenAI models via the
329+ Responses API, this allows you to skip passing in input from the previous turn.
322330
323331 Returns:
324332 A run result containing all the inputs, guardrail results and the output of the last
@@ -332,6 +340,7 @@ def run_sync(
332340 max_turns = max_turns ,
333341 hooks = hooks ,
334342 run_config = run_config ,
343+ previous_response_id = previous_response_id ,
335344 )
336345 )
337346
@@ -344,6 +353,7 @@ def run_streamed(
344353 max_turns : int = DEFAULT_MAX_TURNS ,
345354 hooks : RunHooks [TContext ] | None = None ,
346355 run_config : RunConfig | None = None ,
356+ previous_response_id : str | None = None ,
347357 ) -> RunResultStreaming :
348358 """Run a workflow starting at the given agent in streaming mode. The returned result object
349359 contains a method you can use to stream semantic events as they are generated.
@@ -370,7 +380,8 @@ def run_streamed(
370380 AI invocation (including any tool calls that might occur).
371381 hooks: An object that receives callbacks on various lifecycle events.
372382 run_config: Global settings for the entire agent run.
373-
383+ previous_response_id: The ID of the previous response, if using OpenAI models via the
384+ Responses API, this allows you to skip passing in input from the previous turn.
374385 Returns:
375386 A result object that contains data about the run, as well as a method to stream events.
376387 """
@@ -428,6 +439,7 @@ def run_streamed(
428439 hooks = hooks ,
429440 context_wrapper = context_wrapper ,
430441 run_config = run_config ,
442+ previous_response_id = previous_response_id ,
431443 )
432444 )
433445 return streamed_result
@@ -485,6 +497,7 @@ async def _run_streamed_impl(
485497 hooks : RunHooks [TContext ],
486498 context_wrapper : RunContextWrapper [TContext ],
487499 run_config : RunConfig ,
500+ previous_response_id : str | None ,
488501 ):
489502 current_span : Span [AgentSpanData ] | None = None
490503 current_agent = starting_agent
@@ -554,6 +567,7 @@ async def _run_streamed_impl(
554567 should_run_agent_start_hooks ,
555568 tool_use_tracker ,
556569 all_tools ,
570+ previous_response_id ,
557571 )
558572 should_run_agent_start_hooks = False
559573
@@ -623,6 +637,7 @@ async def _run_single_turn_streamed(
623637 should_run_agent_start_hooks : bool ,
624638 tool_use_tracker : AgentToolUseTracker ,
625639 all_tools : list [Tool ],
640+ previous_response_id : str | None ,
626641 ) -> SingleStepResult :
627642 if should_run_agent_start_hooks :
628643 await asyncio .gather (
@@ -662,6 +677,7 @@ async def _run_single_turn_streamed(
662677 get_model_tracing_impl (
663678 run_config .tracing_disabled , run_config .trace_include_sensitive_data
664679 ),
680+ previous_response_id = previous_response_id ,
665681 ):
666682 if isinstance (event , ResponseCompletedEvent ):
667683 usage = (
@@ -717,6 +733,7 @@ async def _run_single_turn(
717733 run_config : RunConfig ,
718734 should_run_agent_start_hooks : bool ,
719735 tool_use_tracker : AgentToolUseTracker ,
736+ previous_response_id : str | None ,
720737 ) -> SingleStepResult :
721738 # Ensure we run the hooks before anything else
722739 if should_run_agent_start_hooks :
@@ -746,6 +763,7 @@ async def _run_single_turn(
746763 context_wrapper ,
747764 run_config ,
748765 tool_use_tracker ,
766+ previous_response_id ,
749767 )
750768
751769 return await cls ._get_single_step_result_from_response (
@@ -888,6 +906,7 @@ async def _get_new_response(
888906 context_wrapper : RunContextWrapper [TContext ],
889907 run_config : RunConfig ,
890908 tool_use_tracker : AgentToolUseTracker ,
909+ previous_response_id : str | None ,
891910 ) -> ModelResponse :
892911 model = cls ._get_model (agent , run_config )
893912 model_settings = agent .model_settings .resolve (run_config .model_settings )
@@ -903,6 +922,7 @@ async def _get_new_response(
903922 tracing = get_model_tracing_impl (
904923 run_config .tracing_disabled , run_config .trace_include_sensitive_data
905924 ),
925+ previous_response_id = previous_response_id ,
906926 )
907927
908928 context_wrapper .usage .add (new_response .usage )
0 commit comments