Spaces:
Running
Running
File size: 5,715 Bytes
026ee5d d45d242 026ee5d d45d242 026ee5d d45d242 026ee5d d45d242 026ee5d d45d242 026ee5d d45d242 026ee5d d45d242 026ee5d d45d242 026ee5d d45d242 026ee5d d45d242 026ee5d d45d242 026ee5d d45d242 026ee5d d45d242 026ee5d d45d242 026ee5d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 |
# Tools API Reference
This page documents the API for DeepCritical search tools.
## SearchTool Protocol
All tools implement the `SearchTool` protocol:
```python
class SearchTool(Protocol):
@property
def name(self) -> str: ...
async def search(
self,
query: str,
max_results: int = 10
) -> list[Evidence]: ...
```
## PubMedTool
**Module**: `src.tools.pubmed`
**Purpose**: Search peer-reviewed biomedical literature from PubMed.
### Properties
#### `name`
```python
@property
def name(self) -> str
```
Returns tool name: `"pubmed"`
### Methods
#### `search`
```python
async def search(
self,
query: str,
max_results: int = 10
) -> list[Evidence]
```
Searches PubMed for articles.
**Parameters**:
- `query`: Search query string
- `max_results`: Maximum number of results to return (default: 10)
**Returns**: List of `Evidence` objects with PubMed articles.
**Raises**:
- `SearchError`: If search fails (timeout, HTTP error, XML parsing error)
- `RateLimitError`: If rate limit is exceeded (429 status code)
**Note**: Uses NCBI E-utilities (ESearch → EFetch). Rate limit: 0.34s between requests. Handles single vs. multiple articles.
## ClinicalTrialsTool
**Module**: `src.tools.clinicaltrials`
**Purpose**: Search ClinicalTrials.gov for interventional studies.
### Properties
#### `name`
```python
@property
def name(self) -> str
```
Returns tool name: `"clinicaltrials"`
### Methods
#### `search`
```python
async def search(
self,
query: str,
max_results: int = 10
) -> list[Evidence]
```
Searches ClinicalTrials.gov for trials.
**Parameters**:
- `query`: Search query string
- `max_results`: Maximum number of results to return (default: 10)
**Returns**: List of `Evidence` objects with clinical trials.
**Note**: Only returns interventional studies with status: COMPLETED, ACTIVE_NOT_RECRUITING, RECRUITING, ENROLLING_BY_INVITATION. Uses `requests` library (NOT httpx - WAF blocks httpx). Runs in thread pool for async compatibility.
**Raises**:
- `SearchError`: If search fails (HTTP error, request exception)
## EuropePMCTool
**Module**: `src.tools.europepmc`
**Purpose**: Search Europe PMC for preprints and peer-reviewed articles.
### Properties
#### `name`
```python
@property
def name(self) -> str
```
Returns tool name: `"europepmc"`
### Methods
#### `search`
```python
async def search(
self,
query: str,
max_results: int = 10
) -> list[Evidence]
```
Searches Europe PMC for articles and preprints.
**Parameters**:
- `query`: Search query string
- `max_results`: Maximum number of results to return (default: 10)
**Returns**: List of `Evidence` objects with articles/preprints.
**Note**: Includes both preprints (marked with `[PREPRINT - Not peer-reviewed]`) and peer-reviewed articles. Handles preprint markers. Builds URLs from DOI or PMID.
**Raises**:
- `SearchError`: If search fails (HTTP error, connection error)
## RAGTool
**Module**: `src.tools.rag_tool`
**Purpose**: Semantic search within collected evidence.
### Initialization
```python
def __init__(
self,
rag_service: LlamaIndexRAGService | None = None,
oauth_token: str | None = None
) -> None
```
**Parameters**:
- `rag_service`: Optional RAG service instance. If None, will be lazy-initialized.
- `oauth_token`: Optional OAuth token from HuggingFace login (for RAG LLM)
### Properties
#### `name`
```python
@property
def name(self) -> str
```
Returns tool name: `"rag"`
### Methods
#### `search`
```python
async def search(
self,
query: str,
max_results: int = 10
) -> list[Evidence]
```
Searches collected evidence using semantic similarity.
**Parameters**:
- `query`: Search query string
- `max_results`: Maximum number of results to return (default: 10)
**Returns**: List of `Evidence` objects from collected evidence.
**Raises**:
- `ConfigurationError`: If RAG service is unavailable
**Note**: Requires evidence to be ingested into RAG service first. Wraps `LlamaIndexRAGService`. Returns Evidence from RAG results.
## SearchHandler
**Module**: `src.tools.search_handler`
**Purpose**: Orchestrates parallel searches across multiple tools.
### Initialization
```python
def __init__(
self,
tools: list[SearchTool],
timeout: float = 30.0,
include_rag: bool = False,
auto_ingest_to_rag: bool = True,
oauth_token: str | None = None
) -> None
```
**Parameters**:
- `tools`: List of search tools to use
- `timeout`: Timeout for each search in seconds (default: 30.0)
- `include_rag`: Whether to include RAG tool in searches (default: False)
- `auto_ingest_to_rag`: Whether to automatically ingest results into RAG (default: True)
- `oauth_token`: Optional OAuth token from HuggingFace login (for RAG LLM)
### Methods
#### `execute`
<!--codeinclude-->
[SearchHandler.execute](../src/tools/search_handler.py) start_line:86 end_line:86
<!--/codeinclude-->
Searches multiple tools in parallel.
**Parameters**:
- `query`: Search query string
- `max_results_per_tool`: Maximum results per tool (default: 10)
**Returns**: `SearchResult` with:
- `query`: The search query
- `evidence`: Aggregated list of evidence
- `sources_searched`: List of source names searched
- `total_found`: Total number of results
- `errors`: List of error messages from failed tools
**Raises**:
- `SearchError`: If search times out
**Note**: Uses `asyncio.gather()` for parallel execution. Handles tool failures gracefully (returns errors in `SearchResult.errors`). Automatically ingests evidence into RAG if enabled.
## See Also
- [Architecture - Tools](../architecture/tools.md) - Architecture overview
- [Models API](models.md) - Data models used by tools
|