@@ -74,14 +74,9 @@ async def call_agent(self) -> str:
7474
7575 # Add all tool results to messages (they will be in the same order as tool_calls)
7676 for tool_call , (tool_call_id , content ) in zip (message .tool_calls , tool_results ):
77+ tool_message_content = self ._format_tool_message_content (content )
7778 self .append_message_and_log (
78- Message (
79- role = "tool" ,
80- content = [
81- ChatCompletionContentPartTextParam (text = content .text , type = "text" ) for content in content
82- ],
83- tool_call_id = tool_call_id ,
84- )
79+ Message (role = "tool" , content = tool_message_content , tool_call_id = tool_call_id )
8580 )
8681 return await self .call_agent ()
8782 return message .content
@@ -114,6 +109,18 @@ def _get_content_from_tool_result(self, tool_result: CallToolResult) -> List[Tex
114109 raise NotImplementedError ("Non-text content is not supported yet" )
115110 return tool_result .content
116111
112+ def _format_tool_message_content (
113+ self , content : List [TextContent ]
114+ ) -> Union [str , List [ChatCompletionContentPartTextParam ]]:
115+ """Format tool result content for inclusion in a tool message.
116+
117+ - If a single text item, return plain string per OpenAI semantics.
118+ - If multiple items, return a list of text parts.
119+ """
120+ if len (content ) == 1 and isinstance (content [0 ], TextContent ):
121+ return content [0 ].text
122+ return [ChatCompletionContentPartTextParam (text = c .text , type = "text" ) for c in content ]
123+
117124
118125async def default_agent_rollout_processor (
119126 rows : List [EvaluationRow ], config : RolloutProcessorConfig
0 commit comments