fix: use admin-configured WEB_SEARCH_RESULT_COUNT as default (#23488)

The built-in search_web tool hardcoded count=5 as the default,
ignoring the admin-configured WEB_SEARCH_RESULT_COUNT setting.
When the LLM did not specify a count, the tool always returned 5
results regardless of admin configuration.

Now the tool defaults to the admin-configured value when the LLM
omits the count parameter, while still capping LLM-requested
values at the admin maximum to prevent abuse.

Closes #23485
This commit is contained in:
Classic298
2026-04-08 13:13:44 -07:00
committed by GitHub
parent 803d833908
commit e7e006e781
+5 -8
View File
@@ -149,7 +149,7 @@ async def calculate_timestamp(
async def search_web( async def search_web(
query: str, query: str,
count: int = 5, count: Optional[int] = None,
__request__: Request = None, __request__: Request = None,
__user__: dict = None, __user__: dict = None,
) -> str: ) -> str:
@@ -158,7 +158,7 @@ async def search_web(
or topics not covered in internal documents. or topics not covered in internal documents.
:param query: The search query to look up :param query: The search query to look up
:param count: Number of results to return (default: 5) :param count: Number of results to return (default: admin-configured value)
:return: JSON with search results containing title, link, and snippet for each result :return: JSON with search results containing title, link, and snippet for each result
""" """
if __request__ is None: if __request__ is None:
@@ -168,12 +168,9 @@ async def search_web(
engine = __request__.app.state.config.WEB_SEARCH_ENGINE engine = __request__.app.state.config.WEB_SEARCH_ENGINE
user = UserModel(**__user__) if __user__ else None user = UserModel(**__user__) if __user__ else None
# Enforce maximum result count from config to prevent abuse configured = __request__.app.state.config.WEB_SEARCH_RESULT_COUNT
count = ( max_count = 5 if configured is None else configured
count count = max(1, min(count, max_count)) if count is not None else max_count
if count < __request__.app.state.config.WEB_SEARCH_RESULT_COUNT
else __request__.app.state.config.WEB_SEARCH_RESULT_COUNT
)
results = await asyncio.to_thread(_search_web, __request__, engine, query, user) results = await asyncio.to_thread(_search_web, __request__, engine, query, user)