@@ -208,6 +208,9 @@ class RunOptions(TypedDict, Generic[TContext]):
208208 previous_response_id : NotRequired [str | None ]
209209 """The ID of the previous response, if any."""
210210
211+ conversation_id : NotRequired [str | None ]
212+ """The ID of the stored conversation, if any."""
213+
211214 session : NotRequired [Session | None ]
212215 """The session for the run."""
213216
@@ -224,6 +227,7 @@ async def run(
224227 hooks : RunHooks [TContext ] | None = None ,
225228 run_config : RunConfig | None = None ,
226229 previous_response_id : str | None = None ,
230+ conversation_id : str | None = None ,
227231 session : Session | None = None ,
228232 ) -> RunResult :
229233 """Run a workflow starting at the given agent. The agent will run in a loop until a final
@@ -248,6 +252,7 @@ async def run(
248252 run_config: Global settings for the entire agent run.
249253 previous_response_id: The ID of the previous response, if using OpenAI models via the
250254 Responses API, this allows you to skip passing in input from the previous turn.
255+ conversation_id: The ID of the stored conversation, if any.
251256 Returns:
252257 A run result containing all the inputs, guardrail results and the output of the last
253258 agent. Agents may perform handoffs, so we don't know the specific type of the output.
@@ -261,6 +266,7 @@ async def run(
261266 hooks = hooks ,
262267 run_config = run_config ,
263268 previous_response_id = previous_response_id ,
269+ conversation_id = conversation_id ,
264270 session = session ,
265271 )
266272
@@ -275,6 +281,7 @@ def run_sync(
275281 hooks : RunHooks [TContext ] | None = None ,
276282 run_config : RunConfig | None = None ,
277283 previous_response_id : str | None = None ,
284+ conversation_id : str | None = None ,
278285 session : Session | None = None ,
279286 ) -> RunResult :
280287 """Run a workflow synchronously, starting at the given agent. Note that this just wraps the
@@ -302,6 +309,7 @@ def run_sync(
302309 run_config: Global settings for the entire agent run.
303310 previous_response_id: The ID of the previous response, if using OpenAI models via the
304311 Responses API, this allows you to skip passing in input from the previous turn.
312+ conversation_id: The ID of the stored conversation, if any.
305313 Returns:
306314 A run result containing all the inputs, guardrail results and the output of the last
307315 agent. Agents may perform handoffs, so we don't know the specific type of the output.
@@ -315,6 +323,7 @@ def run_sync(
315323 hooks = hooks ,
316324 run_config = run_config ,
317325 previous_response_id = previous_response_id ,
326+ conversation_id = conversation_id ,
318327 session = session ,
319328 )
320329
@@ -328,6 +337,7 @@ def run_streamed(
328337 hooks : RunHooks [TContext ] | None = None ,
329338 run_config : RunConfig | None = None ,
330339 previous_response_id : str | None = None ,
340+ conversation_id : str | None = None ,
331341 session : Session | None = None ,
332342 ) -> RunResultStreaming :
333343 """Run a workflow starting at the given agent in streaming mode. The returned result object
@@ -353,6 +363,7 @@ def run_streamed(
353363 run_config: Global settings for the entire agent run.
354364 previous_response_id: The ID of the previous response, if using OpenAI models via the
355365 Responses API, this allows you to skip passing in input from the previous turn.
366+ conversation_id: The ID of the stored conversation, if any.
356367 Returns:
357368 A result object that contains data about the run, as well as a method to stream events.
358369 """
@@ -365,6 +376,7 @@ def run_streamed(
365376 hooks = hooks ,
366377 run_config = run_config ,
367378 previous_response_id = previous_response_id ,
379+ conversation_id = conversation_id ,
368380 session = session ,
369381 )
370382
@@ -386,6 +398,7 @@ async def run(
386398 hooks = kwargs .get ("hooks" )
387399 run_config = kwargs .get ("run_config" )
388400 previous_response_id = kwargs .get ("previous_response_id" )
401+ conversation_id = kwargs .get ("conversation_id" )
389402 session = kwargs .get ("session" )
390403 if hooks is None :
391404 hooks = RunHooks [Any ]()
@@ -478,6 +491,7 @@ async def run(
478491 should_run_agent_start_hooks = should_run_agent_start_hooks ,
479492 tool_use_tracker = tool_use_tracker ,
480493 previous_response_id = previous_response_id ,
494+ conversation_id = conversation_id ,
481495 ),
482496 )
483497 else :
@@ -492,6 +506,7 @@ async def run(
492506 should_run_agent_start_hooks = should_run_agent_start_hooks ,
493507 tool_use_tracker = tool_use_tracker ,
494508 previous_response_id = previous_response_id ,
509+ conversation_id = conversation_id ,
495510 )
496511 should_run_agent_start_hooks = False
497512
@@ -558,6 +573,7 @@ def run_sync(
558573 hooks = kwargs .get ("hooks" )
559574 run_config = kwargs .get ("run_config" )
560575 previous_response_id = kwargs .get ("previous_response_id" )
576+ conversation_id = kwargs .get ("conversation_id" )
561577 session = kwargs .get ("session" )
562578
563579 return asyncio .get_event_loop ().run_until_complete (
@@ -570,6 +586,7 @@ def run_sync(
570586 hooks = hooks ,
571587 run_config = run_config ,
572588 previous_response_id = previous_response_id ,
589+ conversation_id = conversation_id ,
573590 )
574591 )
575592
@@ -584,6 +601,7 @@ def run_streamed(
584601 hooks = kwargs .get ("hooks" )
585602 run_config = kwargs .get ("run_config" )
586603 previous_response_id = kwargs .get ("previous_response_id" )
604+ conversation_id = kwargs .get ("conversation_id" )
587605 session = kwargs .get ("session" )
588606
589607 if hooks is None :
@@ -638,6 +656,7 @@ def run_streamed(
638656 context_wrapper = context_wrapper ,
639657 run_config = run_config ,
640658 previous_response_id = previous_response_id ,
659+ conversation_id = conversation_id ,
641660 session = session ,
642661 )
643662 )
@@ -738,6 +757,7 @@ async def _start_streaming(
738757 context_wrapper : RunContextWrapper [TContext ],
739758 run_config : RunConfig ,
740759 previous_response_id : str | None ,
760+ conversation_id : str | None ,
741761 session : Session | None ,
742762 ):
743763 if streamed_result .trace :
@@ -821,6 +841,7 @@ async def _start_streaming(
821841 tool_use_tracker ,
822842 all_tools ,
823843 previous_response_id ,
844+ conversation_id ,
824845 )
825846 should_run_agent_start_hooks = False
826847
@@ -923,6 +944,7 @@ async def _run_single_turn_streamed(
923944 tool_use_tracker : AgentToolUseTracker ,
924945 all_tools : list [Tool ],
925946 previous_response_id : str | None ,
947+ conversation_id : str | None ,
926948 ) -> SingleStepResult :
927949 emitted_tool_call_ids : set [str ] = set ()
928950
@@ -983,6 +1005,7 @@ async def _run_single_turn_streamed(
9831005 run_config .tracing_disabled , run_config .trace_include_sensitive_data
9841006 ),
9851007 previous_response_id = previous_response_id ,
1008+ conversation_id = conversation_id ,
9861009 prompt = prompt_config ,
9871010 ):
9881011 if isinstance (event , ResponseCompletedEvent ):
@@ -1091,6 +1114,7 @@ async def _run_single_turn(
10911114 should_run_agent_start_hooks : bool ,
10921115 tool_use_tracker : AgentToolUseTracker ,
10931116 previous_response_id : str | None ,
1117+ conversation_id : str | None ,
10941118 ) -> SingleStepResult :
10951119 # Ensure we run the hooks before anything else
10961120 if should_run_agent_start_hooks :
@@ -1124,6 +1148,7 @@ async def _run_single_turn(
11241148 run_config ,
11251149 tool_use_tracker ,
11261150 previous_response_id ,
1151+ conversation_id ,
11271152 prompt_config ,
11281153 )
11291154
@@ -1318,6 +1343,7 @@ async def _get_new_response(
13181343 run_config : RunConfig ,
13191344 tool_use_tracker : AgentToolUseTracker ,
13201345 previous_response_id : str | None ,
1346+ conversation_id : str | None ,
13211347 prompt_config : ResponsePromptParam | None ,
13221348 ) -> ModelResponse :
13231349 # Allow user to modify model input right before the call, if configured
@@ -1352,6 +1378,7 @@ async def _get_new_response(
13521378 run_config .tracing_disabled , run_config .trace_include_sensitive_data
13531379 ),
13541380 previous_response_id = previous_response_id ,
1381+ conversation_id = conversation_id ,
13551382 prompt = prompt_config ,
13561383 )
13571384 # If the agent has hooks, we need to call them after the LLM call
0 commit comments