fix(anthropic): preserve web_fetch_tool_result in multi-turn conversations#18142
Merged
2 commits merged intoJan 12, 2026
Merged
fix(anthropic): preserve web_fetch_tool_result in multi-turn conversations#181422 commits merged into
2 commits merged into
Conversation
…tions Fixes BerriAI#18137 Similar to the fix for web_search_tool_result (BerriAI#17746, BerriAI#17798), this PR preserves web_fetch_tool_result blocks in multi-turn conversations. Changes: - Add handling for web_fetch_tool_result in transformation.py (non-streaming) - Add capture of web_fetch_tool_result in handler.py (streaming) - Fix streaming tool arguments bug where empty input {} was prepended to actual arguments by using empty string instead of str({}) - Add unit tests for web_fetch_tool_result handling
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Collaborator
|
@Chesars Can you fix the conflict |
Resolve conflict in handler.py arguments initialization:
- Use upstream's simpler arguments="" approach
- Both versions fix the same bug (preventing '{}' prepending)
- Upstream solution is cleaner and already tested
Preserves PR's unique contributions:
- web_fetch_tool_result support in handler.py (streaming)
- web_fetch_tool_result support in transformation.py (non-streaming)
- Tests for web_fetch_tool_result functionality
Contributor
Author
@Sameerlite Fixed 👍 |
This pull request was closed.
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.
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