From a0a8b86fc8214bf505821efd7e9058d1adb3f22c Mon Sep 17 00:00:00 2001 From: skamenan7 Date: Mon, 7 Jul 2025 15:13:56 -0400 Subject: [PATCH] fix(brave-search): change tool name and standardize response format - Change tool name from 'web_search' to 'web_search_brave' to avoid conflicts with Tavily - Standardize response format to JSON with 'query' and 'top_k' fields for consistency - Remove built_in_type parameter from ToolDef to match Tavily implementation - Return structured dict instead of string from _clean_result_by_type method Fixes #2606: Resolves tool name conflicts and response format inconsistencies that were causing non-deterministic behavior and poor user experience --- .../remote/tool_runtime/brave_search/brave_search.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/llama_stack/providers/remote/tool_runtime/brave_search/brave_search.py b/llama_stack/providers/remote/tool_runtime/brave_search/brave_search.py index b96b9e59c..326987ba9 100644 --- a/llama_stack/providers/remote/tool_runtime/brave_search/brave_search.py +++ b/llama_stack/providers/remote/tool_runtime/brave_search/brave_search.py @@ -4,6 +4,7 @@ # This source code is licensed under the terms described in the LICENSE file in # the root directory of this source tree. +import json from typing import Any import httpx @@ -18,7 +19,6 @@ from llama_stack.apis.tools import ( ToolRuntime, ) from llama_stack.distribution.request_headers import NeedsRequestProviderData -from llama_stack.models.llama.datatypes import BuiltinTool from llama_stack.providers.datatypes import ToolGroupsProtocolPrivate from .config import BraveSearchToolConfig @@ -54,7 +54,7 @@ class BraveSearchToolRuntimeImpl(ToolGroupsProtocolPrivate, ToolRuntime, NeedsRe return ListToolDefsResponse( data=[ ToolDef( - name="web_search", + name="web_search_brave", description="Search the web for information", parameters=[ ToolParameter( @@ -63,7 +63,6 @@ class BraveSearchToolRuntimeImpl(ToolGroupsProtocolPrivate, ToolRuntime, NeedsRe parameter_type="string", ) ], - built_in_type=BuiltinTool.brave_search, ) ] ) @@ -85,9 +84,10 @@ class BraveSearchToolRuntimeImpl(ToolGroupsProtocolPrivate, ToolRuntime, NeedsRe ) response.raise_for_status() results = self._clean_brave_response(response.json()) - content_items = "\n".join([str(result) for result in results]) + # Format response consistently with Tavily (JSON with query and top_k) + formatted_response = {"query": kwargs["query"], "top_k": results} return ToolInvocationResult( - content=content_items, + content=json.dumps(formatted_response), ) def _clean_brave_response(self, search_response): @@ -143,4 +143,4 @@ class BraveSearchToolRuntimeImpl(ToolGroupsProtocolPrivate, ToolRuntime, NeedsRe else: cleaned = {k: v for k, v in results.items() if k in selected_keys} - return str(cleaned) + return cleaned