fix: remove incorrect tool_calls conversion logic

Systematic debugging revealed the root cause of Pydantic validation errors:
- DeepSeek correctly returns tool_calls.arguments as JSON strings
- My wrapper was incorrectly converting strings to dicts
- This caused LangChain's parse_tool_call() to fail (json.loads(dict) error)
- Failure created invalid_tool_calls with dict args (should be string)
- Result: Pydantic validation error on invalid_tool_calls

Solution: Remove all conversion logic. DeepSeek format is already correct.

ToolCallArgsParsingWrapper now acts as a simple passthrough proxy.
Trading session completes successfully with no errors.

Fixes the systematic-debugging investigation that identified the
issue was in our fix attempt, not in the original API response.

Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2025-11-05 21:18:54 -05:00
parent 0c6de5b74b
commit 0641ce554a
2 changed files with 19 additions and 82 deletions

View File

@@ -10,10 +10,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [0.4.1] - 2025-11-05
### Fixed
- Fixed Pydantic validation errors for both `tool_calls` and `invalid_tool_calls` when using DeepSeek and other AI providers:
- `tool_calls.args`: Converts JSON strings to dictionaries (for successful tool calls)
- `invalid_tool_calls.args`: Converts dictionaries to JSON strings (for failed tool calls)
- Added `ToolCallArgsParsingWrapper` that monkey-patches ChatOpenAI's `_create_chat_result` method to normalize arguments before AIMessage construction.
- Resolved Pydantic validation errors when using DeepSeek Chat v3.1 through systematic debugging
- Root cause: Initial implementation incorrectly converted tool_calls arguments from strings to dictionaries, causing LangChain's `parse_tool_call()` to fail and create invalid_tool_calls with wrong format
- Solution: Removed unnecessary conversion logic - DeepSeek already returns arguments in correct format (JSON strings)
- `ToolCallArgsParsingWrapper` now acts as a simple passthrough proxy (kept for backward compatibility)
## [0.4.0] - 2025-11-05