From 3d958ef7e980dbb7b0e42f3742790c6ca3c5b88b Mon Sep 17 00:00:00 2001 From: Fahad Date: Tue, 10 Jun 2025 12:45:57 +0400 Subject: [PATCH] feat: enhance websearch functionality with reasoning-based approach MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Changed use_websearch default from False to True for all tools - Redesigned websearch behavior to focus on reasoning rather than direct search - Tools now analyze when web searches would be helpful and recommend specific searches - Updated all tool-specific websearch instructions to be more thoughtful - Gemini will now suggest what Claude should search for and explain why Key improvements: - Web search is now enabled by default for better documentation awareness - Instead of performing searches, Gemini reasons about what searches would help - Provides specific search recommendations for Claude to execute - More collaborative approach between Gemini and Claude This change makes the tools more intelligent about when external information would be valuable while keeping Claude in control of actual web searches. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- tools/analyze.py | 4 ++-- tools/base.py | 22 +++++++++++++++++----- tools/chat.py | 4 ++-- tools/codereview.py | 4 ++-- tools/debug.py | 4 ++-- tools/precommit.py | 4 ++-- tools/thinkdeep.py | 12 ++++++------ 7 files changed, 33 insertions(+), 21 deletions(-) diff --git a/tools/analyze.py b/tools/analyze.py index adc2aa1..79450b4 100644 --- a/tools/analyze.py +++ b/tools/analyze.py @@ -86,7 +86,7 @@ class AnalyzeTool(BaseTool): "use_websearch": { "type": "boolean", "description": "Enable web search for documentation, best practices, and current information. Particularly useful for: brainstorming sessions, architectural design discussions, exploring industry best practices, working with specific frameworks/technologies, researching solutions to complex problems, or when current documentation and community insights would enhance the analysis.", - "default": False, + "default": True, }, }, "required": ["files", "question"], @@ -157,7 +157,7 @@ class AnalyzeTool(BaseTool): # Add web search instruction if enabled websearch_instruction = self.get_websearch_instruction( request.use_websearch, - """Specifically search for: + """When analyzing code, consider if searches for these would help: - Documentation for technologies or frameworks found in the code - Best practices and design patterns relevant to the analysis - API references and usage examples diff --git a/tools/base.py b/tools/base.py index 4c49263..1b76379 100644 --- a/tools/base.py +++ b/tools/base.py @@ -165,18 +165,30 @@ class BaseTool(ABC): base_instruction = """ -WEB SEARCH ENABLED: Feel free to perform appropriate web searches to enhance your analysis.""" +WEB SEARCH REASONING: As you analyze this request, consider whether web searches would enhance your response. +If you identify areas where current documentation, API references, or community solutions would be valuable, +please note in your response what specific searches Claude should perform and why they would be helpful.""" if tool_specific: - return f"{base_instruction} {tool_specific}" + return f"{base_instruction} + +{tool_specific} + +In your response, if web searches would be beneficial, include a section like: +**Recommended Web Searches for Claude:** +- [Specific topic/framework/library] - to verify/understand/confirm [specific aspect] +- [Another search topic] - to explore [specific concern or feature]""" # Default instruction for all tools - return f"""{base_instruction} Search for: + return f"""{base_instruction} + +Consider searches for: - Current documentation and best practices -- Similar issues and community solutions +- Similar issues and community solutions - API references and usage examples - Recent developments and updates -Consider relevant findings when formulating your response.""" + +If any of these would strengthen your analysis, specify what Claude should search for and why.""" @abstractmethod def get_request_model(self): diff --git a/tools/chat.py b/tools/chat.py index b0766d6..c830851 100644 --- a/tools/chat.py +++ b/tools/chat.py @@ -71,7 +71,7 @@ class ChatTool(BaseTool): "use_websearch": { "type": "boolean", "description": "Enable web search for documentation, best practices, and current information. Particularly useful for: brainstorming sessions, architectural design discussions, exploring industry best practices, working with specific frameworks/technologies, researching solutions to complex problems, or when current documentation and community insights would enhance the analysis.", - "default": False, + "default": True, }, }, "required": ["prompt"], @@ -123,7 +123,7 @@ class ChatTool(BaseTool): # Add web search instruction if enabled websearch_instruction = self.get_websearch_instruction( request.use_websearch, - """Specifically search for: + """When discussing topics, consider if searches for these would help: - Documentation for any technologies or concepts mentioned - Current best practices and patterns - Recent developments or updates diff --git a/tools/codereview.py b/tools/codereview.py index 4f99807..3e523cd 100644 --- a/tools/codereview.py +++ b/tools/codereview.py @@ -124,7 +124,7 @@ class CodeReviewTool(BaseTool): "use_websearch": { "type": "boolean", "description": "Enable web search for documentation, best practices, and current information. Particularly useful for: brainstorming sessions, architectural design discussions, exploring industry best practices, working with specific frameworks/technologies, researching solutions to complex problems, or when current documentation and community insights would enhance the analysis.", - "default": False, + "default": True, }, }, "required": ["files", "context"], @@ -213,7 +213,7 @@ class CodeReviewTool(BaseTool): # Add web search instruction if enabled websearch_instruction = self.get_websearch_instruction( request.use_websearch, - """Specifically search for: + """When reviewing code, consider if searches for these would help: - Security vulnerabilities and CVEs for libraries/frameworks used - Best practices for the languages and frameworks in the code - Common anti-patterns and their solutions diff --git a/tools/debug.py b/tools/debug.py index 7d54984..1d9a549 100644 --- a/tools/debug.py +++ b/tools/debug.py @@ -89,7 +89,7 @@ class DebugIssueTool(BaseTool): "use_websearch": { "type": "boolean", "description": "Enable web search for documentation, best practices, and current information. Particularly useful for: brainstorming sessions, architectural design discussions, exploring industry best practices, working with specific frameworks/technologies, researching solutions to complex problems, or when current documentation and community insights would enhance the analysis.", - "default": False, + "default": True, }, }, "required": ["error_description"], @@ -166,7 +166,7 @@ class DebugIssueTool(BaseTool): # Add web search instruction if enabled websearch_instruction = self.get_websearch_instruction( request.use_websearch, - """Specifically search for: + """When debugging issues, consider if searches for these would help: - The exact error message to find known solutions - Framework-specific error codes and their meanings - Similar issues in forums, GitHub issues, or Stack Overflow diff --git a/tools/precommit.py b/tools/precommit.py index 6b3ebba..11453ea 100644 --- a/tools/precommit.py +++ b/tools/precommit.py @@ -98,7 +98,7 @@ class Precommit(BaseTool): schema["properties"]["use_websearch"] = { "type": "boolean", "description": "Enable web search for documentation, best practices, and current information. Particularly useful for: brainstorming sessions, architectural design discussions, exploring industry best practices, working with specific frameworks/technologies, researching solutions to complex problems, or when current documentation and community insights would enhance the analysis.", - "default": False, + "default": True, } return schema @@ -380,7 +380,7 @@ class Precommit(BaseTool): # Add web search instruction if enabled websearch_instruction = self.get_websearch_instruction( request.use_websearch, - """Specifically search for: + """When validating changes, consider if searches for these would help: - Best practices for new features or patterns introduced - Security implications of the changes - Known issues with libraries or APIs being used diff --git a/tools/thinkdeep.py b/tools/thinkdeep.py index 70f9a03..e2d20dd 100644 --- a/tools/thinkdeep.py +++ b/tools/thinkdeep.py @@ -85,7 +85,7 @@ class ThinkDeepTool(BaseTool): "use_websearch": { "type": "boolean", "description": "Enable web search for documentation, best practices, and current information. Particularly useful for: brainstorming sessions, architectural design discussions, exploring industry best practices, working with specific frameworks/technologies, researching solutions to complex problems, or when current documentation and community insights would enhance the analysis.", - "default": False, + "default": True, }, }, "required": ["current_analysis"], @@ -155,11 +155,11 @@ class ThinkDeepTool(BaseTool): # Add web search instruction if enabled websearch_instruction = self.get_websearch_instruction( request.use_websearch, - """Specifically search for: -- Current documentation for technologies, frameworks, or APIs being discussed -- Similar issues and their solutions from the community -- Best practices and recent developments -- Official sources to verify information""", + """When analyzing complex problems, consider if searches for these would help: +- Current documentation for specific technologies, frameworks, or APIs mentioned +- Known issues, workarounds, or community solutions for similar problems +- Recent updates, deprecations, or best practices that might affect the approach +- Official sources to verify assumptions or clarify technical details""", ) # Combine system prompt with context