aigroup-econ-mcp 1.3.3__py3-none-any.whl → 1.4.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.
Files changed (120) hide show
  1. .gitignore +253 -0
  2. PKG-INFO +710 -0
  3. README.md +672 -0
  4. __init__.py +14 -0
  5. aigroup_econ_mcp-1.4.3.dist-info/METADATA +710 -0
  6. aigroup_econ_mcp-1.4.3.dist-info/RECORD +92 -0
  7. aigroup_econ_mcp-1.4.3.dist-info/entry_points.txt +2 -0
  8. aigroup_econ_mcp-1.4.3.dist-info/licenses/LICENSE +21 -0
  9. cli.py +28 -0
  10. econometrics/README.md +18 -0
  11. econometrics/__init__.py +191 -0
  12. econometrics/advanced_methods/modern_computing_machine_learning/__init__.py +0 -0
  13. econometrics/basic_parametric_estimation/__init__.py +31 -0
  14. econometrics/basic_parametric_estimation/gmm/__init__.py +13 -0
  15. econometrics/basic_parametric_estimation/gmm/gmm_model.py +256 -0
  16. econometrics/basic_parametric_estimation/mle/__init__.py +13 -0
  17. econometrics/basic_parametric_estimation/mle/mle_model.py +241 -0
  18. econometrics/basic_parametric_estimation/ols/__init__.py +13 -0
  19. econometrics/basic_parametric_estimation/ols/ols_model.py +141 -0
  20. econometrics/causal_inference/causal_identification_strategy/__init__.py +0 -0
  21. econometrics/missing_data/missing_data_measurement_error/__init__.py +0 -0
  22. econometrics/model_specification_diagnostics_robust_inference/README.md +173 -0
  23. econometrics/model_specification_diagnostics_robust_inference/__init__.py +78 -0
  24. econometrics/model_specification_diagnostics_robust_inference/diagnostic_tests/__init__.py +20 -0
  25. econometrics/model_specification_diagnostics_robust_inference/diagnostic_tests/diagnostic_tests_model.py +149 -0
  26. econometrics/model_specification_diagnostics_robust_inference/generalized_least_squares/__init__.py +15 -0
  27. econometrics/model_specification_diagnostics_robust_inference/generalized_least_squares/gls_model.py +130 -0
  28. econometrics/model_specification_diagnostics_robust_inference/model_selection/__init__.py +18 -0
  29. econometrics/model_specification_diagnostics_robust_inference/model_selection/model_selection_model.py +286 -0
  30. econometrics/model_specification_diagnostics_robust_inference/regularization/__init__.py +15 -0
  31. econometrics/model_specification_diagnostics_robust_inference/regularization/regularization_model.py +177 -0
  32. econometrics/model_specification_diagnostics_robust_inference/robust_errors/__init__.py +15 -0
  33. econometrics/model_specification_diagnostics_robust_inference/robust_errors/robust_errors_model.py +122 -0
  34. econometrics/model_specification_diagnostics_robust_inference/simultaneous_equations/__init__.py +15 -0
  35. econometrics/model_specification_diagnostics_robust_inference/simultaneous_equations/simultaneous_equations_model.py +246 -0
  36. econometrics/model_specification_diagnostics_robust_inference/weighted_least_squares/__init__.py +15 -0
  37. econometrics/model_specification_diagnostics_robust_inference/weighted_least_squares/wls_model.py +127 -0
  38. econometrics/nonparametric/nonparametric_semiparametric_methods/__init__.py +0 -0
  39. econometrics/spatial_econometrics/spatial_econometrics_new/__init__.py +0 -0
  40. econometrics/specific_data_modeling/micro_discrete_limited_data/__init__.py +0 -0
  41. econometrics/specific_data_modeling/survival_duration_data/__init__.py +0 -0
  42. econometrics/specific_data_modeling/time_series_panel_data/__init__.py +143 -0
  43. econometrics/specific_data_modeling/time_series_panel_data/arima_model.py +104 -0
  44. econometrics/specific_data_modeling/time_series_panel_data/cointegration_vecm.py +334 -0
  45. econometrics/specific_data_modeling/time_series_panel_data/dynamic_panel_models.py +653 -0
  46. econometrics/specific_data_modeling/time_series_panel_data/exponential_smoothing.py +176 -0
  47. econometrics/specific_data_modeling/time_series_panel_data/garch_model.py +198 -0
  48. econometrics/specific_data_modeling/time_series_panel_data/panel_diagnostics.py +125 -0
  49. econometrics/specific_data_modeling/time_series_panel_data/panel_var.py +60 -0
  50. econometrics/specific_data_modeling/time_series_panel_data/structural_break_tests.py +87 -0
  51. econometrics/specific_data_modeling/time_series_panel_data/time_varying_parameter_models.py +106 -0
  52. econometrics/specific_data_modeling/time_series_panel_data/unit_root_tests.py +204 -0
  53. econometrics/specific_data_modeling/time_series_panel_data/var_svar_model.py +372 -0
  54. econometrics/statistical_inference/statistical_inference_techniques/__init__.py +0 -0
  55. econometrics/statistics/distribution_decomposition_methods/__init__.py +0 -0
  56. econometrics/tests/basic_parametric_estimation_tests/__init__.py +3 -0
  57. econometrics/tests/basic_parametric_estimation_tests/test_gmm.py +128 -0
  58. econometrics/tests/basic_parametric_estimation_tests/test_mle.py +127 -0
  59. econometrics/tests/basic_parametric_estimation_tests/test_ols.py +100 -0
  60. econometrics/tests/model_specification_diagnostics_tests/__init__.py +3 -0
  61. econometrics/tests/model_specification_diagnostics_tests/test_diagnostic_tests.py +86 -0
  62. econometrics/tests/model_specification_diagnostics_tests/test_robust_errors.py +89 -0
  63. econometrics/tests/specific_data_modeling_tests/__init__.py +3 -0
  64. econometrics/tests/specific_data_modeling_tests/test_arima.py +98 -0
  65. econometrics/tests/specific_data_modeling_tests/test_dynamic_panel.py +198 -0
  66. econometrics/tests/specific_data_modeling_tests/test_exponential_smoothing.py +105 -0
  67. econometrics/tests/specific_data_modeling_tests/test_garch.py +118 -0
  68. econometrics/tests/specific_data_modeling_tests/test_unit_root.py +156 -0
  69. econometrics/tests/specific_data_modeling_tests/test_var.py +124 -0
  70. prompts/__init__.py +0 -0
  71. prompts/analysis_guides.py +43 -0
  72. pyproject.toml +78 -0
  73. resources/MCP_MASTER_GUIDE.md +422 -0
  74. resources/MCP_TOOLS_DATA_FORMAT_GUIDE.md +185 -0
  75. resources/__init__.py +0 -0
  76. server.py +83 -0
  77. tools/README.md +88 -0
  78. tools/__init__.py +45 -0
  79. tools/data_loader.py +213 -0
  80. tools/decorators.py +38 -0
  81. tools/econometrics_adapter.py +286 -0
  82. tools/mcp_tool_groups/__init__.py +1 -0
  83. tools/mcp_tool_groups/basic_parametric_tools.py +173 -0
  84. tools/mcp_tool_groups/model_specification_tools.py +402 -0
  85. tools/mcp_tool_groups/time_series_tools.py +494 -0
  86. tools/mcp_tools_registry.py +114 -0
  87. tools/model_specification_adapter.py +369 -0
  88. tools/output_formatter.py +563 -0
  89. tools/time_series_panel_data_adapter.py +858 -0
  90. tools/time_series_panel_data_tools.py +65 -0
  91. aigroup_econ_mcp/__init__.py +0 -19
  92. aigroup_econ_mcp/cli.py +0 -82
  93. aigroup_econ_mcp/config.py +0 -561
  94. aigroup_econ_mcp/server.py +0 -452
  95. aigroup_econ_mcp/tools/__init__.py +0 -19
  96. aigroup_econ_mcp/tools/base.py +0 -470
  97. aigroup_econ_mcp/tools/cache.py +0 -533
  98. aigroup_econ_mcp/tools/data_loader.py +0 -195
  99. aigroup_econ_mcp/tools/file_parser.py +0 -1027
  100. aigroup_econ_mcp/tools/machine_learning.py +0 -60
  101. aigroup_econ_mcp/tools/ml_ensemble.py +0 -210
  102. aigroup_econ_mcp/tools/ml_evaluation.py +0 -272
  103. aigroup_econ_mcp/tools/ml_models.py +0 -54
  104. aigroup_econ_mcp/tools/ml_regularization.py +0 -186
  105. aigroup_econ_mcp/tools/monitoring.py +0 -555
  106. aigroup_econ_mcp/tools/optimized_example.py +0 -229
  107. aigroup_econ_mcp/tools/panel_data.py +0 -619
  108. aigroup_econ_mcp/tools/regression.py +0 -214
  109. aigroup_econ_mcp/tools/statistics.py +0 -154
  110. aigroup_econ_mcp/tools/time_series.py +0 -698
  111. aigroup_econ_mcp/tools/timeout.py +0 -283
  112. aigroup_econ_mcp/tools/tool_descriptions.py +0 -410
  113. aigroup_econ_mcp/tools/tool_handlers.py +0 -1016
  114. aigroup_econ_mcp/tools/tool_registry.py +0 -478
  115. aigroup_econ_mcp/tools/validation.py +0 -482
  116. aigroup_econ_mcp-1.3.3.dist-info/METADATA +0 -525
  117. aigroup_econ_mcp-1.3.3.dist-info/RECORD +0 -30
  118. aigroup_econ_mcp-1.3.3.dist-info/entry_points.txt +0 -2
  119. /aigroup_econ_mcp-1.3.3.dist-info/licenses/LICENSE → /LICENSE +0 -0
  120. {aigroup_econ_mcp-1.3.3.dist-info → aigroup_econ_mcp-1.4.3.dist-info}/WHEEL +0 -0
