---
name: load-forecasting
version: 1.0.0
description: Power load forecasting model skill, providing functions to obtain load forecasting model lists, load models, perform quick load forecasting, and calculate load forecasting model evaluation parameters (MAE, RMSE, R², MAPE). Supports model training, automatically generates HTML reports after evaluation, and requires secondary parameter confirmation before training.
compatibility: Requires Python 3.x and access to API http://47.96.16.84:5005
return_format_specification:
  preview_training_params:
    format: "&**&key1=value1|key2=value2|...|keyN=valueN&**&"
    description: "Parameter preview return format, using | as a separator, wrapped in &**&, JSON format is NOT used. The frontend will automatically render this into an interactive table — DO NOT use markdown tables or any other format."
    example: "&**&learning_rate=0.001|batch_size=32|max_epochs=100|window_size=96|hidden_size=128|num_layers=2|split_ratio=811|start_time=2024-01-01 00:00:00|end_time=2025-12-31 23:45:00&**&"
    critical: "NEVER render training parameters as a markdown table. ONLY output the &**&...&**& string. The system framework will convert it into an interactive table automatically."
  evaluate_model:
    format: "@@@@@<report_address>@@@@@"
    description: "Evaluation report return format, using @@@@@ to wrap the report address"
    example: "@@@@@/skills/report-generator/output/report_1234567890.html@@@@@"
metadata:
  author: Manus AI
---

# 【Load Forecasting Model】

This skill is used for the complete evaluation process and model training function of power load forecasting models. It provides functions to obtain model lists, load models, perform quick load forecasting, and calculate evaluation parameters.

---

## ⚠️ Critical Rules

- MUST: For model evaluation, model listing, prediction results, and data comparison, you must call `report-generator` to generate an HTML report.
- MUST: Do not display the model path in the model list report.
- MUST: Before training, you must call `handle_training_request.py` to preview all parameters and perform secondary parameter confirmation.
- MUST: The training function must be triggered manually through conversation and will not be executed automatically.
- MUST: The system will only start training after the user explicitly expresses the intention to confirm (e.g., "Confirm parameters, start training").
- NEVER: The parameter preview return format strictly prohibits the use of JSON; it must strictly be `&**&key1=value1|key2=value2|...&**&` (using | as a separator and wrapped in &**&).
- NEVER: **DO NOT render training parameters as a markdown table, code block, or any other visual format.** The ONLY allowed output for parameter preview is the raw `&**&...&**&` string. The frontend framework handles all rendering automatically.

---

## When to Use

### Handled by this skill

- User asks about power load forecasting models, model evaluation, or calculating model parameters.
- User requests to list all load forecasting models.
- User requests to execute load forecasting or compare historical data with predicted data.
- User wants to perform manual model training.

### Not handled by this skill (Hand over to other skills)

- PV power generation prediction related tasks → Hand over to `【pv-prediction-model】`
- Pure report generation and formatting tasks (non-load data) → Hand over to `【report-generator】`

---

## How to Execute

> Execute the following steps in order. For each step, you MUST send a progress message before running the command.

### Step 1: Select Template

**FIRST**, send this message to the user:

`【开始分析】正在理解需求，匹配数据视图与展示模板...`

**THEN**, run:

```bash
cd /workspace/skills/report-generator && \
python3 scripts/step1_select.py --query "{{USER_QUERY}}" --data "{}"
```

*Replace `{{USER_QUERY}}` with the user's original question.*

Output example:

```json
{
  "status": "success",
  "template_name": "dataTable",
  "reason": "模型列表适合用表格形式展示"
}
```

Pass to next step: `template_name` → `--template` in Step 3.

---

### Step 2: Execute Action

**FIRST**, send this message to the user:

`【数据处理】正在执行操作并获取数据...`

**THEN**, run the appropriate command based on user request:

**Get model list:**
```bash
python scripts/predict_and_evaluate.py --action list_models
```

