Commit b7d2ebb
committed
Fix: Enhance tool calling to support multi-step orchestration
## Problem
Meta Llama and other models were stuck in infinite tool calling loops
after receiving tool results. The previous fix set tool_choice="none"
unconditionally after any tool result, which prevented legitimate
multi-step tool orchestration patterns.
## Solution
Implemented intelligent tool_choice management that:
1. Allows models to continue calling tools for multi-step workflows
2. Prevents infinite loops via max_sequential_tool_calls limit (default: 8)
3. Detects infinite loops by identifying repeated tool calls with identical arguments
## Changes
- Added max_sequential_tool_calls parameter to OCIGenAIBase (default: 8)
- Enhanced GenericProvider.messages_to_oci_params() with _should_allow_more_tool_calls()
- Loop detection checks for same tool called with same args in succession
- Safety limit prevents runaway tool calling beyond configured maximum
## Backward Compatibility
✅ Fully backward compatible - no breaking changes
- New parameter is optional with sensible default (8)
- Existing code continues to work without modifications
- Previous infinite loop fix remains active as fallback
## Technical Details
The fix passes max_sequential_tool_calls from ChatOCIGenAI to Provider
via kwargs, allowing the provider to determine whether to set
tool_choice="none" (force stop) or tool_choice="auto" (allow continuation).1 parent 5ce1280 commit b7d2ebb
File tree
2 files changed
+92
-10
lines changed- libs/oci/langchain_oci
- chat_models
- llms
2 files changed
+92
-10
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
367 | 367 | | |
368 | 368 | | |
369 | 369 | | |
370 | | - | |
371 | | - | |
372 | | - | |
| 370 | + | |
373 | 371 | | |
374 | 372 | | |
375 | 373 | | |
| |||
381 | 379 | | |
382 | 380 | | |
383 | 381 | | |
384 | | - | |
385 | | - | |
386 | | - | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
387 | 393 | | |
388 | 394 | | |
389 | 395 | | |
| |||
713 | 719 | | |
714 | 720 | | |
715 | 721 | | |
716 | | - | |
717 | | - | |
| 722 | + | |
| 723 | + | |
718 | 724 | | |
719 | 725 | | |
720 | 726 | | |
| |||
736 | 742 | | |
737 | 743 | | |
738 | 744 | | |
739 | | - | |
| 745 | + | |
740 | 746 | | |
741 | 747 | | |
742 | 748 | | |
743 | 749 | | |
| 750 | + | |
| 751 | + | |
| 752 | + | |
| 753 | + | |
| 754 | + | |
| 755 | + | |
| 756 | + | |
| 757 | + | |
| 758 | + | |
| 759 | + | |
| 760 | + | |
| 761 | + | |
| 762 | + | |
| 763 | + | |
| 764 | + | |
| 765 | + | |
| 766 | + | |
| 767 | + | |
| 768 | + | |
| 769 | + | |
| 770 | + | |
| 771 | + | |
| 772 | + | |
| 773 | + | |
| 774 | + | |
| 775 | + | |
| 776 | + | |
| 777 | + | |
| 778 | + | |
| 779 | + | |
| 780 | + | |
| 781 | + | |
| 782 | + | |
| 783 | + | |
| 784 | + | |
| 785 | + | |
| 786 | + | |
| 787 | + | |
| 788 | + | |
| 789 | + | |
| 790 | + | |
| 791 | + | |
| 792 | + | |
| 793 | + | |
| 794 | + | |
| 795 | + | |
| 796 | + | |
| 797 | + | |
| 798 | + | |
| 799 | + | |
| 800 | + | |
| 801 | + | |
| 802 | + | |
| 803 | + | |
| 804 | + | |
| 805 | + | |
| 806 | + | |
| 807 | + | |
| 808 | + | |
| 809 | + | |
| 810 | + | |
| 811 | + | |
| 812 | + | |
| 813 | + | |
| 814 | + | |
| 815 | + | |
| 816 | + | |
744 | 817 | | |
745 | 818 | | |
746 | 819 | | |
| |||
934 | 1007 | | |
935 | 1008 | | |
936 | 1009 | | |
| 1010 | + | |
937 | 1011 | | |
938 | 1012 | | |
939 | 1013 | | |
| |||
1050 | 1124 | | |
1051 | 1125 | | |
1052 | 1126 | | |
1053 | | - | |
| 1127 | + | |
| 1128 | + | |
| 1129 | + | |
| 1130 | + | |
| 1131 | + | |
1054 | 1132 | | |
1055 | 1133 | | |
1056 | 1134 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
116 | 116 | | |
117 | 117 | | |
118 | 118 | | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
119 | 123 | | |
120 | 124 | | |
121 | 125 | | |
| |||
0 commit comments