@@ -3405,7 +3405,11 @@ def _execute_tool_with_context(self, function_name, arguments, state):
34053405 # Apply default limit even without context management
34063406 # This prevents runaway tool outputs from causing overflow
34073407 if len (result_str ) > DEFAULT_TOOL_OUTPUT_LIMIT :
3408- truncated = result_str [:DEFAULT_TOOL_OUTPUT_LIMIT ] + "...[output truncated]"
3408+ # Use smart truncation format that judge recognizes as OK
3409+ tail_size = min (DEFAULT_TOOL_OUTPUT_LIMIT // 5 , 2000 )
3410+ head = result_str [:DEFAULT_TOOL_OUTPUT_LIMIT - tail_size ]
3411+ tail = result_str [- tail_size :] if tail_size > 0 else ""
3412+ truncated = f"{ head } \n ...[{ len (result_str ):,} chars, showing first/last portions]...\n { tail } "
34093413 else :
34103414 truncated = result_str
34113415
@@ -3499,21 +3503,35 @@ def _truncate_dict_fields(self, data: dict, tool_name: str, max_field_chars: int
34993503 result = {}
35003504 for key , value in data .items ():
35013505 if isinstance (value , str ) and len (value ) > max_field_chars :
3502- # Truncate large string fields
3503- result [key ] = value [:max_field_chars ] + "...[truncated]"
3504- logging .debug (f"Truncated field '{ key } ' from { len (value )} to { max_field_chars } chars" )
3506+ # Smart truncate large string fields preserving head and tail
3507+ head_limit = int (max_field_chars * 0.8 )
3508+ tail_limit = int (max_field_chars * 0.15 )
3509+ head = value [:head_limit ]
3510+ tail = value [- tail_limit :] if tail_limit > 0 else ""
3511+ result [key ] = f"{ head } \n ...[{ len (value ):,} chars, showing first/last portions]...\n { tail } "
3512+ logging .debug (f"Smart truncated field '{ key } ' from { len (value )} to ~{ max_field_chars } chars" )
35053513 elif isinstance (value , dict ):
35063514 result [key ] = self ._truncate_dict_fields (value , tool_name , max_field_chars )
35073515 elif isinstance (value , list ):
35083516 result [key ] = [
35093517 self ._truncate_dict_fields (item , tool_name , max_field_chars ) if isinstance (item , dict )
3510- else (item [: max_field_chars ] + "...[truncated]" if isinstance (item , str ) and len (item ) > max_field_chars else item )
3518+ else (self . _smart_truncate_str ( item , max_field_chars ) if isinstance (item , str ) and len (item ) > max_field_chars else item )
35113519 for item in value
35123520 ]
35133521 else :
35143522 result [key ] = value
35153523 return result
35163524
3525+ def _smart_truncate_str (self , text : str , max_chars : int ) -> str :
3526+ """Smart truncate a string preserving head and tail."""
3527+ if len (text ) <= max_chars :
3528+ return text
3529+ head_limit = int (max_chars * 0.8 )
3530+ tail_limit = int (max_chars * 0.15 )
3531+ head = text [:head_limit ]
3532+ tail = text [- tail_limit :] if tail_limit > 0 else ""
3533+ return f"{ head } \n ...[{ len (text ):,} chars, showing first/last portions]...\n { tail } "
3534+
35173535 def _execute_tool_impl (self , function_name , arguments ):
35183536 """Internal tool execution implementation."""
35193537
@@ -3906,7 +3924,7 @@ def _chat_completion(self, messages, temperature=1.0, tools=None, stream=True, r
39063924 execute_tool_fn = self .execute_tool ,
39073925 agent_name = self .name ,
39083926 agent_role = self .role ,
3909- agent_tools = [t . __name__ for t in self .tools ] if self .tools else None ,
3927+ agent_tools = [getattr ( t , ' __name__' , str ( t )) for t in self .tools ] if self .tools else None ,
39103928 task_name = task_name ,
39113929 task_description = task_description ,
39123930 task_id = task_id ,
@@ -3933,7 +3951,7 @@ def _chat_completion(self, messages, temperature=1.0, tools=None, stream=True, r
39333951 execute_tool_fn = self .execute_tool ,
39343952 agent_name = self .name ,
39353953 agent_role = self .role ,
3936- agent_tools = [t . __name__ for t in self .tools ] if self .tools else None ,
3954+ agent_tools = [getattr ( t , ' __name__' , str ( t )) for t in self .tools ] if self .tools else None ,
39373955 task_name = task_name ,
39383956 task_description = task_description ,
39393957 task_id = task_id ,
@@ -3952,7 +3970,7 @@ def _chat_completion(self, messages, temperature=1.0, tools=None, stream=True, r
39523970 execute_tool_fn = self .execute_tool ,
39533971 agent_name = self .name ,
39543972 agent_role = self .role ,
3955- agent_tools = [t . __name__ for t in self .tools ] if self .tools else None ,
3973+ agent_tools = [getattr ( t , ' __name__' , str ( t )) for t in self .tools ] if self .tools else None ,
39563974 task_name = task_name ,
39573975 task_description = task_description ,
39583976 task_id = task_id ,
@@ -4091,7 +4109,7 @@ def _execute_callback_and_display(self, prompt: str, response: str, generation_t
40914109 generation_time = generation_time ,
40924110 agent_name = self .name ,
40934111 agent_role = self .role ,
4094- agent_tools = [t . __name__ for t in self .tools ] if self .tools else None ,
4112+ agent_tools = [getattr ( t , ' __name__' , str ( t )) for t in self .tools ] if self .tools else None ,
40954113 task_name = task_name ,
40964114 task_description = task_description ,
40974115 task_id = task_id
@@ -4103,7 +4121,7 @@ def _execute_callback_and_display(self, prompt: str, response: str, generation_t
41034121 generation_time = generation_time , console = self .console ,
41044122 agent_name = self .name ,
41054123 agent_role = self .role ,
4106- agent_tools = [t . __name__ for t in self .tools ] if self .tools else None ,
4124+ agent_tools = [getattr ( t , ' __name__' , str ( t )) for t in self .tools ] if self .tools else None ,
41074125 task_name = None , # Not available in this context
41084126 task_description = None , # Not available in this context
41094127 task_id = None ) # Not available in this context
0 commit comments