mirror of
https://gitee.com/wanwujie/deer-flow
synced 2026-04-26 15:24:48 +08:00
feat: Add intelligent clarification feature in coordinate step for research queries (#613)
* fix: support local models by making thought field optional in Plan model - Make thought field optional in Plan model to fix Pydantic validation errors with local models - Add Ollama configuration example to conf.yaml.example - Update documentation to include local model support - Improve planner prompt with better JSON format requirements Fixes local model integration issues where models like qwen3:14b would fail due to missing thought field in JSON output. * feat: Add intelligent clarification feature for research queries - Add multi-turn clarification process to refine vague research questions - Implement three-dimension clarification standard (Tech/App, Focus, Scope) - Add clarification state management in coordinator node - Update coordinator prompt with detailed clarification guidelines - Add UI settings to enable/disable clarification feature (disabled by default) - Update workflow to handle clarification rounds recursively - Add comprehensive test coverage for clarification functionality - Update documentation with clarification feature usage guide Key components: - src/graph/nodes.py: Core clarification logic and state management - src/prompts/coordinator.md: Detailed clarification guidelines - src/workflow.py: Recursive clarification handling - web/: UI settings integration - tests/: Comprehensive test coverage - docs/: Updated configuration guide * fix: Improve clarification conversation continuity - Add comprehensive conversation history to clarification context - Include previous exchanges summary in system messages - Add explicit guidelines for continuing rounds in coordinator prompt - Prevent LLM from starting new topics during clarification - Ensure topic continuity across clarification rounds Fixes issue where LLM would restart clarification instead of building upon previous exchanges. * fix: Add conversation history to clarification context * fix: resolve clarification feature message to planer, prompt, test issues - Optimize coordinator.md prompt template for better clarification flow - Simplify final message sent to planner after clarification - Fix API key assertion issues in test_search.py * fix: Add configurable max_clarification_rounds and comprehensive tests - Add max_clarification_rounds parameter for external configuration - Add comprehensive test cases for clarification feature in test_app.py - Fixes issues found during interactive mode testing where: - Recursive call failed due to missing initial_state parameter - Clarification exited prematurely at max rounds - Incorrect logging of max rounds reached * Move clarification tests to test_nodes.py and add max_clarification_rounds to zh.json
This commit is contained in:
28
main.py
28
main.py
@@ -20,6 +20,8 @@ def ask(
|
||||
max_plan_iterations=1,
|
||||
max_step_num=3,
|
||||
enable_background_investigation=True,
|
||||
enable_clarification=False,
|
||||
max_clarification_rounds=None,
|
||||
):
|
||||
"""Run the agent workflow with the given question.
|
||||
|
||||
@@ -29,6 +31,8 @@ def ask(
|
||||
max_plan_iterations: Maximum number of plan iterations
|
||||
max_step_num: Maximum number of steps in a plan
|
||||
enable_background_investigation: If True, performs web search before planning to enhance context
|
||||
enable_clarification: If False (default), skip clarification; if True, enable multi-turn clarification
|
||||
max_clarification_rounds: Maximum number of clarification rounds (default: None, uses State default=3)
|
||||
"""
|
||||
asyncio.run(
|
||||
run_agent_workflow_async(
|
||||
@@ -37,6 +41,8 @@ def ask(
|
||||
max_plan_iterations=max_plan_iterations,
|
||||
max_step_num=max_step_num,
|
||||
enable_background_investigation=enable_background_investigation,
|
||||
enable_clarification=enable_clarification,
|
||||
max_clarification_rounds=max_clarification_rounds,
|
||||
)
|
||||
)
|
||||
|
||||
@@ -46,6 +52,8 @@ def main(
|
||||
max_plan_iterations=1,
|
||||
max_step_num=3,
|
||||
enable_background_investigation=True,
|
||||
enable_clarification=False,
|
||||
max_clarification_rounds=None,
|
||||
):
|
||||
"""Interactive mode with built-in questions.
|
||||
|
||||
@@ -54,6 +62,8 @@ def main(
|
||||
debug: If True, enables debug level logging
|
||||
max_plan_iterations: Maximum number of plan iterations
|
||||
max_step_num: Maximum number of steps in a plan
|
||||
enable_clarification: If False (default), skip clarification; if True, enable multi-turn clarification
|
||||
max_clarification_rounds: Maximum number of clarification rounds (default: None, uses State default=3)
|
||||
"""
|
||||
# First select language
|
||||
language = inquirer.select(
|
||||
@@ -93,6 +103,8 @@ def main(
|
||||
max_plan_iterations=max_plan_iterations,
|
||||
max_step_num=max_step_num,
|
||||
enable_background_investigation=enable_background_investigation,
|
||||
enable_clarification=enable_clarification,
|
||||
max_clarification_rounds=max_clarification_rounds,
|
||||
)
|
||||
|
||||
|
||||
@@ -124,6 +136,18 @@ if __name__ == "__main__":
|
||||
dest="enable_background_investigation",
|
||||
help="Disable background investigation before planning",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--enable-clarification",
|
||||
action="store_true",
|
||||
dest="enable_clarification",
|
||||
help="Enable multi-turn clarification for vague questions (default: disabled)",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--max-clarification-rounds",
|
||||
type=int,
|
||||
dest="max_clarification_rounds",
|
||||
help="Maximum number of clarification rounds (default: 3)",
|
||||
)
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
@@ -134,6 +158,8 @@ if __name__ == "__main__":
|
||||
max_plan_iterations=args.max_plan_iterations,
|
||||
max_step_num=args.max_step_num,
|
||||
enable_background_investigation=args.enable_background_investigation,
|
||||
enable_clarification=args.enable_clarification,
|
||||
max_clarification_rounds=args.max_clarification_rounds,
|
||||
)
|
||||
else:
|
||||
# Parse user input from command line arguments or user input
|
||||
@@ -153,4 +179,6 @@ if __name__ == "__main__":
|
||||
max_plan_iterations=args.max_plan_iterations,
|
||||
max_step_num=args.max_step_num,
|
||||
enable_background_investigation=args.enable_background_investigation,
|
||||
enable_clarification=args.enable_clarification,
|
||||
max_clarification_rounds=args.max_clarification_rounds,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user