fix(llm): handle tool execution exceptions in LiteLLMProvider #809
+116
−6
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Fixes a critical bug where exceptions raised during tool execution in
LiteLLMProvider.complete_with_tools()would crash the entire LLM generation loop, causing loss of conversation context and preventing graceful error recovery.Problem
The
complete_with_tools()method only caughtJSONDecodeErrorwhen parsing tool arguments, but did not handle exceptions raised during actual tool execution. When a tool raised an exception:Solution
tool_executor(tool_use)calls in comprehensive try/except blocksToolResulterrors with error detailsToolResultChanges
core/framework/llm/litellm.py: Added exception handling and result normalization incomplete_with_tools()core/tests/test_litellm_provider.py: Added regression testtest_complete_with_tools_tool_exception_is_capturedCHANGELOG.md: Documented the fixTesting
All 23 tests pass, including the new regression test that verifies:
ToolResultwithis_error=Trueuv run pytest tests/test_litellm_provider.py -v
23 passed