ds-agent-cli 0.1.0

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 (67) hide show
  1. package/bin/ds-agent.js +451 -0
  2. package/ds_agent/__init__.py +8 -0
  3. package/package.json +28 -0
  4. package/requirements.txt +126 -0
  5. package/setup.py +35 -0
  6. package/src/__init__.py +7 -0
  7. package/src/_compress_tool_result.py +118 -0
  8. package/src/api/__init__.py +4 -0
  9. package/src/api/app.py +1626 -0
  10. package/src/cache/__init__.py +5 -0
  11. package/src/cache/cache_manager.py +561 -0
  12. package/src/cli.py +2886 -0
  13. package/src/dynamic_prompts.py +281 -0
  14. package/src/orchestrator.py +4799 -0
  15. package/src/progress_manager.py +139 -0
  16. package/src/reasoning/__init__.py +332 -0
  17. package/src/reasoning/business_summary.py +431 -0
  18. package/src/reasoning/data_understanding.py +356 -0
  19. package/src/reasoning/model_explanation.py +383 -0
  20. package/src/reasoning/reasoning_trace.py +239 -0
  21. package/src/registry/__init__.py +3 -0
  22. package/src/registry/tools_registry.py +3 -0
  23. package/src/session_memory.py +448 -0
  24. package/src/session_store.py +370 -0
  25. package/src/storage/__init__.py +19 -0
  26. package/src/storage/artifact_store.py +620 -0
  27. package/src/storage/helpers.py +116 -0
  28. package/src/storage/huggingface_storage.py +694 -0
  29. package/src/storage/r2_storage.py +0 -0
  30. package/src/storage/user_files_service.py +288 -0
  31. package/src/tools/__init__.py +335 -0
  32. package/src/tools/advanced_analysis.py +823 -0
  33. package/src/tools/advanced_feature_engineering.py +708 -0
  34. package/src/tools/advanced_insights.py +578 -0
  35. package/src/tools/advanced_preprocessing.py +549 -0
  36. package/src/tools/advanced_training.py +906 -0
  37. package/src/tools/agent_tool_mapping.py +326 -0
  38. package/src/tools/auto_pipeline.py +420 -0
  39. package/src/tools/autogluon_training.py +1480 -0
  40. package/src/tools/business_intelligence.py +860 -0
  41. package/src/tools/cloud_data_sources.py +581 -0
  42. package/src/tools/code_interpreter.py +390 -0
  43. package/src/tools/computer_vision.py +614 -0
  44. package/src/tools/data_cleaning.py +614 -0
  45. package/src/tools/data_profiling.py +593 -0
  46. package/src/tools/data_type_conversion.py +268 -0
  47. package/src/tools/data_wrangling.py +433 -0
  48. package/src/tools/eda_reports.py +284 -0
  49. package/src/tools/enhanced_feature_engineering.py +241 -0
  50. package/src/tools/feature_engineering.py +302 -0
  51. package/src/tools/matplotlib_visualizations.py +1327 -0
  52. package/src/tools/model_training.py +520 -0
  53. package/src/tools/nlp_text_analytics.py +761 -0
  54. package/src/tools/plotly_visualizations.py +497 -0
  55. package/src/tools/production_mlops.py +852 -0
  56. package/src/tools/time_series.py +507 -0
  57. package/src/tools/tools_registry.py +2133 -0
  58. package/src/tools/visualization_engine.py +559 -0
  59. package/src/utils/__init__.py +42 -0
  60. package/src/utils/error_recovery.py +313 -0
  61. package/src/utils/parallel_executor.py +402 -0
  62. package/src/utils/polars_helpers.py +248 -0
  63. package/src/utils/schema_extraction.py +132 -0
  64. package/src/utils/semantic_layer.py +392 -0
  65. package/src/utils/token_budget.py +411 -0
  66. package/src/utils/validation.py +377 -0
  67. package/src/workflow_state.py +154 -0
