aiecs 1.2.2__py3-none-any.whl → 1.3.3__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of aiecs might be problematic. Click here for more details.
- aiecs/__init__.py +1 -1
- aiecs/llm/clients/vertex_client.py +22 -2
- aiecs/main.py +2 -2
- aiecs/scripts/tools_develop/README.md +111 -2
- aiecs/scripts/tools_develop/TOOL_AUTO_DISCOVERY.md +234 -0
- aiecs/scripts/tools_develop/validate_tool_schemas.py +80 -21
- aiecs/scripts/tools_develop/verify_tools.py +347 -0
- aiecs/tools/__init__.py +94 -30
- aiecs/tools/apisource/__init__.py +106 -0
- aiecs/tools/apisource/intelligence/__init__.py +20 -0
- aiecs/tools/apisource/intelligence/data_fusion.py +378 -0
- aiecs/tools/apisource/intelligence/query_analyzer.py +387 -0
- aiecs/tools/apisource/intelligence/search_enhancer.py +384 -0
- aiecs/tools/apisource/monitoring/__init__.py +12 -0
- aiecs/tools/apisource/monitoring/metrics.py +308 -0
- aiecs/tools/apisource/providers/__init__.py +114 -0
- aiecs/tools/apisource/providers/base.py +684 -0
- aiecs/tools/apisource/providers/census.py +412 -0
- aiecs/tools/apisource/providers/fred.py +575 -0
- aiecs/tools/apisource/providers/newsapi.py +402 -0
- aiecs/tools/apisource/providers/worldbank.py +346 -0
- aiecs/tools/apisource/reliability/__init__.py +14 -0
- aiecs/tools/apisource/reliability/error_handler.py +362 -0
- aiecs/tools/apisource/reliability/fallback_strategy.py +420 -0
- aiecs/tools/apisource/tool.py +814 -0
- aiecs/tools/apisource/utils/__init__.py +12 -0
- aiecs/tools/apisource/utils/validators.py +343 -0
- aiecs/tools/langchain_adapter.py +95 -17
- aiecs/tools/search_tool/__init__.py +102 -0
- aiecs/tools/search_tool/analyzers.py +583 -0
- aiecs/tools/search_tool/cache.py +280 -0
- aiecs/tools/search_tool/constants.py +127 -0
- aiecs/tools/search_tool/context.py +219 -0
- aiecs/tools/search_tool/core.py +773 -0
- aiecs/tools/search_tool/deduplicator.py +123 -0
- aiecs/tools/search_tool/error_handler.py +257 -0
- aiecs/tools/search_tool/metrics.py +375 -0
- aiecs/tools/search_tool/rate_limiter.py +177 -0
- aiecs/tools/search_tool/schemas.py +297 -0
- aiecs/tools/statistics/data_loader_tool.py +2 -2
- aiecs/tools/statistics/data_transformer_tool.py +1 -1
- aiecs/tools/task_tools/__init__.py +8 -8
- aiecs/tools/task_tools/report_tool.py +1 -1
- aiecs/tools/tool_executor/__init__.py +2 -0
- aiecs/tools/tool_executor/tool_executor.py +284 -14
- aiecs/utils/__init__.py +11 -0
- aiecs/utils/cache_provider.py +698 -0
- aiecs/utils/execution_utils.py +5 -5
- {aiecs-1.2.2.dist-info → aiecs-1.3.3.dist-info}/METADATA +1 -1
- {aiecs-1.2.2.dist-info → aiecs-1.3.3.dist-info}/RECORD +54 -22
- aiecs/tools/task_tools/search_tool.py +0 -1123
- {aiecs-1.2.2.dist-info → aiecs-1.3.3.dist-info}/WHEEL +0 -0
- {aiecs-1.2.2.dist-info → aiecs-1.3.3.dist-info}/entry_points.txt +0 -0
- {aiecs-1.2.2.dist-info → aiecs-1.3.3.dist-info}/licenses/LICENSE +0 -0
- {aiecs-1.2.2.dist-info → aiecs-1.3.3.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Pydantic Schema Definitions for SearchTool Operations
|
|
3
|
+
|
|
4
|
+
Provides input validation, type safety, and automatic documentation
|
|
5
|
+
for all SearchTool operations.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from typing import Optional, List, Dict, Any
|
|
9
|
+
from pydantic import BaseModel, Field, field_validator
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class SearchWebSchema(BaseModel):
|
|
13
|
+
"""Schema for search_web operation"""
|
|
14
|
+
|
|
15
|
+
query: str = Field(
|
|
16
|
+
description="Search query string"
|
|
17
|
+
)
|
|
18
|
+
num_results: int = Field(
|
|
19
|
+
default=10,
|
|
20
|
+
ge=1,
|
|
21
|
+
le=100,
|
|
22
|
+
description="Number of results to return (1-100)"
|
|
23
|
+
)
|
|
24
|
+
start_index: int = Field(
|
|
25
|
+
default=1,
|
|
26
|
+
ge=1,
|
|
27
|
+
le=91,
|
|
28
|
+
description="Starting index for pagination (1-91)"
|
|
29
|
+
)
|
|
30
|
+
language: str = Field(
|
|
31
|
+
default="en",
|
|
32
|
+
description="Language code for results (e.g., 'en', 'zh-CN', 'es')"
|
|
33
|
+
)
|
|
34
|
+
country: str = Field(
|
|
35
|
+
default="us",
|
|
36
|
+
description="Country code for geolocation (e.g., 'us', 'cn', 'uk')"
|
|
37
|
+
)
|
|
38
|
+
safe_search: str = Field(
|
|
39
|
+
default="medium",
|
|
40
|
+
description="Safe search level: 'off', 'medium', or 'high'"
|
|
41
|
+
)
|
|
42
|
+
date_restrict: Optional[str] = Field(
|
|
43
|
+
default=None,
|
|
44
|
+
description="Date restriction (e.g., 'd7' for last 7 days, 'm3' for last 3 months)"
|
|
45
|
+
)
|
|
46
|
+
file_type: Optional[str] = Field(
|
|
47
|
+
default=None,
|
|
48
|
+
description="File type filter (e.g., 'pdf', 'doc', 'xls')"
|
|
49
|
+
)
|
|
50
|
+
exclude_terms: Optional[List[str]] = Field(
|
|
51
|
+
default=None,
|
|
52
|
+
description="Terms to exclude from search results"
|
|
53
|
+
)
|
|
54
|
+
auto_enhance: bool = Field(
|
|
55
|
+
default=True,
|
|
56
|
+
description="Whether to automatically enhance query based on detected intent"
|
|
57
|
+
)
|
|
58
|
+
return_summary: bool = Field(
|
|
59
|
+
default=False,
|
|
60
|
+
description="Whether to return a structured summary of results"
|
|
61
|
+
)
|
|
62
|
+
|
|
63
|
+
@field_validator('safe_search')
|
|
64
|
+
@classmethod
|
|
65
|
+
def validate_safe_search(cls, v: str) -> str:
|
|
66
|
+
"""Validate safe search level"""
|
|
67
|
+
allowed = ['off', 'medium', 'high']
|
|
68
|
+
if v not in allowed:
|
|
69
|
+
raise ValueError(f"safe_search must be one of {allowed}")
|
|
70
|
+
return v
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
class SearchImagesSchema(BaseModel):
|
|
74
|
+
"""Schema for search_images operation"""
|
|
75
|
+
|
|
76
|
+
query: str = Field(
|
|
77
|
+
description="Image search query string"
|
|
78
|
+
)
|
|
79
|
+
num_results: int = Field(
|
|
80
|
+
default=10,
|
|
81
|
+
ge=1,
|
|
82
|
+
le=100,
|
|
83
|
+
description="Number of image results to return (1-100)"
|
|
84
|
+
)
|
|
85
|
+
image_size: Optional[str] = Field(
|
|
86
|
+
default=None,
|
|
87
|
+
description="Image size filter: 'icon', 'small', 'medium', 'large', 'xlarge', 'xxlarge', 'huge'"
|
|
88
|
+
)
|
|
89
|
+
image_type: Optional[str] = Field(
|
|
90
|
+
default=None,
|
|
91
|
+
description="Image type filter: 'clipart', 'face', 'lineart', 'stock', 'photo', 'animated'"
|
|
92
|
+
)
|
|
93
|
+
image_color_type: Optional[str] = Field(
|
|
94
|
+
default=None,
|
|
95
|
+
description="Color type filter: 'color', 'gray', 'mono', 'trans'"
|
|
96
|
+
)
|
|
97
|
+
safe_search: str = Field(
|
|
98
|
+
default="medium",
|
|
99
|
+
description="Safe search level: 'off', 'medium', or 'high'"
|
|
100
|
+
)
|
|
101
|
+
|
|
102
|
+
@field_validator('safe_search')
|
|
103
|
+
@classmethod
|
|
104
|
+
def validate_safe_search(cls, v: str) -> str:
|
|
105
|
+
"""Validate safe search level"""
|
|
106
|
+
allowed = ['off', 'medium', 'high']
|
|
107
|
+
if v not in allowed:
|
|
108
|
+
raise ValueError(f"safe_search must be one of {allowed}")
|
|
109
|
+
return v
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
class SearchNewsSchema(BaseModel):
|
|
113
|
+
"""Schema for search_news operation"""
|
|
114
|
+
|
|
115
|
+
query: str = Field(
|
|
116
|
+
description="News search query string"
|
|
117
|
+
)
|
|
118
|
+
num_results: int = Field(
|
|
119
|
+
default=10,
|
|
120
|
+
ge=1,
|
|
121
|
+
le=100,
|
|
122
|
+
description="Number of news results to return (1-100)"
|
|
123
|
+
)
|
|
124
|
+
start_index: int = Field(
|
|
125
|
+
default=1,
|
|
126
|
+
ge=1,
|
|
127
|
+
le=91,
|
|
128
|
+
description="Starting index for pagination (1-91)"
|
|
129
|
+
)
|
|
130
|
+
language: str = Field(
|
|
131
|
+
default="en",
|
|
132
|
+
description="Language code for news articles (e.g., 'en', 'zh-CN', 'es')"
|
|
133
|
+
)
|
|
134
|
+
date_restrict: Optional[str] = Field(
|
|
135
|
+
default=None,
|
|
136
|
+
description="Date restriction (e.g., 'd7' for last 7 days, 'm1' for last month)"
|
|
137
|
+
)
|
|
138
|
+
sort_by: str = Field(
|
|
139
|
+
default="date",
|
|
140
|
+
description="Sort order: 'date' for newest first, 'relevance' for most relevant"
|
|
141
|
+
)
|
|
142
|
+
|
|
143
|
+
@field_validator('sort_by')
|
|
144
|
+
@classmethod
|
|
145
|
+
def validate_sort_by(cls, v: str) -> str:
|
|
146
|
+
"""Validate sort order"""
|
|
147
|
+
allowed = ['date', 'relevance']
|
|
148
|
+
if v not in allowed:
|
|
149
|
+
raise ValueError(f"sort_by must be one of {allowed}")
|
|
150
|
+
return v
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
class SearchVideosSchema(BaseModel):
|
|
154
|
+
"""Schema for search_videos operation"""
|
|
155
|
+
|
|
156
|
+
query: str = Field(
|
|
157
|
+
description="Video search query string"
|
|
158
|
+
)
|
|
159
|
+
num_results: int = Field(
|
|
160
|
+
default=10,
|
|
161
|
+
ge=1,
|
|
162
|
+
le=100,
|
|
163
|
+
description="Number of video results to return (1-100)"
|
|
164
|
+
)
|
|
165
|
+
start_index: int = Field(
|
|
166
|
+
default=1,
|
|
167
|
+
ge=1,
|
|
168
|
+
le=91,
|
|
169
|
+
description="Starting index for pagination (1-91)"
|
|
170
|
+
)
|
|
171
|
+
language: str = Field(
|
|
172
|
+
default="en",
|
|
173
|
+
description="Language code for videos (e.g., 'en', 'zh-CN', 'es')"
|
|
174
|
+
)
|
|
175
|
+
safe_search: str = Field(
|
|
176
|
+
default="medium",
|
|
177
|
+
description="Safe search level: 'off', 'medium', or 'high'"
|
|
178
|
+
)
|
|
179
|
+
|
|
180
|
+
@field_validator('safe_search')
|
|
181
|
+
@classmethod
|
|
182
|
+
def validate_safe_search(cls, v: str) -> str:
|
|
183
|
+
"""Validate safe search level"""
|
|
184
|
+
allowed = ['off', 'medium', 'high']
|
|
185
|
+
if v not in allowed:
|
|
186
|
+
raise ValueError(f"safe_search must be one of {allowed}")
|
|
187
|
+
return v
|
|
188
|
+
|
|
189
|
+
|
|
190
|
+
class SearchPaginatedSchema(BaseModel):
|
|
191
|
+
"""Schema for search_paginated operation"""
|
|
192
|
+
|
|
193
|
+
query: str = Field(
|
|
194
|
+
description="Search query string"
|
|
195
|
+
)
|
|
196
|
+
total_results: int = Field(
|
|
197
|
+
ge=1,
|
|
198
|
+
le=1000,
|
|
199
|
+
description="Total number of results to retrieve (1-1000)"
|
|
200
|
+
)
|
|
201
|
+
search_type: str = Field(
|
|
202
|
+
default="web",
|
|
203
|
+
description="Type of search: 'web', 'images', 'news', or 'videos'"
|
|
204
|
+
)
|
|
205
|
+
|
|
206
|
+
@field_validator('search_type')
|
|
207
|
+
@classmethod
|
|
208
|
+
def validate_search_type(cls, v: str) -> str:
|
|
209
|
+
"""Validate search type"""
|
|
210
|
+
allowed = ['web', 'images', 'news', 'videos']
|
|
211
|
+
if v not in allowed:
|
|
212
|
+
raise ValueError(f"search_type must be one of {allowed}")
|
|
213
|
+
return v
|
|
214
|
+
|
|
215
|
+
|
|
216
|
+
class SearchBatchSchema(BaseModel):
|
|
217
|
+
"""Schema for search_batch operation"""
|
|
218
|
+
|
|
219
|
+
queries: List[str] = Field(
|
|
220
|
+
description="List of search queries to execute in batch"
|
|
221
|
+
)
|
|
222
|
+
search_type: str = Field(
|
|
223
|
+
default="web",
|
|
224
|
+
description="Type of search: 'web', 'images', 'news', or 'videos'"
|
|
225
|
+
)
|
|
226
|
+
num_results: int = Field(
|
|
227
|
+
default=10,
|
|
228
|
+
ge=1,
|
|
229
|
+
le=100,
|
|
230
|
+
description="Number of results per query (1-100)"
|
|
231
|
+
)
|
|
232
|
+
|
|
233
|
+
@field_validator('queries')
|
|
234
|
+
@classmethod
|
|
235
|
+
def validate_queries(cls, v: List[str]) -> List[str]:
|
|
236
|
+
"""Validate queries list"""
|
|
237
|
+
if not v:
|
|
238
|
+
raise ValueError("queries list cannot be empty")
|
|
239
|
+
if len(v) > 50:
|
|
240
|
+
raise ValueError("Maximum 50 queries allowed in batch")
|
|
241
|
+
return v
|
|
242
|
+
|
|
243
|
+
@field_validator('search_type')
|
|
244
|
+
@classmethod
|
|
245
|
+
def validate_search_type(cls, v: str) -> str:
|
|
246
|
+
"""Validate search type"""
|
|
247
|
+
allowed = ['web', 'images', 'news', 'videos']
|
|
248
|
+
if v not in allowed:
|
|
249
|
+
raise ValueError(f"search_type must be one of {allowed}")
|
|
250
|
+
return v
|
|
251
|
+
|
|
252
|
+
|
|
253
|
+
class ValidateCredentialsSchema(BaseModel):
|
|
254
|
+
"""Schema for validate_credentials operation (no parameters required)"""
|
|
255
|
+
pass
|
|
256
|
+
|
|
257
|
+
|
|
258
|
+
class GetQuotaStatusSchema(BaseModel):
|
|
259
|
+
"""Schema for get_quota_status operation (no parameters required)"""
|
|
260
|
+
pass
|
|
261
|
+
|
|
262
|
+
|
|
263
|
+
class GetMetricsSchema(BaseModel):
|
|
264
|
+
"""Schema for get_metrics operation (no parameters required)"""
|
|
265
|
+
pass
|
|
266
|
+
|
|
267
|
+
|
|
268
|
+
class GetMetricsReportSchema(BaseModel):
|
|
269
|
+
"""Schema for get_metrics_report operation (no parameters required)"""
|
|
270
|
+
pass
|
|
271
|
+
|
|
272
|
+
|
|
273
|
+
class GetHealthScoreSchema(BaseModel):
|
|
274
|
+
"""Schema for get_health_score operation (no parameters required)"""
|
|
275
|
+
pass
|
|
276
|
+
|
|
277
|
+
|
|
278
|
+
class GetSearchContextSchema(BaseModel):
|
|
279
|
+
"""Schema for get_search_context operation (no parameters required)"""
|
|
280
|
+
pass
|
|
281
|
+
|
|
282
|
+
|
|
283
|
+
__all__ = [
|
|
284
|
+
'SearchWebSchema',
|
|
285
|
+
'SearchImagesSchema',
|
|
286
|
+
'SearchNewsSchema',
|
|
287
|
+
'SearchVideosSchema',
|
|
288
|
+
'SearchPaginatedSchema',
|
|
289
|
+
'SearchBatchSchema',
|
|
290
|
+
'ValidateCredentialsSchema',
|
|
291
|
+
'GetQuotaStatusSchema',
|
|
292
|
+
'GetMetricsSchema',
|
|
293
|
+
'GetMetricsReportSchema',
|
|
294
|
+
'GetHealthScoreSchema',
|
|
295
|
+
'GetSearchContextSchema',
|
|
296
|
+
]
|
|
297
|
+
|
|
@@ -151,7 +151,7 @@ class DataLoaderTool(BaseTool):
|
|
|
151
151
|
source: str = Field(description="Path to data source file")
|
|
152
152
|
source_type: Optional[DataSourceType] = Field(default=DataSourceType.AUTO, description="Data source type")
|
|
153
153
|
strategy: LoadStrategy = Field(default=LoadStrategy.FULL_LOAD, description="Loading strategy")
|
|
154
|
-
|
|
154
|
+
data_schema: Optional[Dict[str, Any]] = Field(default=None, description="Expected schema for validation")
|
|
155
155
|
validation_rules: Optional[Dict[str, Any]] = Field(default=None, description="Data quality validation rules")
|
|
156
156
|
nrows: Optional[int] = Field(default=None, description="Number of rows to load")
|
|
157
157
|
chunk_size: Optional[int] = Field(default=None, description="Chunk size for chunked loading")
|
|
@@ -164,7 +164,7 @@ class DataLoaderTool(BaseTool):
|
|
|
164
164
|
class ValidateSchemaSchema(BaseModel):
|
|
165
165
|
"""Schema for validate_schema operation"""
|
|
166
166
|
data: Union[Dict[str, Any], List[Dict[str, Any]]] = Field(description="Data to validate")
|
|
167
|
-
|
|
167
|
+
data_schema: Dict[str, Any] = Field(description="Expected schema")
|
|
168
168
|
|
|
169
169
|
class StreamDataSchema(BaseModel):
|
|
170
170
|
"""Schema for stream_data operation"""
|
|
@@ -149,7 +149,7 @@ class DataTransformerTool(BaseTool):
|
|
|
149
149
|
"""Schema for transform_data operation"""
|
|
150
150
|
data: Union[Dict[str, Any], List[Dict[str, Any]]] = Field(description="Data to transform")
|
|
151
151
|
transformations: List[Dict[str, Any]] = Field(description="List of transformation steps")
|
|
152
|
-
|
|
152
|
+
enable_validation: bool = Field(default=True, description="Validate transformations")
|
|
153
153
|
|
|
154
154
|
class AutoTransformSchema(BaseModel):
|
|
155
155
|
"""Schema for auto_transform operation"""
|
|
@@ -12,8 +12,11 @@ This module contains specialized tools for various task-oriented operations:
|
|
|
12
12
|
- report_tool: Report generation and formatting operations
|
|
13
13
|
- research_tool: Research and information gathering operations
|
|
14
14
|
- scraper_tool: Web scraping and data extraction operations
|
|
15
|
-
- search_api: Search API integration operations
|
|
16
15
|
- stats_tool: Statistical analysis and computation operations
|
|
16
|
+
|
|
17
|
+
Note:
|
|
18
|
+
- apisource_tool is now a standalone package at aiecs.tools.apisource
|
|
19
|
+
- search_tool is now a standalone package at aiecs.tools.search_tool
|
|
17
20
|
"""
|
|
18
21
|
|
|
19
22
|
# Lazy import all task tools to avoid heavy dependencies at import time
|
|
@@ -22,13 +25,12 @@ import os
|
|
|
22
25
|
# Define available tools for lazy loading
|
|
23
26
|
_AVAILABLE_TOOLS = [
|
|
24
27
|
'chart_tool',
|
|
25
|
-
'classfire_tool',
|
|
28
|
+
'classfire_tool',
|
|
26
29
|
'image_tool',
|
|
27
30
|
'pandas_tool',
|
|
28
31
|
'report_tool',
|
|
29
32
|
'research_tool',
|
|
30
33
|
'scraper_tool',
|
|
31
|
-
'search_api',
|
|
32
34
|
'stats_tool'
|
|
33
35
|
]
|
|
34
36
|
|
|
@@ -43,7 +45,7 @@ def _lazy_load_tool(tool_name: str):
|
|
|
43
45
|
"""Lazy load a specific tool module"""
|
|
44
46
|
if tool_name in _LOADED_TOOLS:
|
|
45
47
|
return
|
|
46
|
-
|
|
48
|
+
|
|
47
49
|
try:
|
|
48
50
|
if tool_name == 'chart_tool':
|
|
49
51
|
from . import chart_tool
|
|
@@ -61,13 +63,11 @@ def _lazy_load_tool(tool_name: str):
|
|
|
61
63
|
from . import research_tool
|
|
62
64
|
elif tool_name == 'scraper_tool':
|
|
63
65
|
from . import scraper_tool
|
|
64
|
-
elif tool_name == 'search_api':
|
|
65
|
-
from . import search_api
|
|
66
66
|
elif tool_name == 'stats_tool':
|
|
67
67
|
from . import stats_tool
|
|
68
|
-
|
|
68
|
+
|
|
69
69
|
_LOADED_TOOLS.add(tool_name)
|
|
70
|
-
|
|
70
|
+
|
|
71
71
|
except Exception as e:
|
|
72
72
|
import logging
|
|
73
73
|
logger = logging.getLogger(__name__)
|
|
@@ -19,7 +19,7 @@ from docx import Document
|
|
|
19
19
|
from docx.shared import Pt as DocxPt, RGBColor
|
|
20
20
|
import markdown
|
|
21
21
|
import matplotlib.pyplot as plt
|
|
22
|
-
from pydantic import ValidationError, ConfigDict, Field
|
|
22
|
+
from pydantic import BaseModel, ValidationError, ConfigDict, Field
|
|
23
23
|
import tempfile
|
|
24
24
|
import logging
|
|
25
25
|
|
|
@@ -12,6 +12,7 @@ from .tool_executor import (
|
|
|
12
12
|
get_executor,
|
|
13
13
|
validate_input,
|
|
14
14
|
cache_result,
|
|
15
|
+
cache_result_with_strategy,
|
|
15
16
|
run_in_executor,
|
|
16
17
|
measure_execution_time,
|
|
17
18
|
sanitize_input
|
|
@@ -29,6 +30,7 @@ __all__ = [
|
|
|
29
30
|
'get_executor',
|
|
30
31
|
'validate_input',
|
|
31
32
|
'cache_result',
|
|
33
|
+
'cache_result_with_strategy',
|
|
32
34
|
'run_in_executor',
|
|
33
35
|
'measure_execution_time',
|
|
34
36
|
'sanitize_input'
|