Fix GPT-5 tool calling format incompatibility

GPT-5 wraps tool arguments in an array format like:
[{"arg": "value"}, []]

while GPT-4 uses a flat dict format:
{"arg": "value"}

This commit adds a _coerce_args_dict() helper method that normalizes
both formats by unwrapping the array when the first element is a dict
and all trailing elements are empty.

The fix is applied across all parsing attempts (JSON, Python literal,
JSON5, and repaired JSON) to ensure consistent behavior.

Tests added to verify:
- GPT-5 array-wrapped format is correctly normalized
- GPT-4 flat dict format continues to work unchanged
- Invalid list formats are properly rejected
- Complex nested arguments work with both formats

Fixes #3889

Co-Authored-By: João <joao@crewai.com>
This commit is contained in:
Devin AI
2025-11-11 12:23:39 +00:00
parent 01f0111d52
commit 1b7f44dc34
3 changed files with 4311 additions and 4029 deletions

8110
uv.lock generated

File diff suppressed because it is too large Load Diff