fix(litellm): generate fallback ID for null tool_call IDs#1843
Closed
giulio-leone wants to merge 1 commit intostrands-agents:mainfrom
Closed
fix(litellm): generate fallback ID for null tool_call IDs#1843giulio-leone wants to merge 1 commit intostrands-agents:mainfrom
giulio-leone wants to merge 1 commit intostrands-agents:mainfrom
Conversation
Some LiteLLM proxy backends return tool_calls with id=None, causing downstream failures when the event loop tries to match tool results back to tool_call IDs. Generate a UUID-based fallback ID (tooluse_<hex>) when the tool_call ID is None, matching the format used elsewhere in the codebase. Fixes strands-agents#1259 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Author
|
Closing to reduce PR volume. Happy to resubmit individually if the team finds this fix useful. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Bug
When using LiteLLM with certain proxy backends, tool_calls are returned with
id: null. This causes downstream failures in the event loop when it tries to match tool results back to their originating tool_call IDs.Reported in: #1259
Root cause
_process_tool_calls()passestool_deltas[0]directly toformat_chunk(), which readsevent["data"].idto settoolUseId. When the proxy returnsnullfor the ID,toolUseIdbecomesNone, breaking tool result matching.Fix
Before emitting the
content_startevent, check if the first tool delta'sidisNoneand generate a UUID-based fallback (tooluse_<hex>), matching the ID format used elsewhere in the codebase.Testing
test_stream_non_streaming_null_tool_call_id: creates a tool_call withid=None, verifies the emitted event has a non-nulltoolUseIdstarting withtooluse_Fixes #1259