Commit b2b70a7
committed
fix: harden JSON misformat handling to prevent infinite loops and crashes
Circuit breaker now covers BOTH failure modes:
- Case A: complete parse failure (tool_request is None)
- Case B: parseable-but-invalid JSON (RepairableException from validation)
Previously, Case B bypassed the consecutive_misformat counter entirely
because RepairableException was swallowed by _50_handle_repairable_exception
extension, allowing the agent to loop forever on models producing JSON
without required tool_name/tool_args fields.
Changes:
- agent.py: Wrap validate_tool_request in try/except RepairableException
inside process_tools; increment counter for Case B; move counter reset
to after validation passes (not after tool execution)
- prompts/fw.msg_misformat.md: Add attempt countdown, remove contradictory
code-fence example, compress to single-line JSON example
- tests/test_misformat_circuit_breaker.py: 73 tests covering extraction,
validation, circuit breaker (both cases), and end-to-end pipeline
Workaround: Models producing frequent misformats (especially thinking/reasoning
models like MiniMax M2.5) can be improved by adding response_format to the
Chat model additional parameters in Agent Zero settings:
response_format={"type": "json_object"}
This forces JSON output at the token generation level. Confirmed supported
on OpenRouter for MiniMax M2.5, DeepSeek V3, Gemini 2.5 Flash, Grok 4.1.1 parent 506d723 commit b2b70a7
4 files changed
Lines changed: 625 additions & 16 deletions
File tree
- helpers
- prompts
- tests
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
334 | 334 | | |
335 | 335 | | |
336 | 336 | | |
| 337 | + | |
337 | 338 | | |
338 | 339 | | |
339 | 340 | | |
| |||
844 | 845 | | |
845 | 846 | | |
846 | 847 | | |
847 | | - | |
848 | | - | |
| 848 | + | |
| 849 | + | |
| 850 | + | |
| 851 | + | |
| 852 | + | |
| 853 | + | |
| 854 | + | |
| 855 | + | |
| 856 | + | |
| 857 | + | |
| 858 | + | |
| 859 | + | |
| 860 | + | |
| 861 | + | |
849 | 862 | | |
850 | 863 | | |
| 864 | + | |
| 865 | + | |
| 866 | + | |
| 867 | + | |
| 868 | + | |
851 | 869 | | |
852 | 870 | | |
853 | 871 | | |
| |||
933 | 951 | | |
934 | 952 | | |
935 | 953 | | |
936 | | - | |
| 954 | + | |
| 955 | + | |
| 956 | + | |
| 957 | + | |
| 958 | + | |
| 959 | + | |
937 | 960 | | |
938 | 961 | | |
939 | 962 | | |
940 | 963 | | |
941 | | - | |
| 964 | + | |
942 | 965 | | |
| 966 | + | |
| 967 | + | |
| 968 | + | |
| 969 | + | |
| 970 | + | |
943 | 971 | | |
944 | 972 | | |
945 | 973 | | |
| 974 | + | |
| 975 | + | |
946 | 976 | | |
947 | | - | |
| 977 | + | |
948 | 978 | | |
949 | | - | |
| 979 | + | |
950 | 980 | | |
951 | | - | |
| 981 | + | |
952 | 982 | | |
953 | 983 | | |
954 | 984 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
28 | | - | |
29 | | - | |
30 | | - | |
31 | | - | |
32 | | - | |
33 | | - | |
34 | | - | |
35 | | - | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
36 | 54 | | |
37 | 55 | | |
38 | 56 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
0 commit comments