mirror of
https://gitee.com/wanwujie/deer-flow
synced 2026-04-19 04:14:46 +08:00
fix: repair missing step_type fields in Plan validation (#653)
* fix: resolve issue #650 - repair missing step_type fields in Plan validation - Add step_type repair logic to validate_and_fix_plan() to auto-infer missing step_type - Infer as 'research' when need_search=true, 'processing' when need_search=false - Add explicit CRITICAL REQUIREMENT section to planner.md emphasizing step_type mandatory for every step - Include validation checklist and examples showing both research and processing steps - Add 23 comprehensive unit tests for validate_and_fix_plan() covering all scenarios - Add 4 integration tests specifically for Issue #650 with actual Plan validation - Prevents Pydantic ValidationError: 'Field required' for missing step_type * Update tests/unit/graph/test_plan_validation.py Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update tests/unit/graph/test_plan_validation.py Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * update the planner.zh_CN.md with recent changes of planner.md --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -164,6 +164,30 @@ When planning information gathering, consider these key aspects and ensure COMPR
|
||||
- Do not include steps for summarizing or consolidating the gathered information.
|
||||
- **CRITICAL**: Verify that your plan includes at least one step with `need_search: true` before finalizing
|
||||
|
||||
## CRITICAL REQUIREMENT: step_type Field
|
||||
|
||||
**⚠️ IMPORTANT: You MUST include the `step_type` field for EVERY step in your plan. This is mandatory and cannot be omitted.**
|
||||
|
||||
For each step you create, you MUST explicitly set ONE of these values:
|
||||
- `"research"` - For steps that gather information via web search or retrieval (when `need_search: true`)
|
||||
- `"processing"` - For steps that analyze, compute, or process data without web search (when `need_search: false`)
|
||||
|
||||
**Validation Checklist - For EVERY Step, Verify ALL 4 Fields Are Present:**
|
||||
- [ ] `need_search`: Must be either `true` or `false`
|
||||
- [ ] `title`: Must describe what the step does
|
||||
- [ ] `description`: Must specify exactly what data to collect
|
||||
- [ ] `step_type`: Must be either `"research"` or `"processing"`
|
||||
|
||||
**Common Mistake to Avoid:**
|
||||
- ❌ WRONG: `{"need_search": true, "title": "...", "description": "..."}` (missing `step_type`)
|
||||
- ✅ CORRECT: `{"need_search": true, "title": "...", "description": "...", "step_type": "research"}`
|
||||
|
||||
**Step Type Assignment Rules:**
|
||||
- If `need_search` is `true` → use `step_type: "research"`
|
||||
- If `need_search` is `false` → use `step_type: "processing"`
|
||||
|
||||
Failure to include `step_type` for any step will cause validation errors and prevent the research plan from executing.
|
||||
|
||||
# Output Format
|
||||
|
||||
**CRITICAL: You MUST output a valid JSON object that exactly matches the Plan interface below. Do not include any text before or after the JSON. Do not use markdown code blocks. Output ONLY the raw JSON.**
|
||||
@@ -189,24 +213,38 @@ interface Plan {
|
||||
}
|
||||
```
|
||||
|
||||
**Example Output:**
|
||||
**Example Output (with BOTH research and processing steps):**
|
||||
```json
|
||||
{
|
||||
"locale": "en-US",
|
||||
"has_enough_context": false,
|
||||
"thought": "To understand the current market trends in AI, we need to gather comprehensive information about recent developments, key players, and market dynamics.",
|
||||
"thought": "To understand the current market trends in AI, we need to gather comprehensive information about recent developments, key players, and market dynamics, then analyze and synthesize this data.",
|
||||
"title": "AI Market Research Plan",
|
||||
"steps": [
|
||||
{
|
||||
"need_search": true,
|
||||
"title": "Current AI Market Analysis",
|
||||
"description": "Collect data on market size, growth rates, major players, and investment trends in AI sector.",
|
||||
"description": "Collect data on market size, growth rates, major players, investment trends, recent product launches, and technological breakthroughs in the AI sector from reliable sources.",
|
||||
"step_type": "research"
|
||||
},
|
||||
{
|
||||
"need_search": true,
|
||||
"title": "Emerging Trends and Future Outlook",
|
||||
"description": "Research emerging trends, expert forecasts, and future predictions for the AI market including expected growth, new market segments, and regulatory changes.",
|
||||
"step_type": "research"
|
||||
},
|
||||
{
|
||||
"need_search": false,
|
||||
"title": "Synthesize and Analyze Market Data",
|
||||
"description": "Analyze and synthesize all collected data to identify patterns, calculate market growth projections, compare competitor positions, and create data visualizations.",
|
||||
"step_type": "processing"
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
**NOTE:** Every step must have a `step_type` field set to either `"research"` or `"processing"`. Research steps (with `need_search: true`) gather data. Processing steps (with `need_search: false`) analyze the gathered data.
|
||||
|
||||
# Notes
|
||||
|
||||
- Focus on information gathering in research steps - delegate all calculations to processing steps
|
||||
|
||||
@@ -164,6 +164,30 @@ CURRENT_TIME: {{ CURRENT_TIME }}
|
||||
- 不要包括总结或整合收集信息的步骤。
|
||||
- **关键**:在最终确定之前验证你的计划包括至少一个带有`need_search: true`的步骤
|
||||
|
||||
## 关键要求:step_type字段
|
||||
|
||||
**⚠️ 重要:你必须为计划中的每一个步骤包含`step_type`字段。这是强制性的,不能省略。**
|
||||
|
||||
对于你创建的每个步骤,你必须显式设置以下值之一:
|
||||
- `"research"` - 用于通过网络搜索或检索来收集信息的步骤(当`need_search: true`时)
|
||||
- `"processing"` - 用于分析、计算或处理数据而不进行网络搜索的步骤(当`need_search: false`时)
|
||||
|
||||
**验证清单 - 对于每一个步骤,验证所有4个字段都存在:**
|
||||
- [ ] `need_search`:必须是`true`或`false`
|
||||
- [ ] `title`:必须描述步骤的作用
|
||||
- [ ] `description`:必须指定要收集的确切数据
|
||||
- [ ] `step_type`:必须是`"research"`或`"processing"`
|
||||
|
||||
**常见错误避免:**
|
||||
- ❌ 错误:`{"need_search": true, "title": "...", "description": "..."}` (缺少`step_type`)
|
||||
- ✅ 正确:`{"need_search": true, "title": "...", "description": "...", "step_type": "research"}`
|
||||
|
||||
**步骤类型分配规则:**
|
||||
- 如果`need_search`是`true` → 使用`step_type: "research"`
|
||||
- 如果`need_search`是`false` → 使用`step_type: "processing"`
|
||||
|
||||
任何步骤缺少`step_type`都将导致验证错误,阻止研究计划执行。
|
||||
|
||||
# 输出格式
|
||||
|
||||
**关键:你必须输出与下面的Plan接口完全匹配的有效JSON对象。不包括JSON之前或之后的任何文本。不使用markdown代码块。仅输出原始JSON。**
|
||||
@@ -189,24 +213,38 @@ interface Plan {
|
||||
}
|
||||
```
|
||||
|
||||
**示例输出:**
|
||||
**示例输出(包含研究步骤和处理步骤):**
|
||||
```json
|
||||
{
|
||||
"locale": "zh-CN",
|
||||
"has_enough_context": false,
|
||||
"thought": "要理解AI中当前的市场趋势,我们需要收集关于最近发展、主要参与者和市场动态的全面信息。",
|
||||
"thought": "要理解AI中当前的市场趋势,我们需要收集关于最近发展、主要参与者和市场动态的全面信息,然后分析和综合这些数据。",
|
||||
"title": "AI市场研究计划",
|
||||
"steps": [
|
||||
{
|
||||
"need_search": true,
|
||||
"title": "当前AI市场分析",
|
||||
"description": "收集关于AI部门市场规模、增长率、主要参与者和投资趋势的数据。",
|
||||
"description": "从可靠来源收集关于市场规模、增长率、主要参与者、投资趋势、最近的产品发布和AI部门技术突破的数据。",
|
||||
"step_type": "research"
|
||||
},
|
||||
{
|
||||
"need_search": true,
|
||||
"title": "新兴趋势和未来前景",
|
||||
"description": "研究新兴趋势、专家预测和AI市场的未来预测,包括预期增长、新的市场细分和监管变化。",
|
||||
"step_type": "research"
|
||||
},
|
||||
{
|
||||
"need_search": false,
|
||||
"title": "综合和分析市场数据",
|
||||
"description": "分析和综合所有收集的数据,以识别模式、计算市场增长预测、比较竞争对手位置并创建数据可视化。",
|
||||
"step_type": "processing"
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
**注意:** 每个步骤必须有一个`step_type`字段,设置为`"research"`或`"processing"`。研究步骤(带有`need_search: true`)收集数据。处理步骤(带有`need_search: false`)分析收集的数据。
|
||||
|
||||
# 注意
|
||||
|
||||
- 在研究步骤中关注信息收集——将所有计算委托给处理步骤
|
||||
|
||||
Reference in New Issue
Block a user