@@ -304,7 +304,9 @@ def _format_messages_for_debug(
304304
305305 return formatted
306306
307- def _truncate_content (self , content , max_length : int = 200 ) -> str :
307+ def _truncate_content (
308+ self , content , max_length : int = 200
309+ ) -> str | list [dict [str , Any ]]:
308310 """Truncate content to max_length with ellipsis.
309311
310312 Args:
@@ -318,22 +320,19 @@ def _truncate_content(self, content, max_length: int = 200) -> str:
318320 text = content
319321 elif isinstance (content , list ):
320322 # Extract text from content blocks
321- text_parts = []
322323 for item in content :
323324 if isinstance (item , dict ):
324325 if item .get ("type" ) == "text" :
325- text_parts .append (item .get ("text" , "" ))
326- elif item .get ("type" ) == "tool_use" :
327- text_parts .append (f"[tool:{ item .get ('name' , 'unknown' )} ]" )
328- elif item .get ("type" ) == "tool_result" :
329- result = item .get ("content" , "" )
330- if isinstance (result , str ):
331- text_parts .append (f"[result:{ result [:50 ]} ...]" )
332- else :
333- text_parts .append ("[result:...]" )
334- elif isinstance (item , str ):
335- text_parts .append (item )
336- text = " | " .join (text_parts )
326+ item ["text" ] = self ._truncate_content (item .get ("text" , "" ))
327+ elif item .get ("type" ) == "thinking" :
328+ item ["thinking" ] = self ._truncate_content (
329+ f"[tool:{ item .get ('thinking' , '' )} ]"
330+ )
331+ elif item .get ("type" ) == "image_url" :
332+ item ["image_url" ] = self ._truncate_content (
333+ item .get ("image_url" , {}).get ("url" , "" )
334+ )
335+ return content
337336 else :
338337 text = str (content )
339338
0 commit comments