@@ -222,7 +222,7 @@ async def _execute_rollout(
222222 current_observation = user_message .content if user_message .content else ""
223223
224224 user_prompt = envs .format_user_prompt (rollout_idx , current_observation )
225- conversation_history = [
225+ trajectory . conversation_history = [
226226 {"role" : "system" , "content" : system_prompt },
227227 {"role" : "user" , "content" : user_prompt },
228228 ]
@@ -242,7 +242,7 @@ async def _execute_rollout(
242242
243243 if user_simulator and user_simulator_state :
244244 # Get user simulator messages and find the last assistant message
245- user_simulator_messages = self ._get_user_simulator_messages (conversation_history )
245+ user_simulator_messages = self ._get_user_simulator_messages (trajectory . conversation_history )
246246
247247 # Last message was agent, simulated user response
248248 if user_simulator_messages and isinstance (user_simulator_messages [- 1 ], AssistantMessage ):
@@ -253,7 +253,7 @@ async def _execute_rollout(
253253 user_content = user_message .content if user_message .content else ""
254254
255255 user_prompt = envs .format_user_prompt (rollout_idx , user_content )
256- conversation_history .append ({"role" : "user" , "content" : user_prompt })
256+ trajectory . conversation_history .append ({"role" : "user" , "content" : user_prompt })
257257
258258 # Check if user simulator signaled termination
259259 if UserSimulator .is_stop (user_message ):
@@ -263,7 +263,7 @@ async def _execute_rollout(
263263 # In each turn: keep looping until assistant is ready to provide final response
264264 while not turn_completed and not trajectory .terminated :
265265 tool_calls , usage_stats , finish_reason = await policy (
266- tool_schema , rollout_idx , conversation_history
266+ tool_schema , rollout_idx , trajectory . conversation_history
267267 )
268268
269269 # calc llm usage stats happened in this turn if there is aany
@@ -295,7 +295,7 @@ async def _execute_rollout(
295295 rollout_idx ,
296296 tool_call ,
297297 tool_response ,
298- conversation_history ,
298+ trajectory . conversation_history ,
299299 reward ,
300300 env_end ,
301301 info ,
@@ -326,12 +326,14 @@ async def _execute_rollout(
326326 "num_tool_calls" : 1 ,
327327 }
328328 print (f"🔍 control_plane_step: { control_plane_step } " )
329- conversation_history [- 1 ]["control_plane_step" ] = control_plane_step
329+ trajectory . conversation_history [- 1 ]["control_plane_step" ] = control_plane_step
330330 trajectory .control_plane_steps .append (control_plane_step )
331331
332332 # Log conversation state for playback if in recording mode
333333 if recording_mode :
334- policy .log_conversation_state_for_playback (rollout_idx , step - 1 , conversation_history )
334+ policy .log_conversation_state_for_playback (
335+ rollout_idx , step - 1 , trajectory .conversation_history
336+ )
335337
336338 if env_end :
337339 # if the env marks the end of the rollout, break the tool call loop
@@ -365,17 +367,21 @@ async def _execute_rollout(
365367 "tool_calls" : tool_calls_summary ,
366368 "num_tool_calls" : len (tool_calls ),
367369 }
368- conversation_history [- 1 ]["control_plane_step" ] = control_plane_step
370+ trajectory . conversation_history [- 1 ]["control_plane_step" ] = control_plane_step
369371 trajectory .control_plane_steps .append (control_plane_step )
370372
371373 # Log conversation state for playback if in recording mode
372374 if recording_mode :
373- policy .log_conversation_state_for_playback (rollout_idx , step - 1 , conversation_history )
375+ policy .log_conversation_state_for_playback (
376+ rollout_idx , step - 1 , trajectory .conversation_history
377+ )
374378
375379 # if the env marks end, update control plane summary and do one last policy call, then break the agent loop
376380 # this is to ensure each turn ends with an assistant message, which will align with the actual agentic llm behavior
377381 if env_end :
378- _ , usage_stats , finish_reason = await policy (tool_schema , rollout_idx , conversation_history )
382+ _ , usage_stats , finish_reason = await policy (
383+ tool_schema , rollout_idx , trajectory .conversation_history
384+ )
379385 if usage_stats :
380386 trajectory .usage ["prompt_tokens" ] += usage_stats .prompt_tokens
381387 trajectory .usage ["completion_tokens" ] += usage_stats .completion_tokens
@@ -393,10 +399,10 @@ async def _execute_rollout(
393399
394400 # Log final OpenAI conversation for terminated trajectories only
395401 if openai_logger :
396- if conversation_history and len (conversation_history ) > 0 :
402+ if trajectory . conversation_history and len (trajectory . conversation_history ) > 0 :
397403 openai_logger (
398404 {
399- "messages" : conversation_history ,
405+ "messages" : trajectory . conversation_history ,
400406 "metadata" : {
401407 "session_id" : session .session_id ,
402408 "seed" : session .seed ,
@@ -422,8 +428,6 @@ async def _execute_rollout(
422428 if not trajectory .termination_reason and step >= steps :
423429 trajectory .termination_reason = TerminationReason .MAX_STEPS
424430
425- trajectory .conversation_history = conversation_history
426-
427431 # Add termination_reason to the final control_plane_step
428432 for msg in reversed (trajectory .conversation_history ):
429433 if msg .get ("control_plane_step" ):
0 commit comments