Compare commits

..

1 Commits

Author SHA1 Message Date
d199b093c1 debug: patch parse_tool_call to identify source of string args
Added global monkey-patch of langchain_core's parse_tool_call to log
the type of 'args' it returns. This will definitively show whether:
1. parse_tool_call is returning string args (bug in langchain_core)
2. Something else is modifying the result after parse_tool_call returns
3. AIMessage construction is getting tool_calls from a different source

This is the critical diagnostic to find the root cause.
2025-11-06 17:42:33 -05:00

View File

@@ -32,6 +32,23 @@ class ToolCallArgsParsingWrapper:
# Model doesn't have this method (e.g., MockChatModel), skip patching
return
# CRITICAL: Also patch parse_tool_call to see what it's returning
from langchain_core.output_parsers import openai_tools
original_parse_tool_call = openai_tools.parse_tool_call
def patched_parse_tool_call(raw_tool_call, *, partial=False, strict=False, return_id=True):
"""Patched parse_tool_call to log what it returns"""
result = original_parse_tool_call(raw_tool_call, partial=partial, strict=strict, return_id=return_id)
if result:
args_type = type(result.get('args', None)).__name__
print(f"[DIAGNOSTIC] parse_tool_call returned: args type = {args_type}")
if args_type == 'str':
print(f"[DIAGNOSTIC] ⚠️ BUG FOUND! parse_tool_call returned STRING args: {result['args']}")
return result
# Replace globally
openai_tools.parse_tool_call = patched_parse_tool_call
original_create_chat_result = self.wrapped_model._create_chat_result
@wraps(original_create_chat_result)