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,431 @@
1
+ """
2
+ Business Summary Module
3
+
4
+ Translates technical ML results into business-friendly summaries.
5
+
6
+ KEY RULES:
7
+ - ✅ Accepts: Model results, metrics, insights
8
+ - ❌ NO: Raw technical details in output
9
+ - ✅ Returns: Executive summaries, ROI estimates, actionable recommendations
10
+ - ❌ NO: Code, statistical jargon, complex formulas
11
+
12
+ Use Cases:
13
+ 1. Executive summaries of ML projects
14
+ 2. ROI/impact estimation
15
+ 3. Stakeholder-friendly reporting
16
+ 4. Business recommendations from technical results
17
+
18
+ Example:
19
+ from reasoning.business_summary import create_executive_summary
20
+
21
+ results = {
22
+ "model_accuracy": 0.95,
23
+ "cost_savings": "$50K/year",
24
+ "deployment_ready": True
25
+ }
26
+
27
+ summary = create_executive_summary(results, "churn_prediction")
28
+ # Returns: "This churn prediction model can save $50K annually..."
29
+ """
30
+
31
+ from typing import Dict, Any, List, Optional
32
+ from . import get_reasoner
33
+
34
+
35
+ def create_executive_summary(
36
+ project_results: Dict[str, Any],
37
+ project_name: str,
38
+ business_objective: Optional[str] = None
39
+ ) -> Dict[str, Any]:
40
+ """
41
+ Create executive summary of ML project for non-technical stakeholders.
42
+
43
+ Args:
44
+ project_results: Technical results (metrics, insights, etc.)
45
+ project_name: Name of the ML project
46
+ business_objective: What business problem this solves
47
+
48
+ Returns:
49
+ {
50
+ "executive_summary": str, # 2-3 sentence overview
51
+ "key_findings": List[str], # 3-5 bullet points
52
+ "business_impact": str, # Expected impact
53
+ "recommendations": List[str], # What to do next
54
+ "risks_and_limitations": List[str] # Important caveats
55
+ }
56
+ """
57
+ reasoner = get_reasoner()
58
+
59
+ objective = ""
60
+ if business_objective:
61
+ objective = f"\n**Business Objective:** {business_objective}"
62
+
63
+ prompt = f"""Create an executive summary for this ML project:
64
+
65
+ **Project:** {project_name}{objective}
66
+
67
+ **Technical Results:**
68
+ {project_results}
69
+
70
+ Write for C-level executives who don't understand ML.
71
+
72
+ Include:
73
+ 1. 2-3 sentence executive summary
74
+ 2. 3-5 key findings (what we learned)
75
+ 3. Business impact (quantified if possible)
76
+ 4. Recommendations (what to do next)
77
+ 5. Risks and limitations (important caveats)
78
+
79
+ Use business language, not technical jargon.
80
+ Focus on outcomes, not methods."""
81
+
82
+ system_prompt = """You are translating technical ML results for business executives.
83
+ Avoid jargon like 'accuracy', 'recall', 'features' - use business terms.
84
+ Focus on ROI, impact, and actionable next steps."""
85
+
86
+ schema = {
87
+ "executive_summary": "string - 2-3 sentence overview",
88
+ "key_findings": ["array of 3-5 key insights"],
89
+ "business_impact": "string - Expected business impact",
90
+ "recommendations": ["array of next steps"],
91
+ "risks_and_limitations": ["array of important caveats"]
92
+ }
93
+
94
+ return reasoner.reason_structured(prompt, schema, system_prompt)
95
+
96
+
97
+ def estimate_business_impact(
98
+ model_performance: Dict[str, Any],
99
+ business_metrics: Dict[str, Any],
100
+ use_case: str
101
+ ) -> Dict[str, Any]:
102
+ """
103
+ Estimate business impact of deploying the model.
104
+
105
+ Args:
106
+ model_performance: Model metrics (accuracy, recall, etc.)
107
+ business_metrics: Business context
108
+ Example: {
109
+ "current_churn_rate": 0.25,
110
+ "customer_lifetime_value": 1000,
111
+ "customers": 10000
112
+ }
113
+ use_case: Description of use case
114
+ Example: "churn prediction", "fraud detection", "demand forecasting"
115
+
116
+ Returns:
117
+ {
118
+ "estimated_impact": str, # Quantified impact
119
+ "assumptions": List[str], # Key assumptions made
120
+ "sensitivity": str, # How sensitive to assumptions
121
+ "confidence_level": str, # Confidence in estimates
122
+ "impact_breakdown": Dict[str, str] # Detailed breakdown
123
+ }
124
+ """
125
+ reasoner = get_reasoner()
126
+
127
+ prompt = f"""Estimate the business impact of deploying this model:
128
+
129
+ **Use Case:** {use_case}
130
+
131
+ **Model Performance:**
132
+ {model_performance}
133
+
134
+ **Business Context:**
135
+ {business_metrics}
136
+
137
+ Estimate:
138
+ 1. Quantified business impact (revenue, cost savings, etc.)
139
+ 2. Key assumptions in your calculation
140
+ 3. Sensitivity to assumptions
141
+ 4. Confidence level in estimates
142
+ 5. Breakdown of impact by component
143
+
144
+ Be conservative in estimates. Show your reasoning."""
145
+
146
+ system_prompt = """You are a business impact analyst.
147
+ Provide realistic, conservative estimates with clear assumptions.
148
+ Show how you calculated impact - don't just guess."""
149
+
150
+ schema = {
151
+ "estimated_impact": "string - Quantified impact estimate",
152
+ "assumptions": ["array of key assumptions"],
153
+ "sensitivity": "string - How sensitive to assumptions",
154
+ "confidence_level": "string - low/medium/high",
155
+ "impact_breakdown": {
156
+ "component": "string - Impact value"
157
+ }
158
+ }
159
+
160
+ return reasoner.reason_structured(prompt, schema, system_prompt)
161
+
162
+
163
+ def create_stakeholder_report(
164
+ audience: str,
165
+ project_status: str,
166
+ key_metrics: Dict[str, Any],
167
+ timeline: Optional[Dict[str, str]] = None
168
+ ) -> str:
169
+ """
170
+ Create customized report for specific stakeholder audience.
171
+
172
+ Args:
173
+ audience: 'executives', 'engineers', 'business_users', 'data_team'
174
+ project_status: Current project status
175
+ key_metrics: Relevant metrics for this audience
176
+ timeline: Optional timeline information
177
+
178
+ Returns:
179
+ Natural language report customized for audience
180
+ """
181
+ reasoner = get_reasoner()
182
+
183
+ timeline_section = ""
184
+ if timeline:
185
+ timeline_section = f"\n**Timeline:**\n{timeline}"
186
+
187
+ # Audience-specific focus
188
+ audience_focus = {
189
+ "executives": "ROI, strategic alignment, high-level status",
190
+ "engineers": "Technical implementation, architecture, performance",
191
+ "business_users": "How to use, what it means for their work, training needs",
192
+ "data_team": "Data quality, model performance, monitoring needs"
193
+ }
194
+
195
+ focus = audience_focus.get(audience, "General status")
196
+
197
+ prompt = f"""Create a report for {audience}:
198
+
199
+ **Project Status:** {project_status}
200
+
201
+ **Key Metrics:**
202
+ {key_metrics}{timeline_section}
203
+
204
+ **Focus Areas:** {focus}
205
+
206
+ Tailor the report for this specific audience.
207
+ Use language and concepts they understand.
208
+ Highlight what matters most to them."""
209
+
210
+ system_prompt = f"""You are writing a report for {audience}.
211
+ Use appropriate language and detail level for this audience.
212
+ Focus on what they care about most."""
213
+
214
+ return reasoner.reason(prompt, system_prompt, temperature=0.2)
215
+
216
+
217
+ def translate_technical_to_business(
218
+ technical_term: str,
219
+ context: Optional[str] = None
220
+ ) -> str:
221
+ """
222
+ Translate technical ML term to business-friendly language.
223
+
224
+ Args:
225
+ technical_term: ML term to translate
226
+ Examples: "precision", "recall", "overfitting", "feature importance"
227
+ context: Optional context for better translation
228
+
229
+ Returns:
230
+ Business-friendly explanation
231
+ """
232
+ reasoner = get_reasoner()
233
+
234
+ context_section = ""
235
+ if context:
236
+ context_section = f"\n**Context:** {context}"
237
+
238
+ prompt = f"""Translate this technical ML term to business language:
239
+
240
+ **Technical Term:** {technical_term}{context_section}
241
+
242
+ Explain:
243
+ 1. What it means in plain English
244
+ 2. Why it matters for business
245
+ 3. Real-world analogy if helpful
246
+
247
+ Avoid technical jargon in your explanation."""
248
+
249
+ system_prompt = """You are translating ML concepts for business audiences.
250
+ Use analogies and examples they can relate to.
251
+ Focus on 'why it matters', not 'how it works'."""
252
+
253
+ return reasoner.reason(prompt, system_prompt, temperature=0.1)
254
+
255
+
256
+ def prioritize_next_steps(
257
+ current_results: Dict[str, Any],
258
+ available_resources: Dict[str, Any],
259
+ business_constraints: Optional[Dict[str, Any]] = None
260
+ ) -> Dict[str, Any]:
261
+ """
262
+ Prioritize next steps based on results, resources, and constraints.
263
+
264
+ Args:
265
+ current_results: Current project state and results
266
+ available_resources: Available time, budget, team
267
+ business_constraints: Deadlines, must-haves, etc.
268
+
269
+ Returns:
270
+ {
271
+ "high_priority": List[Dict], # Must-do items
272
+ "medium_priority": List[Dict], # Should-do items
273
+ "low_priority": List[Dict], # Nice-to-have items
274
+ "rationale": str # Prioritization reasoning
275
+ }
276
+ """
277
+ reasoner = get_reasoner()
278
+
279
+ constraints = ""
280
+ if business_constraints:
281
+ constraints = f"\n**Business Constraints:**\n{business_constraints}"
282
+
283
+ prompt = f"""Prioritize next steps for this ML project:
284
+
285
+ **Current Results:**
286
+ {current_results}
287
+
288
+ **Available Resources:**
289
+ {available_resources}{constraints}
290
+
291
+ Categorize tasks into:
292
+ 1. High Priority (must-do, high impact, blocking)
293
+ 2. Medium Priority (should-do, good ROI)
294
+ 3. Low Priority (nice-to-have, polish)
295
+
296
+ For each item, specify:
297
+ - What to do
298
+ - Why it's important
299
+ - Estimated effort
300
+ - Expected impact
301
+
302
+ Consider resource constraints and business deadlines."""
303
+
304
+ system_prompt = """You are a product/project manager prioritizing ML work.
305
+ Use impact vs effort analysis.
306
+ Be realistic about what can be accomplished with available resources."""
307
+
308
+ schema = {
309
+ "high_priority": [
310
+ {
311
+ "task": "string",
312
+ "reason": "string",
313
+ "effort": "string",
314
+ "impact": "string"
315
+ }
316
+ ],
317
+ "medium_priority": [{"task": "string", "reason": "string", "effort": "string", "impact": "string"}],
318
+ "low_priority": [{"task": "string", "reason": "string", "effort": "string", "impact": "string"}],
319
+ "rationale": "string - Overall prioritization logic"
320
+ }
321
+
322
+ return reasoner.reason_structured(prompt, schema, system_prompt)
323
+
324
+
325
+ def explain_to_customer(
326
+ prediction: Any,
327
+ explanation_level: str = "simple",
328
+ allow_appeal: bool = False
329
+ ) -> str:
330
+ """
331
+ Explain ML prediction to end customer (explainability for users).
332
+
333
+ Args:
334
+ prediction: What the model predicted
335
+ explanation_level: 'simple', 'detailed', or 'technical'
336
+ allow_appeal: Whether customer can appeal the decision
337
+
338
+ Returns:
339
+ Customer-facing explanation
340
+ """
341
+ reasoner = get_reasoner()
342
+
343
+ appeal_text = ""
344
+ if allow_appeal:
345
+ appeal_text = "\n\nNote: Customer can appeal this decision, explain how."
346
+
347
+ prompt = f"""Explain this ML prediction to an end customer:
348
+
349
+ **Prediction:** {prediction}
350
+
351
+ **Explanation Level:** {explanation_level}
352
+
353
+ **Requirements:**
354
+ - Be transparent but not technical
355
+ - Build trust, don't confuse
356
+ - Comply with explainability requirements (GDPR, fair lending, etc.)
357
+ - Don't expose proprietary model details{appeal_text}
358
+
359
+ Focus on:
360
+ - What was decided
361
+ - Key factors that influenced it
362
+ - What customer can do if they disagree"""
363
+
364
+ system_prompt = """You are writing customer-facing explanations.
365
+ Be clear, honest, and empathetic.
366
+ Comply with regulatory explainability requirements.
367
+ Don't say 'the algorithm decided' - take ownership."""
368
+
369
+ return reasoner.reason(prompt, system_prompt, temperature=0.2)
370
+
371
+
372
+ def assess_deployment_readiness(
373
+ model_results: Dict[str, Any],
374
+ production_requirements: Dict[str, Any]
375
+ ) -> Dict[str, Any]:
376
+ """
377
+ Assess whether model is ready for production deployment.
378
+
379
+ Args:
380
+ model_results: Model performance and characteristics
381
+ production_requirements: Production system requirements
382
+ Example: {
383
+ "min_accuracy": 0.90,
384
+ "max_latency_ms": 100,
385
+ "required_explainability": True
386
+ }
387
+
388
+ Returns:
389
+ {
390
+ "ready_for_deployment": bool,
391
+ "readiness_score": float, # 0-1 score
392
+ "blockers": List[str], # Must-fix issues
393
+ "concerns": List[str], # Should-fix issues
394
+ "sign_offs_needed": List[str], # Required approvals
395
+ "deployment_recommendation": str # Go/no-go reasoning
396
+ }
397
+ """
398
+ reasoner = get_reasoner()
399
+
400
+ prompt = f"""Assess deployment readiness:
401
+
402
+ **Model Results:**
403
+ {model_results}
404
+
405
+ **Production Requirements:**
406
+ {production_requirements}
407
+
408
+ Determine:
409
+ 1. Whether model is ready for deployment (yes/no)
410
+ 2. Readiness score (0-1, where 1 = fully ready)
411
+ 3. Blocking issues (must be fixed before deployment)
412
+ 4. Concerns (should be addressed but not blockers)
413
+ 5. Required sign-offs (legal, compliance, business, etc.)
414
+ 6. Go/no-go recommendation with reasoning
415
+
416
+ Be thorough - production issues are costly."""
417
+
418
+ system_prompt = """You are assessing production deployment readiness.
419
+ Be conservative - it's better to delay than deploy broken model.
420
+ Consider performance, reliability, explainability, fairness, and compliance."""
421
+
422
+ schema = {
423
+ "ready_for_deployment": "boolean",
424
+ "readiness_score": "number between 0 and 1",
425
+ "blockers": ["array of must-fix issues"],
426
+ "concerns": ["array of should-fix issues"],
427
+ "sign_offs_needed": ["array of required approvals"],
428
+ "deployment_recommendation": "string - Go/no-go with reasoning"
429
+ }
430
+
431
+ return reasoner.reason_structured(prompt, schema, system_prompt)