@@ -1,283 +0,0 @@
1
- """
2
- 超时控制模块
3
- 为复杂计算任务提供超时控制和资源管理
4
- """
5
-
6
- import asyncio
7
- import signal
8
- import threading
9
- import time
10
- from typing import Any, Callable, Optional, TypeVar, Union
11
- from functools import wraps
12
- from contextlib import contextmanager
13
- import warnings
14
-
15
- T = TypeVar('T')
16
-
17
-
18
- class TimeoutError(Exception):
19
- """超时错误"""
20
- pass
21
-
22
-
23
- class TimeoutManager:
24
- """
25
- 超时管理器
26
- 提供同步和异步的超时控制
27
- """
28
-
29
- def __init__(self):
30
- self._timeout_config = {}
31
-
32
- def set_timeout_config(self, config: dict) -> None:
33
- """设置超时配置"""
34
- self._timeout_config = config
35
-
36
- def get_timeout_for_function(self, function_name: str, default: int = 60) -> int:
37
- """获取函数的超时时间"""
38
- # 从配置中获取超时时间
39
- if function_name in self._timeout_config:
40
- return self._timeout_config[function_name]
41
-
42
- # 根据函数类型返回默认超时
43
- if function_name.startswith(('descriptive_', 'correlation_')):
44
- return 30
45
- elif function_name.startswith(('ols_', 'hypothesis_')):
46
- return 60
47
- elif function_name.startswith(('time_series_', 'panel_')):
48
- return 120
49
- elif function_name.startswith(('var_', 'vecm_', 'garch_')):
50
- return 180
51
- elif function_name.startswith(('random_forest_', 'gradient_boosting_')):
52
- return 300
53
- else:
54
- return default
55
-
56
- async def execute_with_timeout(self, model_name: str, timeout_seconds: int, func: callable, *args, **kwargs):
57
- """使用超时执行函数"""
58
- try:
59
- if asyncio.iscoroutinefunction(func):
60
- # 异步函数
61
- return await asyncio.wait_for(
62
- func(*args, **kwargs),
63
- timeout=timeout_seconds
64
- )
65
- else:
66
- # 同步函数 - 在线程池中执行
67
- loop = asyncio.get_event_loop()
68
- return await loop.run_in_executor(
69
- None,
70
- lambda: self._execute_sync_with_timeout(func, timeout_seconds, *args, **kwargs)
71
- )
72
- except asyncio.TimeoutError:
73
- raise TimeoutError(f"模型 '{model_name}' 执行超时 ({timeout_seconds}秒)")
74
-
75
- def _execute_sync_with_timeout(self, func: callable, timeout_seconds: int, *args, **kwargs):
76
- """同步函数超时执行"""
77
- import threading
78
- import queue
79
-
80
- result_queue = queue.Queue()
81
- exception_queue = queue.Queue()
82
-
83
- def worker():
84
- try:
85
- result = func(*args, **kwargs)
86
- result_queue.put(result)
87
- except Exception as e:
88
- exception_queue.put(e)
89
-
90
- thread = threading.Thread(target=worker)
91
- thread.daemon = True
92
- thread.start()
93
- thread.join(timeout_seconds)
94
-
95
- if thread.is_alive():
96
- raise TimeoutError(f"同步函数执行超时 ({timeout_seconds}秒)")
97
-
98
- if not exception_queue.empty():
99
- raise exception_queue.get()
100
-
101
- return result_queue.get()
102
-
103
- @contextmanager
104
- def timeout_context(self, seconds: int):
105
- """
106
- 同步超时上下文管理器
107
-
108
- Args:
109
- seconds: 超时时间(秒)
110
- """
111
- def timeout_handler(signum, frame):
112
- raise TimeoutError(f"操作超时 ({seconds}秒)")
113
-
114
- # 设置信号处理(仅适用于Unix系统)
115
- original_handler = signal.signal(signal.SIGALRM, timeout_handler)
116
- signal.alarm(seconds)
117
-
118
- try:
119
- yield
120
- finally:
121
- # 取消警报
122
- signal.alarm(0)
123
- signal.signal(signal.SIGALRM, original_handler)
124
-
125
- async def async_timeout_context(self, seconds: int):
126
- """
127
- 异步超时上下文管理器
128
-
129
- Args:
130
- seconds: 超时时间(秒)
131
- """
132
- try:
133
- await asyncio.wait_for(asyncio.sleep(0), timeout=seconds)
134
- except asyncio.TimeoutError:
135
- raise TimeoutError(f"异步操作超时 ({seconds}秒)")
136
-
137
-
138
- def timeout(seconds: int = 60):
139
- """
140
- 同步函数超时装饰器
141
-
142
- Args:
143
- seconds: 超时时间(秒)
144
- """
145
- def decorator(func):
146
- @wraps(func)
147
- def wrapper(*args, **kwargs):
148
- manager = TimeoutManager()
149
-
150
- # 在Windows上使用线程实现超时
151
- if hasattr(signal, 'SIGALRM'):
152
- # Unix系统使用信号
153
- with manager.timeout_context(seconds):
154
- return func(*args, **kwargs)
155
- else:
156
- # Windows系统使用线程
157
- result = [None]
158
- exception = [None]
159
-
160
- def target():
161
- try:
162
- result[0] = func(*args, **kwargs)
163
- except Exception as e:
164
- exception[0] = e
165
-
166
- thread = threading.Thread(target=target)
167
- thread.daemon = True
168
- thread.start()
169
- thread.join(seconds)
170
-
171
- if thread.is_alive():
172
- raise TimeoutError(f"函数 {func.__name__} 执行超时 ({seconds}秒)")
173
-
174
- if exception[0]:
175
- raise exception[0]
176
-
177
- return result[0]
178
-
179
- return wrapper
180
- return decorator
181
-
182
-
183
- def async_timeout(seconds: int = 60):
184
- """
185
- 异步函数超时装饰器
186
-
187
- Args:
188
- seconds: 超时时间(秒)
189
- """
190
- def decorator(func):
191
- @wraps(func)
192
- async def wrapper(*args, **kwargs):
193
- try:
194
- return await asyncio.wait_for(
195
- func(*args, **kwargs),
196
- timeout=seconds
197
- )
198
- except asyncio.TimeoutError:
199
- raise TimeoutError(f"异步函数 {func.__name__} 执行超时 ({seconds}秒)")
200
-
201
- return wrapper
202
- return decorator
203
-
204
-
205
- class ResourceMonitor:
206
- """
207
- 资源监控器
208
- 监控内存和CPU使用情况
209
- """
210
-
211
- def __init__(self):
212
- self._start_time = None
213
- self._peak_memory = 0
214
-
215
- @contextmanager
216
- def monitor_resources(self):
217
- """监控资源使用的上下文管理器"""
218
- import psutil
219
- import os
220
-
221
- process = psutil.Process(os.getpid())
222
- self._start_time = time.time()
223
- initial_memory = process.memory_info().rss
224
-
225
- try:
226
- yield
227
- finally:
228
- current_memory = process.memory_info().rss
229
- memory_increase = (current_memory - initial_memory) / 1024 / 1024 # MB
230
-
231
- execution_time = time.time() - self._start_time
232
-
233
- # 记录资源使用情况
234
- if memory_increase > 100: # 超过100MB
235
- warnings.warn(
236
- f"高内存使用警告: 内存增加 {memory_increase:.2f}MB, "
237
- f"执行时间: {execution_time:.2f}秒"
238
- )
239
-
240
-
241
- # 全局超时管理器实例
242
- global_timeout_manager = TimeoutManager()
243
-
244
-
245
- # 便捷装饰器
246
- def with_timeout(seconds: int = 60):
247
- """便捷超时装饰器,自动选择同步或异步"""
248
- def decorator(func):
249
- if asyncio.iscoroutinefunction(func):
250
- return async_timeout(seconds)(func)
251
- else:
252
- return timeout(seconds)(func)
253
- return decorator
254
-
255
-
256
- def econometric_timeout(function_name: str = None):
257
- """
258
- 计量经济学专用超时装饰器
259
- 根据函数类型自动设置合适的超时时间
260
- """
261
- def decorator(func):
262
- name = function_name or func.__name__
263
- timeout_seconds = global_timeout_manager.get_timeout_for_function(name)
264
-
265
- if asyncio.iscoroutinefunction(func):
266
- return async_timeout(timeout_seconds)(func)
267
- else:
268
- return timeout(timeout_seconds)(func)
269
-
270
- return decorator
271
-
272
-
273
- # 导出主要类和函数
274
- __all__ = [
275
- "TimeoutError",
276
- "TimeoutManager",
277
- "timeout",
278
- "async_timeout",
279
- "with_timeout",
280
- "econometric_timeout",
281
- "ResourceMonitor",
282
- "global_timeout_manager"
283
- ]
@@ -1,410 +0,0 @@
1
- """
2
- 工具描述模块 - 优化版
3
- 统一管理所有MCP工具的描述信息,为大模型提供详细、结构化的工具说明
4
- 包含使用示例、参数说明、适用场景等信息,提升大模型调用体验
5
- """
6
-
7
- from typing import Dict, Any, List, Optional
8
- from pydantic import Field
9
-
10
-
11
- class ToolDescription:
12
- """工具描述类 - 优化版"""
13
-
14
- def __init__(self, name: str, description: str, field_descriptions: Dict[str, str] = None,
15
- examples: Optional[List[str]] = None, use_cases: Optional[List[str]] = None):
16
- self.name = name
17
- self.description = description
18
- self.field_descriptions = field_descriptions or {}
19
- self.examples = examples or []
20
- self.use_cases = use_cases or []
21
-
22
- def get_field_description(self, field_name: str, default: str = "") -> str:
23
- """获取字段描述"""
24
- return self.field_descriptions.get(field_name, default)
25
-
26
- def get_full_description(self) -> str:
27
- """获取完整描述,包含示例和用例"""
28
- full_desc = self.description
29
- if self.examples:
30
- full_desc += "\n\n使用示例:\n" + "\n".join(f"- {example}" for example in self.examples)
31
- if self.use_cases:
32
- full_desc += "\n\n适用场景:\n" + "\n".join(f"- {use_case}" for use_case in self.use_cases)
33
- return full_desc
34
-
35
-
36
- # ============================================================================
37
- # 基础统计工具描述 (5个)
38
- # ============================================================================
39
-
40
- DESCRIPTIVE_STATISTICS = ToolDescription(
41
- name="descriptive_statistics",
42
- description="""计算描述性统计量
43
-
44
- 支持三种输入方式:file_path(文件路径)、file_content(文件内容)、data(直接数据)
45
- 支持格式:CSV、JSON、TXT(单列/多列/键值对三种格式)""",
46
- field_descriptions={
47
- "file_path": "CSV/JSON/TXT文件路径",
48
- "file_content": "CSV/JSON/TXT文件内容",
49
- "file_format": "文件格式(csv/json/txt/auto)",
50
- "data": "数据字典"
51
- }
52
- )
53
-
54
- OLS_REGRESSION = ToolDescription(
55
- name="ols_regression",
56
- description="""OLS回归分析
57
-
58
- 支持文件输入或直接数据输入。文件格式示例:
59
- CSV: 最后一列为因变量,其余列为自变量""",
60
- field_descriptions={
61
- "file_path": "CSV/JSON/TXT文件路径",
62
- "file_content": "CSV/JSON/TXT文件内容",
63
- "file_format": "文件格式",
64
- "y_data": "因变量(直接输入)",
65
- "x_data": "自变量(直接输入)",
66
- "feature_names": "特征名称"
67
- }
68
- )
69
-
70
- HYPOTHESIS_TESTING = ToolDescription(
71
- name="hypothesis_testing",
72
- description="假设检验 - 支持文件或直接数据输入",
73
- field_descriptions={
74
- "file_path": "文件路径",
75
- "file_content": "文件内容",
76
- "file_format": "文件格式",
77
- "data": "第一组数据",
78
- "data2": "第二组数据",
79
- "test_type": "检验类型(t_test/adf)"
80
- }
81
- )
82
-
83
- TIME_SERIES_ANALYSIS = ToolDescription(
84
- name="time_series_analysis",
85
- description="时间序列分析 - 支持文件或直接数据输入",
86
- field_descriptions={
87
- "file_path": "文件路径",
88
- "file_content": "文件内容",
89
- "file_format": "文件格式",
90
- "data": "时间序列数据"
91
- }
92
- )
93
-
94
- CORRELATION_ANALYSIS = ToolDescription(
95
- name="correlation_analysis",
96
- description="相关性分析 - 支持文件或直接数据输入",
97
- field_descriptions={
98
- "file_path": "文件路径",
99
- "file_content": "文件内容",
100
- "file_format": "文件格式",
101
- "data": "多变量数据",
102
- "method": "相关系数类型"
103
- }
104
- )
105
-
106
-
107
- # ============================================================================
108
- # 面板数据工具描述 (4个)
109
- # ============================================================================
110
-
111
- PANEL_FIXED_EFFECTS = ToolDescription(
112
- name="panel_fixed_effects",
113
- description="固定效应模型 - 支持文件输入",
114
- field_descriptions={
115
- "file_path": "CSV文件路径。CSV格式要求:必须包含实体ID列(列名含entity_id/id/entity/firm/company/country/region之一)和时间列(列名含time_period/time/date/year/month/period/quarter之一)",
116
- "file_content": "CSV/JSON/TXT文件内容字符串",
117
- "file_format": "文件格式(csv/json/txt/auto)。面板数据推荐使用CSV格式",
118
- "y_data": "因变量数据列表,数值格式",
119
- "x_data": "自变量数据矩阵,二维列表格式",
120
- "entity_ids": "实体ID列表,字符串格式,如 ['A', 'B', 'C', ...]",
121
- "time_periods": "时间周期列表,字符串格式,如 ['2020', '2021', '2022', ...]",
122
- "feature_names": "自变量名称列表,如 ['Investment', 'Employment', 'R&D']",
123
- "entity_effects": "是否包含实体固定效应,默认True",
124
- "time_effects": "是否包含时间固定效应,默认False"
125
- }
126
- )
127
-
128
- PANEL_RANDOM_EFFECTS = ToolDescription(
129
- name="panel_random_effects",
130
- description="随机效应模型 - 支持文件输入",
131
- field_descriptions={
132
- "file_path": "CSV文件路径。CSV格式要求:必须包含实体ID列和时间列",
133
- "file_content": "CSV/JSON/TXT文件内容字符串",
134
- "file_format": "文件格式(csv/json/txt/auto)",
135
- "y_data": "因变量数据列表,数值格式",
136
- "x_data": "自变量数据矩阵,二维列表格式",
137
- "entity_ids": "实体ID列表,字符串格式",
138
- "time_periods": "时间周期列表,字符串格式",
139
- "feature_names": "自变量名称列表",
140
- "entity_effects": "是否包含实体随机效应,默认True",
141
- "time_effects": "是否包含时间随机效应,默认False"
142
- }
143
- )
144
-
145
- PANEL_HAUSMAN_TEST = ToolDescription(
146
- name="panel_hausman_test",
147
- description="Hausman检验 - 支持文件输入",
148
- field_descriptions={
149
- "file_path": "CSV文件路径。CSV格式要求:必须包含实体ID列和时间列",
150
- "file_content": "CSV/JSON/TXT文件内容字符串",
151
- "file_format": "文件格式(csv/json/txt/auto)",
152
- "y_data": "因变量数据列表",
153
- "x_data": "自变量数据矩阵",
154
- "entity_ids": "实体ID列表",
155
- "time_periods": "时间周期列表",
156
- "feature_names": "自变量名称列表"
157
- }
158
- )
159
-
160
- PANEL_UNIT_ROOT_TEST = ToolDescription(
161
- name="panel_unit_root_test",
162
- description="面板单位根检验 - 支持文件输入",
163
- field_descriptions={
164
- "file_path": "CSV文件路径。CSV格式要求:必须包含实体ID列和时间列。数据量要求:至少3个实体,每个实体至少5个时间点",
165
- "file_content": "CSV/JSON/TXT文件内容字符串",
166
- "file_format": "文件格式(csv/json/txt/auto)",
167
- "data": "面板数据(从文件解析后的数据)",
168
- "y_data": "需要检验的变量数据",
169
- "x_data": "自变量数据(通常不用)",
170
- "entity_ids": "实体ID列表",
171
- "time_periods": "时间周期列表",
172
- "feature_names": "变量名称列表",
173
- "test_type": "检验类型(levinlin/ips/adf)"
174
- }
175
- )
176
-
177
-
178
- # ============================================================================
179
- # 高级时间序列工具描述 (5个)
180
- # ============================================================================
181
-
182
- VAR_MODEL_ANALYSIS = ToolDescription(
183
- name="var_model_analysis",
184
- description="VAR模型分析 - 支持文件输入",
185
- field_descriptions={
186
- "file_path": "CSV/JSON/TXT文件路径,包含多个时间序列变量",
187
- "file_content": "CSV/JSON/TXT文件内容字符串",
188
- "file_format": "文件格式(csv/json/txt/auto)",
189
- "data": "多变量时间序列数据字典",
190
- "max_lags": "最大滞后阶数,默认5",
191
- "ic": "信息准则(aic/bic/hqic),默认aic"
192
- }
193
- )
194
-
195
- VECM_MODEL_ANALYSIS = ToolDescription(
196
- name="vecm_model_analysis",
197
- description="VECM模型分析 - 支持文件输入",
198
- field_descriptions={
199
- "file_path": "CSV/JSON/TXT文件路径,包含协整的时间序列变量",
200
- "file_content": "CSV/JSON/TXT文件内容字符串",
201
- "file_format": "文件格式(csv/json/txt/auto)",
202
- "data": "多变量时间序列数据字典",
203
- "coint_rank": "协整秩,默认1",
204
- "deterministic": "确定性项(co/ci/lo/li),默认co",
205
- "max_lags": "最大滞后阶数,默认5"
206
- }
207
- )
208
-
209
- GARCH_MODEL_ANALYSIS = ToolDescription(
210
- name="garch_model_analysis",
211
- description="GARCH模型分析 - 支持文件输入",
212
- field_descriptions={
213
- "file_path": "CSV/JSON/TXT文件路径,包含单个时间序列",
214
- "file_content": "CSV/JSON/TXT文件内容字符串",
215
- "file_format": "文件格式(csv/json/txt/auto)",
216
- "data": "时间序列数据",
217
- "order": "GARCH阶数(p,q),默认(1,1)",
218
- "dist": "误差分布(normal/t/skewt),默认normal"
219
- }
220
- )
221
-
222
- STATE_SPACE_MODEL_ANALYSIS = ToolDescription(
223
- name="state_space_model_analysis",
224
- description="状态空间模型分析 - 支持文件输入",
225
- field_descriptions={
226
- "file_path": "CSV/JSON/TXT文件路径,包含时间序列数据",
227
- "file_content": "CSV/JSON/TXT文件内容字符串",
228
- "file_format": "文件格式(csv/json/txt/auto)",
229
- "data": "时间序列数据",
230
- "state_dim": "状态维度,默认1",
231
- "observation_dim": "观测维度,默认1",
232
- "trend": "是否包含趋势项,默认True",
233
- "seasonal": "是否包含季节项,默认False",
234
- "period": "季节周期,默认12"
235
- }
236
- )
237
-
238
- VARIANCE_DECOMPOSITION_ANALYSIS = ToolDescription(
239
- name="variance_decomposition_analysis",
240
- description="方差分解分析 - 支持文件输入",
241
- field_descriptions={
242
- "file_path": "CSV/JSON/TXT文件路径,包含多个时间序列变量",
243
- "file_content": "CSV/JSON/TXT文件内容字符串",
244
- "file_format": "文件格式(csv/json/txt/auto)",
245
- "data": "多变量时间序列数据字典",
246
- "periods": "预测期数,默认10",
247
- "max_lags": "最大滞后阶数,默认5"
248
- }
249
- )
250
-
251
-
252
- # ============================================================================
253
- # 机器学习工具描述 (6个)
254
- # ============================================================================
255
-
256
- RANDOM_FOREST_REGRESSION_ANALYSIS = ToolDescription(
257
- name="random_forest_regression_analysis",
258
- description="随机森林回归 - 支持文件输入",
259
- field_descriptions={
260
- "file_path": "CSV/JSON/TXT文件路径,最后一列为因变量",
261
- "file_content": "CSV/JSON/TXT文件内容字符串",
262
- "file_format": "文件格式(csv/json/txt/auto)",
263
- "y_data": "因变量数据",
264
- "x_data": "自变量数据矩阵",
265
- "feature_names": "特征名称列表",
266
- "n_estimators": "树的数量,默认100",
267
- "max_depth": "树的最大深度,默认None(不限制)"
268
- }
269
- )
270
-
271
- GRADIENT_BOOSTING_REGRESSION_ANALYSIS = ToolDescription(
272
- name="gradient_boosting_regression_analysis",
273
- description="梯度提升树回归 - 支持文件输入",
274
- field_descriptions={
275
- "file_path": "CSV/JSON/TXT文件路径,最后一列为因变量",
276
- "file_content": "CSV/JSON/TXT文件内容字符串",
277
- "file_format": "文件格式(csv/json/txt/auto)",
278
- "y_data": "因变量数据",
279
- "x_data": "自变量数据矩阵",
280
- "feature_names": "特征名称列表",
281
- "n_estimators": "提升轮数,默认100",
282
- "learning_rate": "学习率,默认0.1",
283
- "max_depth": "树的最大深度,默认3"
284
- }
285
- )
286
-
287
- LASSO_REGRESSION_ANALYSIS = ToolDescription(
288
- name="lasso_regression_analysis",
289
- description="Lasso回归 - 支持文件输入",
290
- field_descriptions={
291
- "file_path": "CSV/JSON/TXT文件路径,最后一列为因变量",
292
- "file_content": "CSV/JSON/TXT文件内容字符串",
293
- "file_format": "文件格式(csv/json/txt/auto)",
294
- "y_data": "因变量数据",
295
- "x_data": "自变量数据矩阵",
296
- "feature_names": "特征名称列表",
297
- "alpha": "正则化强度,默认1.0"
298
- }
299
- )
300
-
301
- RIDGE_REGRESSION_ANALYSIS = ToolDescription(
302
- name="ridge_regression_analysis",
303
- description="Ridge回归 - 支持文件输入",
304
- field_descriptions={
305
- "file_path": "CSV/JSON/TXT文件路径,最后一列为因变量",
306
- "file_content": "CSV/JSON/TXT文件内容字符串",
307
- "file_format": "文件格式(csv/json/txt/auto)",
308
- "y_data": "因变量数据",
309
- "x_data": "自变量数据矩阵",
310
- "feature_names": "特征名称列表",
311
- "alpha": "正则化强度,默认1.0"
312
- }
313
- )
314
-
315
- CROSS_VALIDATION_ANALYSIS = ToolDescription(
316
- name="cross_validation_analysis",
317
- description="交叉验证 - 支持文件输入",
318
- field_descriptions={
319
- "file_path": "CSV/JSON/TXT文件路径,最后一列为因变量",
320
- "file_content": "CSV/JSON/TXT文件内容字符串",
321
- "file_format": "文件格式(csv/json/txt/auto)",
322
- "y_data": "因变量数据",
323
- "x_data": "自变量数据矩阵",
324
- "feature_names": "特征名称列表",
325
- "model_type": "模型类型(random_forest/gradient_boosting/lasso/ridge),默认random_forest",
326
- "cv_folds": "交叉验证折数,默认5",
327
- "scoring": "评分指标(r2/mse/mae),默认r2"
328
- }
329
- )
330
-
331
- FEATURE_IMPORTANCE_ANALYSIS_TOOL = ToolDescription(
332
- name="feature_importance_analysis_tool",
333
- description="特征重要性分析 - 支持文件输入",
334
- field_descriptions={
335
- "file_path": "CSV/JSON/TXT文件路径,最后一列为因变量",
336
- "file_content": "CSV/JSON/TXT文件内容字符串",
337
- "file_format": "文件格式(csv/json/txt/auto)",
338
- "y_data": "因变量数据",
339
- "x_data": "自变量数据矩阵",
340
- "feature_names": "特征名称列表",
341
- "method": "分析方法(random_forest/gradient_boosting/permutation),默认random_forest",
342
- "top_k": "返回前K个重要特征,默认5"
343
- }
344
- )
345
-
346
-
347
- # ============================================================================
348
- # 辅助函数
349
- # ============================================================================
350
-
351
- def get_tool_description(tool_name: str) -> str:
352
- """获取工具描述"""
353
- tool_map = {
354
- "descriptive_statistics": DESCRIPTIVE_STATISTICS,
355
- "ols_regression": OLS_REGRESSION,
356
- "hypothesis_testing": HYPOTHESIS_TESTING,
357
- "time_series_analysis": TIME_SERIES_ANALYSIS,
358
- "correlation_analysis": CORRELATION_ANALYSIS,
359
- "panel_fixed_effects": PANEL_FIXED_EFFECTS,
360
- "panel_random_effects": PANEL_RANDOM_EFFECTS,
361
- "panel_hausman_test": PANEL_HAUSMAN_TEST,
362
- "panel_unit_root_test": PANEL_UNIT_ROOT_TEST,
363
- "var_model_analysis": VAR_MODEL_ANALYSIS,
364
- "vecm_model_analysis": VECM_MODEL_ANALYSIS,
365
- "garch_model_analysis": GARCH_MODEL_ANALYSIS,
366
- "state_space_model_analysis": STATE_SPACE_MODEL_ANALYSIS,
367
- "variance_decomposition_analysis": VARIANCE_DECOMPOSITION_ANALYSIS,
368
- "random_forest_regression_analysis": RANDOM_FOREST_REGRESSION_ANALYSIS,
369
- "gradient_boosting_regression_analysis": GRADIENT_BOOSTING_REGRESSION_ANALYSIS,
370
- "lasso_regression_analysis": LASSO_REGRESSION_ANALYSIS,
371
- "ridge_regression_analysis": RIDGE_REGRESSION_ANALYSIS,
372
- "cross_validation_analysis": CROSS_VALIDATION_ANALYSIS,
373
- "feature_importance_analysis_tool": FEATURE_IMPORTANCE_ANALYSIS_TOOL
374
- }
375
-
376
- tool = tool_map.get(tool_name)
377
- if tool:
378
- return tool.get_full_description()
379
- return ""
380
-
381
-
382
- def get_field_description(tool_name: str, field_name: str, default: str = "") -> str:
383
- """获取字段描述"""
384
- tool_map = {
385
- "descriptive_statistics": DESCRIPTIVE_STATISTICS,
386
- "ols_regression": OLS_REGRESSION,
387
- "hypothesis_testing": HYPOTHESIS_TESTING,
388
- "time_series_analysis": TIME_SERIES_ANALYSIS,
389
- "correlation_analysis": CORRELATION_ANALYSIS,
390
- "panel_fixed_effects": PANEL_FIXED_EFFECTS,
391
- "panel_random_effects": PANEL_RANDOM_EFFECTS,
392
- "panel_hausman_test": PANEL_HAUSMAN_TEST,
393
- "panel_unit_root_test": PANEL_UNIT_ROOT_TEST,
394
- "var_model_analysis": VAR_MODEL_ANALYSIS,
395
- "vecm_model_analysis": VECM_MODEL_ANALYSIS,
396
- "garch_model_analysis": GARCH_MODEL_ANALYSIS,
397
- "state_space_model_analysis": STATE_SPACE_MODEL_ANALYSIS,
398
- "variance_decomposition_analysis": VARIANCE_DECOMPOSITION_ANALYSIS,
399
- "random_forest_regression_analysis": RANDOM_FOREST_REGRESSION_ANALYSIS,
400
- "gradient_boosting_regression_analysis": GRADIENT_BOOSTING_REGRESSION_ANALYSIS,
401
- "lasso_regression_analysis": LASSO_REGRESSION_ANALYSIS,
402
- "ridge_regression_analysis": RIDGE_REGRESSION_ANALYSIS,
403
- "cross_validation_analysis": CROSS_VALIDATION_ANALYSIS,
404
- "feature_importance_analysis_tool": FEATURE_IMPORTANCE_ANALYSIS_TOOL
405
- }
406
-
407
- tool = tool_map.get(tool_name)
408
- if tool:
409
- return tool.get_field_description(field_name, default)
410
- return default