|
|
|
|
|
|
|
|
import logging |
|
|
from typing import Dict, Any, List, Optional |
|
|
from .base_tool import BaseTool |
|
|
|
|
|
class SearchTool(BaseTool): |
|
|
"""Tool for searching scientific literature and databases. |
|
|
|
|
|
This tool allows agents to search for relevant scientific information |
|
|
to support hypothesis generation, evaluation, and refinement. |
|
|
""" |
|
|
|
|
|
def __init__(self): |
|
|
"""Initialize the search tool.""" |
|
|
super().__init__( |
|
|
name="search", |
|
|
description="Search scientific literature and databases for relevant information" |
|
|
) |
|
|
self.logger = logging.getLogger("tool.search") |
|
|
|
|
|
def execute(self, query: str, source: Optional[str] = None, max_results: int = 5) -> List[Dict[str, Any]]: |
|
|
"""Execute a search for scientific information. |
|
|
|
|
|
Args: |
|
|
query: The search query |
|
|
source: Optional specific source to search (e.g., 'pubmed', 'arxiv', 'general') |
|
|
max_results: Maximum number of results to return |
|
|
|
|
|
Returns: |
|
|
A list of search results, each containing title, source, summary, and relevance score |
|
|
""" |
|
|
self.logger.info(f"Executing search: {query} (source: {source or 'all'}, max_results: {max_results})") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mock_results = [ |
|
|
{ |
|
|
"title": f"Scientific Paper about {query} #{i}", |
|
|
"authors": ["Author A", "Author B"], |
|
|
"year": 2023, |
|
|
"source": source or "Scientific Database", |
|
|
"summary": f"This paper discusses various aspects of {query} with significant findings.", |
|
|
"relevance_score": 0.95 - (i * 0.1), |
|
|
"url": f"https://example.org/paper/{i}" |
|
|
} |
|
|
for i in range(min(max_results, 10)) |
|
|
] |
|
|
|
|
|
return mock_results |
|
|
|
|
|
def get_parameters_schema(self) -> Dict[str, Any]: |
|
|
"""Get the JSON schema for the tool's parameters. |
|
|
|
|
|
Returns: |
|
|
A dictionary containing the JSON schema |
|
|
""" |
|
|
return { |
|
|
"type": "object", |
|
|
"properties": { |
|
|
"query": { |
|
|
"type": "string", |
|
|
"description": "The search query for scientific information" |
|
|
}, |
|
|
"source": { |
|
|
"type": "string", |
|
|
"description": "Optional specific source to search (e.g., 'pubmed', 'arxiv', 'general')" |
|
|
}, |
|
|
"max_results": { |
|
|
"type": "integer", |
|
|
"description": "Maximum number of results to return", |
|
|
"default": 5 |
|
|
} |
|
|
}, |
|
|
"required": ["query"] |
|
|
} |
|
|
|