@@ -0,0 +1,326 @@
1
+ """
2
+ Agent-Specific Tool Mapping
3
+ Maps specialist agents to their relevant tools for dynamic loading.
4
+ """
5
+
6
+ from ds_agent.registry.tools_registry import TOOLS
7
+
8
+ # Define tool categories and their tools
9
+ TOOL_CATEGORIES = {
10
+ "profiling": [
11
+ "profile_dataset",
12
+ "detect_data_quality_issues",
13
+ "analyze_correlations",
14
+ "get_smart_summary",
15
+ ],
16
+ "cleaning": [
17
+ "clean_missing_values",
18
+ "handle_outliers",
19
+ "fix_data_types",
20
+ "force_numeric_conversion",
21
+ "smart_type_inference",
22
+ "remove_duplicates",
23
+ ],
24
+ "feature_engineering": [
25
+ "create_time_features",
26
+ "encode_categorical",
27
+ "create_interaction_features",
28
+ "create_ratio_features",
29
+ "create_statistical_features",
30
+ "create_log_features",
31
+ "create_binned_features",
32
+ "create_aggregation_features",
33
+ "auto_feature_engineering",
34
+ ],
35
+ "visualization": [
36
+ "generate_interactive_scatter",
37
+ "generate_interactive_histogram",
38
+ "generate_interactive_box_plots",
39
+ "generate_interactive_correlation_heatmap",
40
+ "generate_interactive_time_series",
41
+ "generate_plotly_dashboard",
42
+ "generate_eda_plots",
43
+ "generate_combined_eda_report",
44
+ ],
45
+ "modeling": [
46
+ "train_baseline_models",
47
+ "train_with_autogluon",
48
+ "predict_with_autogluon",
49
+ "optimize_autogluon_model",
50
+ "analyze_autogluon_model",
51
+ "extend_autogluon_training",
52
+ "train_multilabel_autogluon",
53
+ "hyperparameter_tuning",
54
+ "perform_cross_validation",
55
+ "train_ensemble_models",
56
+ "auto_ml_pipeline",
57
+ "evaluate_model_performance",
58
+ ],
59
+ "time_series": [
60
+ "detect_seasonality",
61
+ "decompose_time_series",
62
+ "forecast_arima",
63
+ "forecast_prophet",
64
+ "forecast_with_autogluon",
65
+ "backtest_timeseries",
66
+ "analyze_timeseries_model",
67
+ "detect_anomalies_time_series",
68
+ ],
69
+ "nlp": [
70
+ "extract_entities",
71
+ "sentiment_analysis",
72
+ "topic_modeling",
73
+ "text_classification",
74
+ "text_preprocessing",
75
+ ],
76
+ "computer_vision": [
77
+ "image_classification",
78
+ "object_detection",
79
+ "image_preprocessing",
80
+ ],
81
+ "business_intelligence": [
82
+ "calculate_kpis",
83
+ "trend_analysis",
84
+ "cohort_analysis",
85
+ "churn_prediction",
86
+ ],
87
+ "production": [
88
+ "export_model_to_onnx",
89
+ "generate_inference_code",
90
+ "create_model_documentation",
91
+ "validate_model_drift",
92
+ ],
93
+ "code_execution": [
94
+ "execute_python_code",
95
+ "debug_code",
96
+ ]
97
+ }
98
+
99
+ # Map specialist agents to their relevant tool categories
100
+ AGENT_TOOL_MAPPING = {
101
+ "data_quality_agent": {
102
+ "categories": ["profiling", "cleaning"],
103
+ "description": "Focuses on data profiling, quality assessment, and cleaning operations"
104
+ },
105
+ "preprocessing_agent": {
106
+ "categories": ["cleaning", "feature_engineering", "profiling"],
107
+ "description": "Handles data cleaning, transformation, and feature engineering"
108
+ },
109
+ "visualization_agent": {
110
+ "categories": ["visualization", "profiling"],
111
+ "description": "Creates charts, plots, and interactive dashboards"
112
+ },
113
+ "modeling_agent": {
114
+ "categories": ["modeling", "feature_engineering", "profiling"],
115
+ "description": "Trains, tunes, and evaluates machine learning models"
116
+ },
117
+ "time_series_agent": {
118
+ "categories": ["time_series", "profiling", "visualization"],
119
+ "description": "Specializes in time series analysis and forecasting"
120
+ },
121
+ "nlp_agent": {
122
+ "categories": ["nlp", "profiling", "visualization"],
123
+ "description": "Natural language processing and text analytics"
124
+ },
125
+ "computer_vision_agent": {
126
+ "categories": ["computer_vision", "profiling"],
127
+ "description": "Image processing and computer vision tasks"
128
+ },
129
+ "business_intelligence_agent": {
130
+ "categories": ["business_intelligence", "visualization", "profiling"],
131
+ "description": "Business metrics, KPIs, and strategic insights"
132
+ },
133
+ "production_agent": {
134
+ "categories": ["production", "modeling"],
135
+ "description": "Model deployment, monitoring, and production operations"
136
+ },
137
+ "general_agent": {
138
+ "categories": ["profiling", "cleaning", "visualization", "code_execution"],
139
+ "description": "General purpose agent for exploratory analysis"
140
+ }
141
+ }
142
+
143
+ # Core tools that should always be available regardless of agent
144
+ CORE_TOOLS = [
145
+ "profile_dataset",
146
+ "get_smart_summary",
147
+ "execute_python_code",
148
+ ]
149
+
150
+
151
+ def get_tools_for_agent(agent_name: str) -> list:
152
+ """
153
+ Get list of tool names relevant to a specific agent.
154
+
155
+ Args:
156
+ agent_name: Name of the specialist agent
157
+
158
+ Returns:
159
+ List of tool names the agent can use
160
+ """
161
+ if agent_name not in AGENT_TOOL_MAPPING:
162
+ # Default to general agent tools
163
+ agent_name = "general_agent"
164
+
165
+ agent_info = AGENT_TOOL_MAPPING[agent_name]
166
+ categories = agent_info["categories"]
167
+
168
+ # Collect all tools from relevant categories
169
+ tools = set(CORE_TOOLS) # Start with core tools
170
+
171
+ for category in categories:
172
+ if category in TOOL_CATEGORIES:
173
+ tools.update(TOOL_CATEGORIES[category])
174
+
175
+ return list(tools)
176
+
177
+
178
+ def get_tool_categories_for_agent(agent_name: str) -> list:
179
+ """
180
+ Get categories of tools relevant to a specific agent.
181
+
182
+ Args:
183
+ agent_name: Name of the specialist agent
184
+
185
+ Returns:
186
+ List of tool category names
187
+ """
188
+ if agent_name not in AGENT_TOOL_MAPPING:
189
+ agent_name = "general_agent"
190
+
191
+ return AGENT_TOOL_MAPPING[agent_name]["categories"]
192
+
193
+
194
+ def filter_tools_by_names(all_tools: list, tool_names: list) -> list:
195
+ """
196
+ Filter tool definitions to only include specified tool names.
197
+
198
+ Args:
199
+ all_tools: List of all tool definitions (from TOOLS registry)
200
+ tool_names: List of tool names to include
201
+
202
+ Returns:
203
+ Filtered list of tool definitions
204
+ """
205
+ filtered = []
206
+ tool_names_set = set(tool_names)
207
+
208
+ for tool in all_tools:
209
+ if tool.get("type") == "function":
210
+ function_name = tool.get("function", {}).get("name")
211
+ if function_name in tool_names_set:
212
+ # Compress description to reduce token usage
213
+ compressed_tool = compress_tool_definition(tool)
214
+ filtered.append(compressed_tool)
215
+
216
+ return filtered
217
+
218
+
219
+ def compress_tool_definition(tool: dict) -> dict:
220
+ """
221
+ Compress tool definition to reduce token usage.
222
+
223
+ Removes verbose examples and shortens descriptions while keeping
224
+ essential information for the LLM to use the tool correctly.
225
+
226
+ Args:
227
+ tool: Tool definition dict
228
+
229
+ Returns:
230
+ Compressed tool definition
231
+ """
232
+ if tool.get("type") != "function":
233
+ return tool
234
+
235
+ compressed = {
236
+ "type": "function",
237
+ "function": {
238
+ "name": tool["function"]["name"],
239
+ "description": compress_description(tool["function"]["description"]),
240
+ "parameters": tool["function"]["parameters"]
241
+ }
242
+ }
243
+
244
+ # Compress parameter descriptions
245
+ if "properties" in compressed["function"]["parameters"]:
246
+ for param_name, param_info in compressed["function"]["parameters"]["properties"].items():
247
+ if "description" in param_info:
248
+ param_info["description"] = compress_description(param_info["description"])
249
+
250
+ return compressed
251
+
252
+
253
+ def compress_description(description: str) -> str:
254
+ """
255
+ Compress a tool or parameter description.
256
+
257
+ Removes examples, extra whitespace, and verbose explanations
258
+ while keeping core functionality description.
259
+
260
+ Args:
261
+ description: Original description
262
+
263
+ Returns:
264
+ Compressed description
265
+ """
266
+ # Remove everything after "Example:" or "Examples:"
267
+ if "Example:" in description:
268
+ description = description.split("Example:")[0]
269
+ if "Examples:" in description:
270
+ description = description.split("Examples:")[0]
271
+
272
+ # Remove extra whitespace and newlines
273
+ description = " ".join(description.split())
274
+
275
+ # Truncate if still too long (keep first 150 chars for params, 250 for tools)
276
+ max_length = 250 if "Use this" in description else 150
277
+ if len(description) > max_length:
278
+ description = description[:max_length].rsplit(' ', 1)[0] + "..."
279
+
280
+ return description.strip()
281
+
282
+
283
+ def get_agent_description(agent_name: str) -> str:
284
+ """
285
+ Get description of what an agent specializes in.
286
+
287
+ Args:
288
+ agent_name: Name of the specialist agent
289
+
290
+ Returns:
291
+ Agent description string
292
+ """
293
+ if agent_name in AGENT_TOOL_MAPPING:
294
+ return AGENT_TOOL_MAPPING[agent_name]["description"]
295
+ return "General purpose data science agent"
296
+
297
+
298
+ def suggest_next_agent(current_agent: str, completed_tools: list) -> str:
299
+ """
300
+ Suggest the next agent to hand off to based on completed tools.
301
+
302
+ Args:
303
+ current_agent: Current agent name
304
+ completed_tools: List of tool names already executed
305
+
306
+ Returns:
307
+ Suggested next agent name, or None if workflow complete
308
+ """
309
+ # Define typical workflow progressions
310
+ workflows = {
311
+ "data_quality_agent": "preprocessing_agent", # After profiling → cleaning
312
+ "preprocessing_agent": "visualization_agent", # After cleaning → visualize
313
+ "visualization_agent": "modeling_agent", # After EDA → modeling
314
+ "modeling_agent": "production_agent", # After training → deploy
315
+ }
316
+
317
+ # Check if current agent has completed its primary tasks
318
+ agent_tools = set(get_tools_for_agent(current_agent))
319
+ completed_set = set(completed_tools)
320
+
321
+ # If less than 30% of agent's tools used, stay with current agent
322
+ if len(completed_set & agent_tools) / max(len(agent_tools), 1) < 0.3:
323
+ return current_agent
324
+
325
+ # Suggest next agent in typical workflow
326
+ return workflows.get(current_agent, None)