**Evaluate model:**
```bash
python scripts/predict_and_evaluate.py --action evaluate_model --model_id "{{MODEL_ID}}"
```

**Preview training parameters (secondary confirmation):**
```bash
python scripts/handle_training_request.py --learning_rate 0.001 --batch_size 32 --max_epochs 100
```

**Start training and monitor progress (ONLY after user confirmation):**
```bash
python scripts/train_station.py --action train_and_monitor --learning_rate 0.001 --batch_size 32 --max_epochs 100
```

**Compare historical and predicted data:**
```bash
python scripts/compare_prediction.py --target_date "{{TARGET_DATE}}" --model_name "{{MODEL_NAME}}"
```

**Execute load forecasting using a specific model:**
```bash
python scripts/load_forecast.py --model_name "{{MODEL_NAME}}"
```

**After Step 2, MUST immediately show the user:**
- Explanation of intermediate results, such as the retrieved model list, evaluation metrics, or parameter preview.

---

### Step 3: Render HTML Report

> Note: Parameter preview and starting training steps do not require report generation.

**FIRST**, send this message to the user:

`【报告生成】正在将结果渲染为可视化报告...`

**THEN**, run:

```bash
cd /workspace/skills/report-generator && \
python3 scripts/step2_render.py \
  --query "{{USER_QUERY}}" \
  --template "{{template_name from Step 1}}" \
  --data "{Output JSON data from Step 2}"
```

Output example:

```json
{
  "status": "success",
  "message": "Report generated successfully",
  "template": "dataTable",
  "address": "/skills/report-generator/output/report_1773642266.html",
  "summary": "共获取到3个负荷预测模型，其中best_model为最优模型。"
}
```

---

## Usage Examples

### Example 1: List all load forecasting models and generate a report

**User Query**: "List all load forecasting models"

**Execution Process**:
1. **Step 1**: Call `step1_select.py --query "列出所有负荷预测模型" --data "{}"` to get the template name `dataTable`.
2. **Step 2**: Call `predict_and_evaluate.py --action list_models` to get the model list.
3. **Step 3**: Call `step2_render.py --query "列出所有负荷预测模型" --template "dataTable" --data "{模型列表数据JSON}"` to generate the final report.

**Final Reply**:
Based on the `summary` returned in Step 3, organize the final reply.
```
@@@@@/skills/report-generator/output/report_1773642266.html@@@@@

#####%查看详细数据%￥点击上方链接查看完整的数据分析报告￥ %继续深入分析%￥基于当前数据进行更深度的挖掘￥ %导出报告%￥将当前报告导出为PDF或图片格式￥#####
```

### Example 2: Evaluate a load forecasting model and generate a report

**User Query**: "Evaluate the performance of best_model"

**Execution Process**:
1. **Step 1**: Call `step1_select.py --query "评估负荷预测模型" --data "{\"model_id\": \"best_model\"}"` to get the template name `dataTable`.
2. **Step 2**: Call `predict_and_evaluate.py --action evaluate_model --model_id best_model` to get prediction and evaluation data.
3. **Step 3**: Call `step2_render.py --query "评估负荷预测模型" --template "dataTable" --data "{预测和评估数据JSON}"` to generate the final report containing evaluation metrics.

### Example 3: Preview training parameters (secondary confirmation)

**User Query**: "I want to train a load forecasting model"

**Execution Process**:
1. **Step 2**: Call `handle_training_request.py --learning_rate 0.001 --batch_size 32 --max_epochs 100`.
2. **Final Reply**: Output the `&**&...&**&` string DIRECTLY and ONLY. Do NOT add any markdown table, do NOT explain the parameters in table form. The frontend will render it automatically.

**Correct output example**:
```
已为您准备好训练参数，系统将自动展示参数确认表格。

&**&learning_rate=0.001|batch_size=32|max_epochs=100|window_size=96|hidden_size=128|num_layers=2|split_ratio=811|start_time=2024-01-01 00:00:00|end_time=2025-12-31 23:45:00&**&
```

**Wrong output (FORBIDDEN)**:
```
| 参数 | 值 |
|------|-----|
| 学习率 | 0.001 |   ← NEVER do this
```

### Example 4: Start training after parameter confirmation

**User Query**: "Confirm parameters, start training" (User action after Example 3)

**Execution Process**:
1. **Step 2**: Call `train_station.py --action train_and_monitor --learning_rate 0.001 --batch_size 32 --max_epochs 100` to start training and monitor progress.
2. **Note**: This step does not require generating a report.

### Example 5: Compare historical data with load forecasting data and generate a report

**User Query**: "Compare historical and predicted data for CNN-RBiLSTM model on 2026-03-30"

**Execution Process**:
1. **Step 1**: Call `step1_select.py --query "对比历史数据和负荷预测数据" --data "{\"target_date\": \"2026-03-30\", \"model_name\": \"CNN-RBiLSTM\"}"` to get the template name `lineChartCompare`.
2. **Step 2**: Call `compare_prediction.py --target_date "2026-03-30" --model_name "CNN-RBiLSTM"` to get the comparison data.
3. **Step 3**: Call `step2_render.py --query "对比历史数据和负荷预测数据" --template "lineChartCompare" --data "{对比数据JSON}"` to generate the final report.

### Example 6: Execute load forecasting using a specific model and generate a report

**User Query**: "Execute load forecasting using CNN-RBiLSTM model"

**Execution Process**:
1. **Step 1**: Call `step1_select.py --query "使用指定模型执行负荷预测" --data "{\"model_name\": \"CNN-RBiLSTM\"}"` to get the template name `lineChart`.
2. **Step 2**: Call `load_forecast.py --model_name "CNN-RBiLSTM"` to get the prediction results.
3. **Step 3**: Call `step2_render.py --query "使用指定模型执行负荷预测" --template "lineChart" --data "{预测数据JSON}"` to generate the final report.

---

## Final Reply Format

Your final reply MUST have exactly three parts:

**Part 1 — Data Analysis Summary (Mandatory, cannot be omitted)**
Based on the `summary` field from the final script output, write a genuine data analysis in the user's language.
**DO NOT** just write "The report has been generated"; you must actually analyze the data content.
⚠️ CRITICAL: Write a brand-new analysis every time. **DO NOT reuse text from previous replies.**

**Part 2 — Address Tag (Second to last line, fixed format)**
```
@@@@@/skills/report-generator/output/report_1773642266.html@@@@@
```
⚠️ Copy the `address` field value EXACTLY from script output. NO spaces around `@@@@@`.

**Part 3 — Suggestions Tag (Last line, fixed format)**
```
#####%查看详细数据%￥点击上方链接查看完整的数据分析报告￥ %继续深入分析%￥基于当前数据进行更深度的挖掘￥ %导出报告%￥将当前报告导出为PDF或图片格式￥#####
```

---

## Gotchas

- Path leakage: Do not display the model path in the model list report.
- Skipping parameter confirmation: It is strictly prohibited to skip the parameter confirmation step and start training directly; you must wait for explicit user consent.
- Report format error: The report address format must strictly follow `@@@@@<report_address>@@@@@`.

---

## Bundled Resources

- `scripts/predict_and_evaluate.py` — Executes load forecasting model list retrieval and evaluation calculations.
- `scripts/handle_training_request.py` — Handles user training requests and previews training parameters.
- `scripts/train_station.py` — Performs load forecasting model training.
- `scripts/compare_prediction.py` — Compares historical load data and predicted load data for a specified date.
- `scripts/load_forecast.py` — Loads a model based on the model name and executes prediction.

> Read these files only when debugging. Normal execution does not require manual inspection.

---

## Error Handling

- `"status": "error"` → Inform the user "Service is temporarily unavailable, please try again later", and output the content of the `message` field.
- API call failure → Check the connection status of the API service `http://47.96.16.84:5005`.
- User refuses to confirm parameters → Cancel the training task and ask the user if they need to adjust the parameters.
