Schema now lists all models including locally available models
New tool to list all models `listmodels` Integration test to for all the different combinations of API keys Tweaks to codereview prompt for a better quality input from Claude Fixed missing 'low' severity in codereview
This commit is contained in:
@@ -6,6 +6,7 @@ from .analyze import AnalyzeTool
|
||||
from .chat import ChatTool
|
||||
from .codereview import CodeReviewTool
|
||||
from .debug import DebugIssueTool
|
||||
from .listmodels import ListModelsTool
|
||||
from .precommit import Precommit
|
||||
from .refactor import RefactorTool
|
||||
from .testgen import TestGenerationTool
|
||||
@@ -18,6 +19,7 @@ __all__ = [
|
||||
"DebugIssueTool",
|
||||
"AnalyzeTool",
|
||||
"ChatTool",
|
||||
"ListModelsTool",
|
||||
"Precommit",
|
||||
"RefactorTool",
|
||||
"TestGenerationTool",
|
||||
|
||||
@@ -99,6 +99,9 @@ class ToolRequest(BaseModel):
|
||||
|
||||
|
||||
class BaseTool(ABC):
|
||||
# Class-level cache for OpenRouter registry to avoid multiple loads
|
||||
_openrouter_registry_cache = None
|
||||
|
||||
"""
|
||||
Abstract base class for all Gemini tools.
|
||||
|
||||
@@ -210,6 +213,20 @@ class BaseTool(ABC):
|
||||
"""
|
||||
pass
|
||||
|
||||
@classmethod
|
||||
def _get_openrouter_registry(cls):
|
||||
"""Get cached OpenRouter registry instance."""
|
||||
if BaseTool._openrouter_registry_cache is None:
|
||||
import logging
|
||||
|
||||
from providers.openrouter_registry import OpenRouterModelRegistry
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
logger.info("Loading OpenRouter registry for the first time (will be cached for all tools)")
|
||||
BaseTool._openrouter_registry_cache = OpenRouterModelRegistry()
|
||||
|
||||
return BaseTool._openrouter_registry_cache
|
||||
|
||||
def is_effective_auto_mode(self) -> bool:
|
||||
"""
|
||||
Check if we're in effective auto mode for schema generation.
|
||||
|
||||
@@ -39,21 +39,32 @@ class CodeReviewRequest(ToolRequest):
|
||||
)
|
||||
prompt: str = Field(
|
||||
...,
|
||||
description="User's summary of what the code does, expected behavior, constraints, and review objectives",
|
||||
description=(
|
||||
"User's summary of what the code does, expected behavior, constraints, and review objectives. "
|
||||
"IMPORTANT: Before using this tool, Claude should first perform its own preliminary review - "
|
||||
"examining the code structure, identifying potential issues, understanding the business logic, "
|
||||
"and noting areas of concern. Include Claude's initial observations about code quality, potential "
|
||||
"bugs, architectural patterns, and specific areas that need deeper scrutiny. This dual-perspective "
|
||||
"approach (Claude's analysis + external model's review) provides more comprehensive feedback and "
|
||||
"catches issues that either reviewer might miss alone."
|
||||
),
|
||||
)
|
||||
images: Optional[list[str]] = Field(
|
||||
None,
|
||||
description="Optional images of architecture diagrams, UI mockups, design documents, or visual references for code review context",
|
||||
description=(
|
||||
"Optional images of architecture diagrams, UI mockups, design documents, or visual references "
|
||||
"for code review context"
|
||||
),
|
||||
)
|
||||
review_type: str = Field("full", description="Type of review: full|security|performance|quick")
|
||||
focus_on: Optional[str] = Field(
|
||||
None,
|
||||
description="Specific aspects to focus on, or additional context that would help understand areas of concern",
|
||||
description=("Specific aspects to focus on, or additional context that would help understand areas of concern"),
|
||||
)
|
||||
standards: Optional[str] = Field(None, description="Coding standards or guidelines to enforce")
|
||||
severity_filter: str = Field(
|
||||
"all",
|
||||
description="Minimum severity to report: critical|high|medium|all",
|
||||
description="Minimum severity to report: critical|high|medium|low|all",
|
||||
)
|
||||
|
||||
|
||||
@@ -81,7 +92,8 @@ class CodeReviewTool(BaseTool):
|
||||
"Choose thinking_mode based on review scope: 'low' for small code snippets, "
|
||||
"'medium' for standard files/modules (default), 'high' for complex systems/architectures, "
|
||||
"'max' for critical security audits or large codebases requiring deepest analysis. "
|
||||
"Note: If you're not currently using a top-tier model such as Opus 4 or above, these tools can provide enhanced capabilities."
|
||||
"Note: If you're not currently using a top-tier model such as Opus 4 or above, these tools "
|
||||
"can provide enhanced capabilities."
|
||||
)
|
||||
|
||||
def get_input_schema(self) -> dict[str, Any]:
|
||||
@@ -96,12 +108,24 @@ class CodeReviewTool(BaseTool):
|
||||
"model": self.get_model_field_schema(),
|
||||
"prompt": {
|
||||
"type": "string",
|
||||
"description": "User's summary of what the code does, expected behavior, constraints, and review objectives",
|
||||
"description": (
|
||||
"User's summary of what the code does, expected behavior, constraints, and review "
|
||||
"objectives. IMPORTANT: Before using this tool, Claude should first perform its own "
|
||||
"preliminary review - examining the code structure, identifying potential issues, "
|
||||
"understanding the business logic, and noting areas of concern. Include Claude's initial "
|
||||
"observations about code quality, potential bugs, architectural patterns, and specific "
|
||||
"areas that need deeper scrutiny. This dual-perspective approach (Claude's analysis + "
|
||||
"external model's review) provides more comprehensive feedback and catches issues that "
|
||||
"either reviewer might miss alone."
|
||||
),
|
||||
},
|
||||
"images": {
|
||||
"type": "array",
|
||||
"items": {"type": "string"},
|
||||
"description": "Optional images of architecture diagrams, UI mockups, design documents, or visual references for code review context",
|
||||
"description": (
|
||||
"Optional images of architecture diagrams, UI mockups, design documents, or visual "
|
||||
"references for code review context"
|
||||
),
|
||||
},
|
||||
"review_type": {
|
||||
"type": "string",
|
||||
@@ -111,7 +135,10 @@ class CodeReviewTool(BaseTool):
|
||||
},
|
||||
"focus_on": {
|
||||
"type": "string",
|
||||
"description": "Specific aspects to focus on, or additional context that would help understand areas of concern",
|
||||
"description": (
|
||||
"Specific aspects to focus on, or additional context that would help understand "
|
||||
"areas of concern"
|
||||
),
|
||||
},
|
||||
"standards": {
|
||||
"type": "string",
|
||||
@@ -119,7 +146,7 @@ class CodeReviewTool(BaseTool):
|
||||
},
|
||||
"severity_filter": {
|
||||
"type": "string",
|
||||
"enum": ["critical", "high", "medium", "all"],
|
||||
"enum": ["critical", "high", "medium", "low", "all"],
|
||||
"default": "all",
|
||||
"description": "Minimum severity level to report",
|
||||
},
|
||||
@@ -132,16 +159,29 @@ class CodeReviewTool(BaseTool):
|
||||
"thinking_mode": {
|
||||
"type": "string",
|
||||
"enum": ["minimal", "low", "medium", "high", "max"],
|
||||
"description": "Thinking depth: minimal (0.5% of model max), low (8%), medium (33%), high (67%), max (100% of model max)",
|
||||
"description": (
|
||||
"Thinking depth: minimal (0.5% of model max), low (8%), medium (33%), high (67%), "
|
||||
"max (100% of model max)"
|
||||
),
|
||||
},
|
||||
"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.",
|
||||
"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": True,
|
||||
},
|
||||
"continuation_id": {
|
||||
"type": "string",
|
||||
"description": "Thread continuation ID for multi-turn conversations. Can be used to continue conversations across different tools. Only provide this if continuing a previous conversation thread.",
|
||||
"description": (
|
||||
"Thread continuation ID for multi-turn conversations. Can be used to continue "
|
||||
"conversations across different tools. Only provide this if continuing a previous "
|
||||
"conversation thread."
|
||||
),
|
||||
},
|
||||
},
|
||||
"required": ["files", "prompt"] + (["model"] if self.is_effective_auto_mode() else []),
|
||||
@@ -263,7 +303,8 @@ class CodeReviewTool(BaseTool):
|
||||
{file_content}
|
||||
=== END CODE ===
|
||||
|
||||
Please provide a code review aligned with the user's context and expectations, following the format specified in the system prompt."""
|
||||
Please provide a code review aligned with the user's context and expectations, following the format specified """
|
||||
"in the system prompt." ""
|
||||
|
||||
return full_prompt
|
||||
|
||||
@@ -285,10 +326,14 @@ Please provide a code review aligned with the user's context and expectations, f
|
||||
|
||||
**Claude's Next Steps:**
|
||||
|
||||
1. **Understand the Context**: First examine the specific functions, files, and code sections mentioned in the review to understand each issue thoroughly.
|
||||
1. **Understand the Context**: First examine the specific functions, files, and code sections mentioned in """
|
||||
"""the review to understand each issue thoroughly.
|
||||
|
||||
2. **Present Options to User**: After understanding the issues, ask the user which specific improvements they would like to implement, presenting them as a clear list of options.
|
||||
2. **Present Options to User**: After understanding the issues, ask the user which specific improvements """
|
||||
"""they would like to implement, presenting them as a clear list of options.
|
||||
|
||||
3. **Implement Selected Fixes**: Only implement the fixes the user chooses, ensuring each change is made correctly and maintains code quality.
|
||||
3. **Implement Selected Fixes**: Only implement the fixes the user chooses, ensuring each change is made """
|
||||
"""correctly and maintains code quality.
|
||||
|
||||
Remember: Always understand the code context before suggesting fixes, and let the user decide which improvements to implement."""
|
||||
Remember: Always understand the code context before suggesting fixes, and let the user decide which """
|
||||
"""improvements to implement."""
|
||||
|
||||
279
tools/listmodels.py
Normal file
279
tools/listmodels.py
Normal file
@@ -0,0 +1,279 @@
|
||||
"""
|
||||
List Models Tool - Display all available models organized by provider
|
||||
|
||||
This tool provides a comprehensive view of all AI models available in the system,
|
||||
organized by their provider (Gemini, OpenAI, X.AI, OpenRouter, Custom).
|
||||
It shows which providers are configured and what models can be used.
|
||||
"""
|
||||
|
||||
import os
|
||||
from typing import Any, Optional
|
||||
|
||||
from mcp.types import TextContent
|
||||
|
||||
from tools.base import BaseTool, ToolRequest
|
||||
from tools.models import ToolModelCategory, ToolOutput
|
||||
|
||||
|
||||
class ListModelsTool(BaseTool):
|
||||
"""
|
||||
Tool for listing all available AI models organized by provider.
|
||||
|
||||
This tool helps users understand:
|
||||
- Which providers are configured (have API keys)
|
||||
- What models are available from each provider
|
||||
- Model aliases and their full names
|
||||
- Context window sizes and capabilities
|
||||
"""
|
||||
|
||||
def get_name(self) -> str:
|
||||
return "listmodels"
|
||||
|
||||
def get_description(self) -> str:
|
||||
return (
|
||||
"LIST AVAILABLE MODELS - Display all AI models organized by provider. "
|
||||
"Shows which providers are configured, available models, their aliases, "
|
||||
"context windows, and capabilities. Useful for understanding what models "
|
||||
"can be used and their characteristics."
|
||||
)
|
||||
|
||||
def get_input_schema(self) -> dict[str, Any]:
|
||||
"""Return the JSON schema for the tool's input"""
|
||||
return {"type": "object", "properties": {}, "required": []}
|
||||
|
||||
def get_system_prompt(self) -> str:
|
||||
"""No AI model needed for this tool"""
|
||||
return ""
|
||||
|
||||
def get_request_model(self):
|
||||
"""Return the Pydantic model for request validation."""
|
||||
return ToolRequest
|
||||
|
||||
async def prepare_prompt(self, request: ToolRequest) -> str:
|
||||
"""Not used for this utility tool"""
|
||||
return ""
|
||||
|
||||
def format_response(self, response: str, request: ToolRequest, model_info: Optional[dict] = None) -> str:
|
||||
"""Not used for this utility tool"""
|
||||
return response
|
||||
|
||||
async def execute(self, arguments: dict[str, Any]) -> list[TextContent]:
|
||||
"""
|
||||
List all available models organized by provider.
|
||||
|
||||
This overrides the base class execute to provide direct output without AI model calls.
|
||||
|
||||
Args:
|
||||
arguments: Standard tool arguments (none required)
|
||||
|
||||
Returns:
|
||||
Formatted list of models by provider
|
||||
"""
|
||||
from config import MODEL_CAPABILITIES_DESC
|
||||
from providers.openrouter_registry import OpenRouterModelRegistry
|
||||
|
||||
output_lines = ["# Available AI Models\n"]
|
||||
|
||||
# Check native providers
|
||||
native_providers = {
|
||||
"gemini": {
|
||||
"name": "Google Gemini",
|
||||
"env_key": "GEMINI_API_KEY",
|
||||
"models": {
|
||||
"flash": "gemini-2.5-flash-preview-05-20",
|
||||
"pro": "gemini-2.5-pro-preview-06-05",
|
||||
},
|
||||
},
|
||||
"openai": {
|
||||
"name": "OpenAI",
|
||||
"env_key": "OPENAI_API_KEY",
|
||||
"models": {
|
||||
"o3": "o3",
|
||||
"o3-mini": "o3-mini",
|
||||
"o3-pro": "o3-pro",
|
||||
"o4-mini": "o4-mini",
|
||||
"o4-mini-high": "o4-mini-high",
|
||||
},
|
||||
},
|
||||
"xai": {
|
||||
"name": "X.AI (Grok)",
|
||||
"env_key": "XAI_API_KEY",
|
||||
"models": {
|
||||
"grok": "grok-3",
|
||||
"grok-3": "grok-3",
|
||||
"grok-3-fast": "grok-3-fast",
|
||||
"grok3": "grok-3",
|
||||
"grokfast": "grok-3-fast",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
# Check each native provider
|
||||
for provider_key, provider_info in native_providers.items():
|
||||
api_key = os.getenv(provider_info["env_key"])
|
||||
is_configured = api_key and api_key != f"your_{provider_key}_api_key_here"
|
||||
|
||||
output_lines.append(f"## {provider_info['name']} {'✅' if is_configured else '❌'}")
|
||||
|
||||
if is_configured:
|
||||
output_lines.append("**Status**: Configured and available")
|
||||
output_lines.append("\n**Models**:")
|
||||
|
||||
for alias, full_name in provider_info["models"].items():
|
||||
# Get description from MODEL_CAPABILITIES_DESC
|
||||
desc = MODEL_CAPABILITIES_DESC.get(alias, "")
|
||||
if isinstance(desc, str):
|
||||
# Extract context window from description
|
||||
import re
|
||||
|
||||
context_match = re.search(r"\(([^)]+context)\)", desc)
|
||||
context_info = context_match.group(1) if context_match else ""
|
||||
|
||||
output_lines.append(f"- `{alias}` → `{full_name}` - {context_info}")
|
||||
|
||||
# Extract key capability
|
||||
if "Ultra-fast" in desc:
|
||||
output_lines.append(" - Fast processing, quick iterations")
|
||||
elif "Deep reasoning" in desc:
|
||||
output_lines.append(" - Extended reasoning with thinking mode")
|
||||
elif "Strong reasoning" in desc:
|
||||
output_lines.append(" - Logical problems, systematic analysis")
|
||||
elif "EXTREMELY EXPENSIVE" in desc:
|
||||
output_lines.append(" - ⚠️ Professional grade (very expensive)")
|
||||
else:
|
||||
output_lines.append(f"**Status**: Not configured (set {provider_info['env_key']})")
|
||||
|
||||
output_lines.append("")
|
||||
|
||||
# Check OpenRouter
|
||||
openrouter_key = os.getenv("OPENROUTER_API_KEY")
|
||||
is_openrouter_configured = openrouter_key and openrouter_key != "your_openrouter_api_key_here"
|
||||
|
||||
output_lines.append(f"## OpenRouter {'✅' if is_openrouter_configured else '❌'}")
|
||||
|
||||
if is_openrouter_configured:
|
||||
output_lines.append("**Status**: Configured and available")
|
||||
output_lines.append("**Description**: Access to multiple cloud AI providers via unified API")
|
||||
|
||||
try:
|
||||
registry = OpenRouterModelRegistry()
|
||||
aliases = registry.list_aliases()
|
||||
|
||||
# Group by provider for better organization
|
||||
providers_models = {}
|
||||
for alias in aliases[:20]: # Limit to first 20 to avoid overwhelming output
|
||||
config = registry.resolve(alias)
|
||||
if config and not (hasattr(config, "is_custom") and config.is_custom):
|
||||
# Extract provider from model_name
|
||||
provider = config.model_name.split("/")[0] if "/" in config.model_name else "other"
|
||||
if provider not in providers_models:
|
||||
providers_models[provider] = []
|
||||
providers_models[provider].append((alias, config))
|
||||
|
||||
output_lines.append("\n**Available Models** (showing top 20):")
|
||||
for provider, models in sorted(providers_models.items()):
|
||||
output_lines.append(f"\n*{provider.title()}:*")
|
||||
for alias, config in models[:5]: # Limit each provider to 5 models
|
||||
context_str = f"{config.context_window // 1000}K" if config.context_window else "?"
|
||||
output_lines.append(f"- `{alias}` → `{config.model_name}` ({context_str} context)")
|
||||
|
||||
total_models = len(aliases)
|
||||
output_lines.append(f"\n...and {total_models - 20} more models available")
|
||||
|
||||
except Exception as e:
|
||||
output_lines.append(f"**Error loading models**: {str(e)}")
|
||||
else:
|
||||
output_lines.append("**Status**: Not configured (set OPENROUTER_API_KEY)")
|
||||
output_lines.append("**Note**: Provides access to GPT-4, Claude, Mistral, and many more")
|
||||
|
||||
output_lines.append("")
|
||||
|
||||
# Check Custom API
|
||||
custom_url = os.getenv("CUSTOM_API_URL")
|
||||
|
||||
output_lines.append(f"## Custom/Local API {'✅' if custom_url else '❌'}")
|
||||
|
||||
if custom_url:
|
||||
output_lines.append("**Status**: Configured and available")
|
||||
output_lines.append(f"**Endpoint**: {custom_url}")
|
||||
output_lines.append("**Description**: Local models via Ollama, vLLM, LM Studio, etc.")
|
||||
|
||||
try:
|
||||
registry = OpenRouterModelRegistry()
|
||||
custom_models = []
|
||||
|
||||
for alias in registry.list_aliases():
|
||||
config = registry.resolve(alias)
|
||||
if config and hasattr(config, "is_custom") and config.is_custom:
|
||||
custom_models.append((alias, config))
|
||||
|
||||
if custom_models:
|
||||
output_lines.append("\n**Custom Models**:")
|
||||
for alias, config in custom_models:
|
||||
context_str = f"{config.context_window // 1000}K" if config.context_window else "?"
|
||||
output_lines.append(f"- `{alias}` → `{config.model_name}` ({context_str} context)")
|
||||
if config.description:
|
||||
output_lines.append(f" - {config.description}")
|
||||
|
||||
except Exception as e:
|
||||
output_lines.append(f"**Error loading custom models**: {str(e)}")
|
||||
else:
|
||||
output_lines.append("**Status**: Not configured (set CUSTOM_API_URL)")
|
||||
output_lines.append("**Example**: CUSTOM_API_URL=http://localhost:11434 (for Ollama)")
|
||||
|
||||
output_lines.append("")
|
||||
|
||||
# Add summary
|
||||
output_lines.append("## Summary")
|
||||
|
||||
# Count configured providers
|
||||
configured_count = sum(
|
||||
[
|
||||
1
|
||||
for p in native_providers.values()
|
||||
if os.getenv(p["env_key"])
|
||||
and os.getenv(p["env_key"]) != f"your_{p['env_key'].lower().replace('_api_key', '')}_api_key_here"
|
||||
]
|
||||
)
|
||||
if is_openrouter_configured:
|
||||
configured_count += 1
|
||||
if custom_url:
|
||||
configured_count += 1
|
||||
|
||||
output_lines.append(f"**Configured Providers**: {configured_count}")
|
||||
|
||||
# Get total available models
|
||||
try:
|
||||
from tools.analyze import AnalyzeTool
|
||||
|
||||
tool = AnalyzeTool()
|
||||
total_models = len(tool._get_available_models())
|
||||
output_lines.append(f"**Total Available Models**: {total_models}")
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
# Add usage tips
|
||||
output_lines.append("\n**Usage Tips**:")
|
||||
output_lines.append("- Use model aliases (e.g., 'flash', 'o3', 'opus') for convenience")
|
||||
output_lines.append("- In auto mode, Claude will select the best model for each task")
|
||||
output_lines.append("- Custom models are only available when CUSTOM_API_URL is set")
|
||||
output_lines.append("- OpenRouter provides access to many cloud models with one API key")
|
||||
|
||||
# Format output
|
||||
content = "\n".join(output_lines)
|
||||
|
||||
tool_output = ToolOutput(
|
||||
status="success",
|
||||
content=content,
|
||||
content_type="text",
|
||||
metadata={
|
||||
"tool_name": self.name,
|
||||
"configured_providers": configured_count,
|
||||
},
|
||||
)
|
||||
|
||||
return [TextContent(type="text", text=tool_output.model_dump_json())]
|
||||
|
||||
def get_model_category(self) -> ToolModelCategory:
|
||||
"""Return the model category for this tool."""
|
||||
return ToolModelCategory.FAST_RESPONSE # Simple listing, no AI needed
|
||||
Reference in New Issue
Block a user