feat: add web search capability to all tools for enhanced analysis

- Add use_websearch parameter to base ToolRequest class
- All tools now inherit web search capability automatically
- Enhanced description emphasizes brainstorming and architectural design
- Add get_websearch_instruction() helper method to base class
- Update all tools to include web search in their prompts when enabled
- Update README documentation with web search examples
- Fix linting issues (ruff, black formatting)

Web search is particularly useful for:
- Brainstorming sessions and architectural design discussions
- Exploring industry best practices
- Working with specific frameworks/technologies
- Researching solutions to complex problems
- Getting current documentation and community insights

🤖 Generated with Claude Code

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Fahad
2025-06-10 11:09:28 +04:00
parent 2fe83dd381
commit cf0b3f7f44
11 changed files with 191 additions and 15 deletions

View File

@@ -84,6 +84,11 @@ class AnalyzeTool(BaseTool):
"enum": ["minimal", "low", "medium", "high", "max"],
"description": "Thinking depth: minimal (128), low (2048), medium (8192), high (16384), max (32768)",
},
"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,
},
},
"required": ["files", "question"],
}
@@ -150,10 +155,20 @@ class AnalyzeTool(BaseTool):
focus_instruction = "\n".join(analysis_focus) if analysis_focus else ""
# Add web search instruction if enabled
websearch_instruction = self.get_websearch_instruction(
request.use_websearch,
"""Specifically search for:
- Documentation for technologies or frameworks found in the code
- Best practices and design patterns relevant to the analysis
- API references and usage examples
- Known issues or solutions for patterns you identify""",
)
# Combine everything
full_prompt = f"""{self.get_system_prompt()}
{focus_instruction}
{focus_instruction}{websearch_instruction}
=== USER QUESTION ===
{request.question}

View File

@@ -46,6 +46,10 @@ class ToolRequest(BaseModel):
None,
description="Thinking depth: minimal (128), low (2048), medium (8192), high (16384), max (32768)",
)
use_websearch: Optional[bool] = Field(
False,
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.",
)
class BaseTool(ABC):
@@ -145,6 +149,35 @@ class BaseTool(ABC):
"""
return "medium" # Default to medium thinking for better reasoning
def get_websearch_instruction(self, use_websearch: bool, tool_specific: Optional[str] = None) -> str:
"""
Generate web search instruction based on the use_websearch parameter.
Args:
use_websearch: Whether web search is enabled
tool_specific: Optional tool-specific search guidance
Returns:
str: Web search instruction to append to prompt, or empty string
"""
if not use_websearch:
return ""
base_instruction = """
WEB SEARCH ENABLED: Feel free to perform appropriate web searches to enhance your analysis."""
if tool_specific:
return f"{base_instruction} {tool_specific}"
# Default instruction for all tools
return f"""{base_instruction} Search for:
- Current documentation and best practices
- Similar issues and community solutions
- API references and usage examples
- Recent developments and updates
Consider relevant findings when formulating your response."""
@abstractmethod
def get_request_model(self):
"""

View File

@@ -68,6 +68,11 @@ class ChatTool(BaseTool):
"enum": ["minimal", "low", "medium", "high", "max"],
"description": "Thinking depth: minimal (128), low (2048), medium (8192), high (16384), max (32768)",
},
"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,
},
},
"required": ["prompt"],
}
@@ -115,8 +120,18 @@ class ChatTool(BaseTool):
# Check token limits
self._validate_token_limit(user_content, "Content")
# Add web search instruction if enabled
websearch_instruction = self.get_websearch_instruction(
request.use_websearch,
"""Specifically search for:
- Documentation for any technologies or concepts mentioned
- Current best practices and patterns
- Recent developments or updates
- Community discussions and solutions""",
)
# Combine system prompt with user content
full_prompt = f"""{self.get_system_prompt()}
full_prompt = f"""{self.get_system_prompt()}{websearch_instruction}
=== USER REQUEST ===
{user_content}

View File

@@ -82,6 +82,11 @@ class DebugIssueTool(BaseTool):
"enum": ["minimal", "low", "medium", "high", "max"],
"description": "Thinking depth: minimal (128), low (2048), medium (8192), high (16384), max (32768)",
},
"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,
},
},
"required": ["error_description"],
}
@@ -154,8 +159,19 @@ class DebugIssueTool(BaseTool):
# Check token limits
self._validate_token_limit(full_context, "Context")
# Add web search instruction if enabled
websearch_instruction = self.get_websearch_instruction(
request.use_websearch,
"""Specifically search for:
- The exact error message to find known solutions
- Framework-specific error codes and their meanings
- Similar issues in forums, GitHub issues, or Stack Overflow
- Workarounds and patches for known bugs
- Version-specific issues and compatibility problems""",
)
# Combine everything
full_prompt = f"""{self.get_system_prompt()}
full_prompt = f"""{self.get_system_prompt()}{websearch_instruction}
{full_context}

View File

@@ -92,7 +92,15 @@ class ReviewChanges(BaseTool):
)
def get_input_schema(self) -> dict[str, Any]:
return self.get_request_model().model_json_schema()
schema = self.get_request_model().model_json_schema()
# Ensure use_websearch is in the schema with proper description
if "properties" in schema and "use_websearch" not in schema["properties"]:
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,
}
return schema
def get_system_prompt(self) -> str:
return REVIEW_CHANGES_PROMPT
@@ -369,6 +377,17 @@ class ReviewChanges(BaseTool):
)
prompt_parts.extend(context_files_content)
# Add web search instruction if enabled
websearch_instruction = self.get_websearch_instruction(
request.use_websearch,
"""Specifically search for:
- Best practices for new features or patterns introduced
- Security implications of the changes
- Known issues with libraries or APIs being used
- Migration guides if updating dependencies
- Performance considerations for the implemented approach""",
)
# Add review instructions
prompt_parts.append("\n## Review Instructions\n")
prompt_parts.append(
@@ -385,7 +404,10 @@ class ReviewChanges(BaseTool):
"you may request them using the standardized JSON response format."
)
return "\n".join(prompt_parts)
# Combine with system prompt and websearch instruction
full_prompt = f"{self.get_system_prompt()}{websearch_instruction}\n\n" + "\n".join(prompt_parts)
return full_prompt
def format_response(self, response: str, request: ReviewChangesRequest) -> str:
"""Format the response with commit guidance"""

View File

@@ -122,6 +122,11 @@ class ReviewCodeTool(BaseTool):
"enum": ["minimal", "low", "medium", "high", "max"],
"description": "Thinking depth: minimal (128), low (2048), medium (8192), high (16384), max (32768)",
},
"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,
},
},
"required": ["files", "context"],
}
@@ -206,8 +211,19 @@ class ReviewCodeTool(BaseTool):
focus_instruction = "\n".join(review_focus) if review_focus else ""
# Add web search instruction if enabled
websearch_instruction = self.get_websearch_instruction(
request.use_websearch,
"""Specifically search for:
- Security vulnerabilities and CVEs for libraries/frameworks used
- Best practices for the languages and frameworks in the code
- Common anti-patterns and their solutions
- Performance optimization techniques
- Recent updates or deprecations in APIs used""",
)
# Construct the complete prompt with system instructions and code
full_prompt = f"""{self.get_system_prompt()}
full_prompt = f"""{self.get_system_prompt()}{websearch_instruction}
=== USER CONTEXT ===
{request.context}

View File

@@ -83,6 +83,11 @@ class ThinkDeeperTool(BaseTool):
"description": "Thinking depth: minimal (128), low (2048), medium (8192), high (16384), max (32768)",
"default": "high",
},
"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,
},
},
"required": ["current_analysis"],
}
@@ -148,8 +153,18 @@ class ThinkDeeperTool(BaseTool):
areas = ", ".join(request.focus_areas)
focus_instruction = f"\n\nFOCUS AREAS: Please pay special attention to {areas} aspects."
# 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""",
)
# Combine system prompt with context
full_prompt = f"""{self.get_system_prompt()}{focus_instruction}
full_prompt = f"""{self.get_system_prompt()}{focus_instruction}{websearch_instruction}
{full_context}