@@ -199,6 +199,9 @@ class RunOptions(TypedDict, Generic[TContext]):
199199 previous_response_id : NotRequired [str | None ]
200200 """The ID of the previous response, if any."""
201201
202+ conversation_id : NotRequired [str | None ]
203+ """The ID of the stored conversation, if any."""
204+
202205 session : NotRequired [Session | None ]
203206 """The session for the run."""
204207
@@ -215,6 +218,7 @@ async def run(
215218 hooks : RunHooks [TContext ] | None = None ,
216219 run_config : RunConfig | None = None ,
217220 previous_response_id : str | None = None ,
221+ conversation_id : str | None = None ,
218222 session : Session | None = None ,
219223 ) -> RunResult :
220224 """Run a workflow starting at the given agent. The agent will run in a loop until a final
@@ -239,6 +243,7 @@ async def run(
239243 run_config: Global settings for the entire agent run.
240244 previous_response_id: The ID of the previous response, if using OpenAI models via the
241245 Responses API, this allows you to skip passing in input from the previous turn.
246+ conversation_id: The ID of the stored conversation, if any.
242247 Returns:
243248 A run result containing all the inputs, guardrail results and the output of the last
244249 agent. Agents may perform handoffs, so we don't know the specific type of the output.
@@ -252,6 +257,7 @@ async def run(
252257 hooks = hooks ,
253258 run_config = run_config ,
254259 previous_response_id = previous_response_id ,
260+ conversation_id = conversation_id ,
255261 session = session ,
256262 )
257263
@@ -266,6 +272,7 @@ def run_sync(
266272 hooks : RunHooks [TContext ] | None = None ,
267273 run_config : RunConfig | None = None ,
268274 previous_response_id : str | None = None ,
275+ conversation_id : str | None = None ,
269276 session : Session | None = None ,
270277 ) -> RunResult :
271278 """Run a workflow synchronously, starting at the given agent. Note that this just wraps the
@@ -293,6 +300,7 @@ def run_sync(
293300 run_config: Global settings for the entire agent run.
294301 previous_response_id: The ID of the previous response, if using OpenAI models via the
295302 Responses API, this allows you to skip passing in input from the previous turn.
303+ conversation_id: The ID of the stored conversation, if any.
296304 Returns:
297305 A run result containing all the inputs, guardrail results and the output of the last
298306 agent. Agents may perform handoffs, so we don't know the specific type of the output.
@@ -306,6 +314,7 @@ def run_sync(
306314 hooks = hooks ,
307315 run_config = run_config ,
308316 previous_response_id = previous_response_id ,
317+ conversation_id = conversation_id ,
309318 session = session ,
310319 )
311320
@@ -319,6 +328,7 @@ def run_streamed(
319328 hooks : RunHooks [TContext ] | None = None ,
320329 run_config : RunConfig | None = None ,
321330 previous_response_id : str | None = None ,
331+ conversation_id : str | None = None ,
322332 session : Session | None = None ,
323333 ) -> RunResultStreaming :
324334 """Run a workflow starting at the given agent in streaming mode. The returned result object
@@ -344,6 +354,7 @@ def run_streamed(
344354 run_config: Global settings for the entire agent run.
345355 previous_response_id: The ID of the previous response, if using OpenAI models via the
346356 Responses API, this allows you to skip passing in input from the previous turn.
357+ conversation_id: The ID of the stored conversation, if any.
347358 Returns:
348359 A result object that contains data about the run, as well as a method to stream events.
349360 """
@@ -356,6 +367,7 @@ def run_streamed(
356367 hooks = hooks ,
357368 run_config = run_config ,
358369 previous_response_id = previous_response_id ,
370+ conversation_id = conversation_id ,
359371 session = session ,
360372 )
361373
@@ -377,6 +389,7 @@ async def run(
377389 hooks = kwargs .get ("hooks" )
378390 run_config = kwargs .get ("run_config" )
379391 previous_response_id = kwargs .get ("previous_response_id" )
392+ conversation_id = kwargs .get ("conversation_id" )
380393 session = kwargs .get ("session" )
381394 if hooks is None :
382395 hooks = RunHooks [Any ]()
@@ -469,6 +482,7 @@ async def run(
469482 should_run_agent_start_hooks = should_run_agent_start_hooks ,
470483 tool_use_tracker = tool_use_tracker ,
471484 previous_response_id = previous_response_id ,
485+ conversation_id = conversation_id ,
472486 ),
473487 )
474488 else :
@@ -483,6 +497,7 @@ async def run(
483497 should_run_agent_start_hooks = should_run_agent_start_hooks ,
484498 tool_use_tracker = tool_use_tracker ,
485499 previous_response_id = previous_response_id ,
500+ conversation_id = conversation_id ,
486501 )
487502 should_run_agent_start_hooks = False
488503
@@ -549,6 +564,7 @@ def run_sync(
549564 hooks = kwargs .get ("hooks" )
550565 run_config = kwargs .get ("run_config" )
551566 previous_response_id = kwargs .get ("previous_response_id" )
567+ conversation_id = kwargs .get ("conversation_id" )
552568 session = kwargs .get ("session" )
553569
554570 return asyncio .get_event_loop ().run_until_complete (
@@ -561,6 +577,7 @@ def run_sync(
561577 hooks = hooks ,
562578 run_config = run_config ,
563579 previous_response_id = previous_response_id ,
580+ conversation_id = conversation_id ,
564581 )
565582 )
566583
@@ -575,6 +592,7 @@ def run_streamed(
575592 hooks = kwargs .get ("hooks" )
576593 run_config = kwargs .get ("run_config" )
577594 previous_response_id = kwargs .get ("previous_response_id" )
595+ conversation_id = kwargs .get ("conversation_id" )
578596 session = kwargs .get ("session" )
579597
580598 if hooks is None :
@@ -629,6 +647,7 @@ def run_streamed(
629647 context_wrapper = context_wrapper ,
630648 run_config = run_config ,
631649 previous_response_id = previous_response_id ,
650+ conversation_id = conversation_id ,
632651 session = session ,
633652 )
634653 )
@@ -729,6 +748,7 @@ async def _start_streaming(
729748 context_wrapper : RunContextWrapper [TContext ],
730749 run_config : RunConfig ,
731750 previous_response_id : str | None ,
751+ conversation_id : str | None ,
732752 session : Session | None ,
733753 ):
734754 if streamed_result .trace :
@@ -812,6 +832,7 @@ async def _start_streaming(
812832 tool_use_tracker ,
813833 all_tools ,
814834 previous_response_id ,
835+ conversation_id ,
815836 )
816837 should_run_agent_start_hooks = False
817838
@@ -914,6 +935,7 @@ async def _run_single_turn_streamed(
914935 tool_use_tracker : AgentToolUseTracker ,
915936 all_tools : list [Tool ],
916937 previous_response_id : str | None ,
938+ conversation_id : str | None ,
917939 ) -> SingleStepResult :
918940 emitted_tool_call_ids : set [str ] = set ()
919941
@@ -974,6 +996,7 @@ async def _run_single_turn_streamed(
974996 run_config .tracing_disabled , run_config .trace_include_sensitive_data
975997 ),
976998 previous_response_id = previous_response_id ,
999+ conversation_id = conversation_id ,
9771000 prompt = prompt_config ,
9781001 ):
9791002 if isinstance (event , ResponseCompletedEvent ):
@@ -1082,6 +1105,7 @@ async def _run_single_turn(
10821105 should_run_agent_start_hooks : bool ,
10831106 tool_use_tracker : AgentToolUseTracker ,
10841107 previous_response_id : str | None ,
1108+ conversation_id : str | None ,
10851109 ) -> SingleStepResult :
10861110 # Ensure we run the hooks before anything else
10871111 if should_run_agent_start_hooks :
@@ -1115,6 +1139,7 @@ async def _run_single_turn(
11151139 run_config ,
11161140 tool_use_tracker ,
11171141 previous_response_id ,
1142+ conversation_id ,
11181143 prompt_config ,
11191144 )
11201145
@@ -1309,6 +1334,7 @@ async def _get_new_response(
13091334 run_config : RunConfig ,
13101335 tool_use_tracker : AgentToolUseTracker ,
13111336 previous_response_id : str | None ,
1337+ conversation_id : str | None ,
13121338 prompt_config : ResponsePromptParam | None ,
13131339 ) -> ModelResponse :
13141340 # Allow user to modify model input right before the call, if configured
@@ -1343,6 +1369,7 @@ async def _get_new_response(
13431369 run_config .tracing_disabled , run_config .trace_include_sensitive_data
13441370 ),
13451371 previous_response_id = previous_response_id ,
1372+ conversation_id = conversation_id ,
13461373 prompt = prompt_config ,
13471374 )
13481375 # If the agent has hooks, we need to call them after the LLM call
0 commit comments