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:
Willem Jiang
2025-10-24 21:26:48 +08:00
committed by GitHub
parent 975b344ca7
commit 36bf5c9ccd
5 changed files with 794 additions and 6 deletions

View File

@@ -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