Skip to content

refactor: websearch interception to use async_execute_tool_calls hook#22865

Draft
mpcusack-altos wants to merge 2 commits intoBerriAI:mainfrom
mpcusack-altos:mcusack/websearch-uses-tool-call-hook
Draft

refactor: websearch interception to use async_execute_tool_calls hook#22865
mpcusack-altos wants to merge 2 commits intoBerriAI:mainfrom
mpcusack-altos:mcusack/websearch-uses-tool-call-hook

Conversation

@mpcusack-altos
Copy link
Copy Markdown
Contributor

Relevant issues

Replaces #20488 (part 2 of 2)

⚠️ Depends on #22864 — merge that first, then rebase this PR.

Summary

Simplifies WebSearchInterceptionLogger by replacing the old two-step agentic loop pattern with the new async_execute_tool_calls hook from #22864.

The handler now only needs to:

  1. Detect websearch tool_use blocks in the response
  2. Execute searches and return ToolCallResult objects

The framework handles message construction, thinking block preservation, and follow-up requests.

  • Reduces handler from ~800 lines to ~200 lines
  • Removes duplicated thinking block extraction logic
  • Legacy async_should_run_agentic_loop stubs kept for backward compat

Pre-Submission checklist

  • I have Added testing in the tests/test_litellm/ directory
  • My PR passes all unit tests on make test-unit (38 passed, 2 skipped)
  • My PR's scope is as isolated as possible, it only solves 1 specific problem
  • I have requested a Greptile review

Test plan

  • test_async_execute_tool_calls_positive_case — verifies tool execution via new hook
  • test_async_execute_tool_calls_with_thinking_blocks — verifies thinking blocks with new hook
  • test_async_pre_call_deployment_hook_* — provider detection via litellm_params
  • test_websearch_interception_thinking.py — transformation layer thinking tests
  • test_websearch_chat_completion.py — chat completion format tests

🤖 Generated with Claude Code

@vercel
Copy link
Copy Markdown

vercel bot commented Mar 5, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
litellm Ready Ready Preview, Comment Mar 5, 2026 5:09am

Request Review

mpcusack-altos and others added 2 commits March 4, 2026 21:07
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant