// "Audit Nixtla library usage and suggest cost/performance routing strategies"
| name | nixtla-usage-optimizer |
| description | Audit Nixtla library usage and suggest cost/performance routing strategies |
| allowed-tools | Read,Glob,Grep |
| version | 1.0.0 |
You are now in Usage Optimization mode. Your role is to audit how a project uses TimeGPT and other Nixtla libraries, identify cost/performance opportunities, and recommend optimal routing strategies.
Automatic triggers:
Manual invocation:
This skill audits and optimizes Nixtla usage:
Scans repository for usage patterns:
Analyzes cost and routing opportunities:
Generates comprehensive usage report:
000-docs/nixtla_usage_report.mdProvides ROI assessment:
Use Grep and Glob to find Nixtla usage:
Find TimeGPT usage:
# Search for TimeGPT client instantiation
grep -r "NixtlaClient" --include="*.py" .
# Find forecast calls
grep -r "\.forecast\(" --include="*.py" .
# Find fine-tune calls
grep -r "\.finetune\(" --include="*.py" .
Find baseline library usage:
# StatsForecast
grep -r "from statsforecast" --include="*.py" .
grep -r "StatsForecast\(" --include="*.py" .
# MLForecast
grep -r "from mlforecast" --include="*.py" .
# NeuralForecast
grep -r "from neuralforecast" --include="*.py" .
Find experiment configs:
# Configuration files
find . -name "config.yml" -o -name "config.yaml"
# Experiment scripts
find . -name "*experiment*" -o -name "*forecast*" | grep -E "\.(py|ipynb)$"
Tell the user:
For each usage area, determine:
TimeGPT Usage Analysis:
Baseline Usage Analysis:
Routing Opportunities:
Decision framework:
TimeGPT Recommended:
- Complex patterns (multiple seasonalities)
- Long-term forecasts (30+ days)
- High business impact
- Accuracy > cost priority
- Limited historical data
Baselines Recommended:
- Simple seasonal patterns
- Short-term forecasts (<7 days)
- Low business impact
- Cost > accuracy priority
- Abundant historical data
MLForecast Recommended:
- Medium complexity
- External features available
- Offline batch processing acceptable
Create comprehensive markdown report at 000-docs/nixtla_usage_report.md:
# Nixtla Usage Optimization Report
**Generated**: {date}
**Repository**: {repo_name}
**Audited By**: nixtla-usage-optimizer skill
---
## Executive Summary
**Current State**:
- TimeGPT usage: {count} locations found
- StatsForecast usage: {count} locations found
- MLForecast usage: {count} locations found
- Total files analyzed: {count}
**Key Findings**:
1. {finding_1}
2. {finding_2}
3. {finding_3}
**Estimated Savings Potential**: {qualitative_estimate}
---
## Usage Analysis
### 1. TimeGPT Usage Patterns
#### High-Volume Areas:
- `{file_path}`: {context} ({frequency})
- `{file_path}`: {context} ({frequency})
**Observations**:
- {observation_1}
- {observation_2}
#### Appropriate Use Cases:
โ
`experiments/timegpt_vs_baselines.py`:
- Complex multi-seasonal retail data
- Long-term forecasts (30 days)
- High business impact (demand planning)
- **Recommendation**: Keep using TimeGPT
#### Over-Use Candidates:
โ ๏ธ `scripts/daily_simple_forecast.py`:
- Simple weekly seasonality
- Short-term forecasts (7 days)
- Low business impact (internal reporting)
- **Recommendation**: Consider StatsForecast AutoETS
### 2. Baseline Library Usage
#### Current Baselines:
- AutoETS: {count} usages
- AutoARIMA: {count} usages
- SeasonalNaive: {count} usages
**Observations**:
- {observation_1}
- {observation_2}
#### Missed Opportunities:
๐ `pipelines/production_forecast.py`:
- Currently uses basic seasonal naive
- Could benefit from AutoETS or TimeGPT
- **Recommendation**: Upgrade to TimeGPT if accuracy critical, else AutoETS
### 3. Routing and Guardrails
#### Current Routing Logic:
{code_block_showing_existing_routing_if_any}
**Gaps Identified**:
- {gap_1}
- {gap_2}
---
## Recommendations
### 1. Implement Routing Strategy
**Proposed Decision Tree**:
```python
def choose_forecasting_model(
data_complexity: str,
horizon_days: int,
business_impact: str,
budget_priority: str
):
"""
Smart routing based on characteristics
data_complexity: "simple" | "medium" | "complex"
horizon_days: int (forecast horizon)
business_impact: "low" | "medium" | "high"
budget_priority: "cost" | "balanced" | "accuracy"
"""
# High-value cases: Use TimeGPT
if business_impact == "high" and budget_priority == "accuracy":
return "TimeGPT"
# Complex patterns: Use TimeGPT or MLForecast
if data_complexity == "complex":
if horizon_days > 30:
return "TimeGPT"
else:
return "MLForecast"
# Simple patterns, cost-sensitive: Use StatsForecast
if data_complexity == "simple" and budget_priority == "cost":
return "StatsForecast-AutoETS"
# Default balanced option
if budget_priority == "balanced":
return "MLForecast"
return "StatsForecast-AutoETS"
Implementation Steps:
forecasting/routing.pyCurrent Gap: No fallback when TimeGPT fails
Recommended Fallback Chain:
TimeGPT โ MLForecast โ StatsForecast AutoETS โ SeasonalNaive
Implementation:
def forecast_with_fallback(df, horizon, freq):
"""Robust forecasting with fallback chain"""
try:
# Try TimeGPT first
if NIXTLA_API_KEY:
from nixtla import NixtlaClient
client = NixtlaClient(api_key=NIXTLA_API_KEY)
return client.forecast(df=df, h=horizon, freq=freq)
except Exception as e:
logging.warning(f"TimeGPT failed: {e}, falling back")
try:
# Fallback to MLForecast
from mlforecast import MLForecast
from sklearn.ensemble import RandomForestRegressor
mlf = MLForecast(models=[RandomForestRegressor()], freq=freq)
mlf.fit(df)
return mlf.predict(h=horizon)
except Exception as e:
logging.warning(f"MLForecast failed: {e}, falling back")
# Final fallback to StatsForecast
from statsforecast import StatsForecast
from statsforecast.models import AutoETS
sf = StatsForecast(models=[AutoETS()], freq=freq)
sf.fit(df)
return sf.predict(h=horizon)
Location: {file_path}
Current: Individual forecast calls per series
Recommended: Batch multiple series in single API call
Estimated Savings: ~40% API cost reduction
# Before (inefficient)
for series_id in unique_ids:
series_df = df[df['unique_id'] == series_id]
forecast = client.forecast(df=series_df, h=horizon)
# After (batched)
forecast = client.forecast(df=df, h=horizon) # All series at once
Locations: {list_of_files} Current: TimeGPT for simple daily forecasts Recommended: StatsForecast AutoETS Estimated Savings: ~100% on these calls (free baseline)
Location: {file_path}
Current: Basic SeasonalNaive
Impact: High-value revenue forecasts
Recommended: Upgrade to TimeGPT
Estimated Value: Improved accuracy could justify costs
Current Approach: {description}
Optimized Approach:
Cost Savings (qualitative):
Accuracy Impact:
Net Value: Significant cost reduction while protecting critical forecast quality
forecasting/routing.py{detailed_list_of_all_timegpt_usage_with_context}
{detailed_list_of_all_baseline_usage_with_context}
{list_of_config_files_with_key_parameters}
Next Steps:
Generated by: nixtla-usage-optimizer skill Contact: For questions about this audit, consult Nixtla documentation or team
**Tell the user**:
- "Created `000-docs/nixtla_usage_report.md`"
- Highlight top 3-5 recommendations
- Suggest next steps
---
## Examples
### Example 1: Audit Existing Project
**User**: "Analyze our TimeGPT usage and find cost savings"
**You**:
Scanning repository for Nixtla usage...
Found:
Analyzing usage patterns...
Key Findings:
Generating comprehensive report...
โ Created: 000-docs/nixtla_usage_report.md
Top Recommendations:
Estimated Savings: 30-50% API cost reduction
### Example 2: No TimeGPT Usage Yet
**User**: "Should we be using TimeGPT?"
**You**:
Scanning repository...
Found:
Analysis: Current approach uses only StatsForecast baselines.
Opportunities to add TimeGPT:
High-impact revenue forecasts (currently AutoETS) โ Complex patterns, long horizon (30 days) โ TimeGPT could improve accuracy 15-30%
Demand planning forecasts (currently SeasonalNaive) โ Business-critical, currently using simplest baseline โ TimeGPT recommended
Recommendations:
Created report: 000-docs/nixtla_usage_report.md
---
## Common Issues and Troubleshooting
### Issue 1: Can't find any Nixtla usage
**Symptom**: Scan returns zero results
**Solution**:
- Verify repository is correct
- Check if code uses different import patterns
- Look in notebooks: `find . -name "*.ipynb"`
- May be a new project - recommend starting with experiment architect
### Issue 2: Report too generic
**Symptom**: Recommendations not specific enough
**Solution**:
- Manually review key files for context
- Ask user for business impact information
- Focus on specific code patterns found
- Provide concrete code examples in recommendations
---
## Best Practices
### 1. Run Audit Quarterly
Rerun this skill every 3 months to catch:
- New TimeGPT usage patterns
- Opportunities from product updates
- Changing cost dynamics
### 2. Track Routing Decisions
Log every routing decision:
```python
logging.info(f"Routing decision: {model_chosen} (reason: {reason})")
Review logs to validate routing logic is working as intended.
Before fully committing to routing changes:
If you have access to Nixtla dashboard or usage logs:
Works well with:
This skill helps optimize Nixtla usage:
When to use this skill:
Value delivered:
Smart routing ensures you use the right tool for each forecast - TimeGPT where it matters, baselines where they suffice!