From 483621f9b7cdf9c4c4450f684606eebb1d1d8d79 Mon Sep 17 00:00:00 2001 From: Bill Date: Thu, 6 Nov 2025 12:10:29 -0500 Subject: [PATCH] debug: add comprehensive diagnostics to trace error location Adding detailed logging to: 1. Show call stack when _create_chat_result is called 2. Verify our wrapper is being executed 3. Check result after _convert_dict_to_message processes tool_calls 4. Identify exact point where string args become the problem This will help determine if error occurs during response processing or if there's a separate code path bypassing our wrapper. --- agent/chat_model_wrapper.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/agent/chat_model_wrapper.py b/agent/chat_model_wrapper.py index ce878ab..fdabdbe 100644 --- a/agent/chat_model_wrapper.py +++ b/agent/chat_model_wrapper.py @@ -37,9 +37,15 @@ class ToolCallArgsParsingWrapper: @wraps(original_create_chat_result) def patched_create_chat_result(response: Any, generation_info: Optional[Dict] = None): """Patched version with diagnostic logging and args parsing""" + import traceback response_dict = response if isinstance(response, dict) else response.model_dump() # DIAGNOSTIC: Log response structure for debugging + print(f"\n[DIAGNOSTIC] _create_chat_result called") + print(f" Response type: {type(response)}") + print(f" Call stack:") + for line in traceback.format_stack()[-5:-1]: # Show last 4 stack frames + print(f" {line.strip()}") print(f"\n[DIAGNOSTIC] Response structure:") print(f" Response keys: {list(response_dict.keys())}") @@ -116,7 +122,18 @@ class ToolCallArgsParsingWrapper: # Keep as-is if serialization fails # Call original method with fixed response - return original_create_chat_result(response_dict, generation_info) + print(f"[DIAGNOSTIC] Calling original_create_chat_result...") + result = original_create_chat_result(response_dict, generation_info) + print(f"[DIAGNOSTIC] original_create_chat_result returned successfully") + print(f"[DIAGNOSTIC] Result type: {type(result)}") + if hasattr(result, 'generations') and result.generations: + gen = result.generations[0] + if hasattr(gen, 'message') and hasattr(gen.message, 'tool_calls'): + print(f"[DIAGNOSTIC] Result has {len(gen.message.tool_calls)} tool_calls") + if gen.message.tool_calls: + tc = gen.message.tool_calls[0] + print(f"[DIAGNOSTIC] tool_calls[0]['args'] type in result: {type(tc['args'])}") + return result # Replace the method self.wrapped_model._create_chat_result = patched_create_chat_result