fix: normalize an already-empty tools list to None under allowed_tool_types

Greptile flagged that filter_tools_by_allowed_types passed an incoming
tools: [] through unchanged, while the whole point of the None return is
that some strict providers reject empty tool arrays. Empty in -> None out.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
Fenghuang 2026-07-22 15:06:53 +09:00
parent 23f4b10017
commit c755a81b5e
2 changed files with 6 additions and 4 deletions

View file

@ -7447,11 +7447,12 @@ def filter_tools_by_allowed_types(
allowed_tool_types: ["function"]
A tool without a ``type`` key is treated as ``function`` (matching OpenAI
defaults). Returns None when no tools survive so an empty ``tools: []``
array is not sent upstream (some providers reject that too).
defaults). Returns None when no tools survive — including when the incoming
list is already empty — so an empty ``tools: []`` array is never sent
upstream (some providers reject that too).
"""
if not tools:
return tools
return None
filtered = [
t
for t in tools

View file

@ -4908,7 +4908,8 @@ def test_filter_tools_by_allowed_types_wider_allowlist_and_empty_result() -> Non
)
assert filter_tools_by_allowed_types(tools=None, allowed_tool_types=["function"]) is None
assert filter_tools_by_allowed_types(tools=[], allowed_tool_types=["function"]) == []
# an already-empty list is normalized to None too — some providers reject tools: []
assert filter_tools_by_allowed_types(tools=[], allowed_tool_types=["function"]) is None
def test_reconcile_tool_choice_after_tool_filtering() -> None: