fix(anthropic): preserve web_fetch_tool_result in multi-turn conversations #18142
+188
−2
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.
Relevant issues
Fixes #18137
Pre-Submission checklist
tests/litellm/directorymake test-unitType
🐛 Bug Fix
Changes
Preserve
web_fetch_tool_resultin multi-turn conversations (same fix as #17746 forweb_search).Example
Solution
When Anthropic returns a
web_fetchresponse, it includes both aserver_tool_useblock and aweb_fetch_tool_resultblock. LiteLLM was only preserving theserver_tool_usebut dropping theweb_fetch_tool_result. This fix captures and storesweb_fetch_tool_resultinprovider_specific_fieldsso it can be reconstructed in subsequent turns.Files changed
litellm/llms/anthropic/chat/transformation.py- handleweb_fetch_tool_result(non-streaming)litellm/llms/anthropic/chat/handler.py- captureweb_fetch_tool_result(streaming)tests/test_litellm/llms/anthropic/chat/test_anthropic_chat_handler.py- add 2 unit testsTests
Tests Added
test_web_fetch_tool_result_captured_in_provider_specific_fieldstest_web_fetch_tool_result_no_extra_tool_calls