AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.
fix: add empty choices guard in extract_openai_tool_calls() (#12540)
## Summary `extract_openai_tool_calls()` in `llm.py` crashes with `IndexError` when the LLM provider returns a response with an empty `choices` list. ### Changes 🏗️ - Added a guard check `if not response.choices: return None` before accessing `response.choices[0]` - This is consistent with the function's existing pattern of returning `None` when no tool calls are found ### Bug Details When an LLM provider returns a response with an empty choices list (e.g., due to content filtering, rate limiting, or API errors), `response.choices[0]` raises `IndexError`. This can crash the entire agent execution pipeline. ### Checklist 📋 #### For code changes: - [x] I have clearly listed my changes in the PR description - [x] I have made a test plan - [x] I have tested my changes according to the test plan: - Verified that the function returns `None` when `response.choices` is empty - Verified existing behavior is unchanged when `response.choices` is non-empty --------- Co-authored-by: goingforstudying-ctrl <[email protected]> Co-authored-by: Claude Opus 4.6 <[email protected]> Co-authored-by: Zamil Majdy <[email protected]>
G
goingforstudying-ctrl committed
c410be890e33577c47b49ecc8d7d0614375b2cc2
Parent: 37d9863
Committed by GitHub <[email protected]>
on 3/31/2026, 1:10:27 PM