refactor: websearch interception to use async_execute_tool_calls hook#22865
Draft
mpcusack-altos wants to merge 2 commits intoBerriAI:mainfrom
Draft
refactor: websearch interception to use async_execute_tool_calls hook#22865mpcusack-altos wants to merge 2 commits intoBerriAI:mainfrom
mpcusack-altos wants to merge 2 commits intoBerriAI:mainfrom
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Adds a simplified tool execution hook pattern to the LiteLLM framework: - ToolCallResult NamedTuple in custom_logger.py for structured tool results - async_execute_tool_calls() method on CustomLogger base class - _call_tool_execution_hooks() in BaseLLMHTTPHandler that aggregates results from all callbacks, constructs follow-up messages (preserving thinking blocks), and makes the follow-up API request - _filter_handled_tool_calls() to allow multiple callbacks to handle different tool calls from the same response This is a framework-level change that moves agentic loop orchestration into the HTTP handler, so individual CustomLogger implementations only need to execute tool calls and return results. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Simplifies WebSearchInterceptionLogger by removing the old two-step agentic loop pattern (async_should_run_agentic_loop + async_run_agentic_loop) and replacing it with the new async_execute_tool_calls hook. The handler now only needs to: 1. Detect websearch tool_use blocks in the response 2. Execute searches and return ToolCallResult objects The framework (BaseLLMHTTPHandler._call_tool_execution_hooks) handles: - Message construction (assistant + tool_result messages) - Thinking block preservation - Follow-up API requests This reduces the handler from ~800 lines to ~200 lines. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
9647125 to
99ef4ea
Compare
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
Replaces #20488 (part 2 of 2)
Summary
Simplifies
WebSearchInterceptionLoggerby replacing the old two-step agentic loop pattern with the newasync_execute_tool_callshook from #22864.The handler now only needs to:
tool_useblocks in the responseToolCallResultobjectsThe framework handles message construction, thinking block preservation, and follow-up requests.
async_should_run_agentic_loopstubs kept for backward compatPre-Submission checklist
tests/test_litellm/directorymake test-unit(38 passed, 2 skipped)Test plan
test_async_execute_tool_calls_positive_case— verifies tool execution via new hooktest_async_execute_tool_calls_with_thinking_blocks— verifies thinking blocks with new hooktest_async_pre_call_deployment_hook_*— provider detection vialitellm_paramstest_websearch_interception_thinking.py— transformation layer thinking teststest_websearch_chat_completion.py— chat completion format tests🤖 Generated with Claude Code