mirror of
https://github.com/Xe138/AI-Trader.git
synced 2026-04-01 17:17:24 -04:00
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.
This commit is contained in:
@@ -32,6 +32,23 @@ class ToolCallArgsParsingWrapper:
|
|||||||
# Model doesn't have this method (e.g., MockChatModel), skip patching
|
# Model doesn't have this method (e.g., MockChatModel), skip patching
|
||||||
return
|
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
|
original_create_chat_result = self.wrapped_model._create_chat_result
|
||||||
|
|
||||||
@wraps(original_create_chat_result)
|
@wraps(original_create_chat_result)
|
||||||
|
|||||||
Reference in New Issue
Block a user