Files
deer-flow/src/server/chat_request.py
jimmyuconn1982 2510cc61de 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
2025-10-14 13:35:57 +08:00

118 lines
4.4 KiB
Python

# Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
# SPDX-License-Identifier: MIT
from typing import List, Optional, Union
from pydantic import BaseModel, Field
from src.config.report_style import ReportStyle
from src.rag.retriever import Resource
class ContentItem(BaseModel):
type: str = Field(..., description="The type of content (text, image, etc.)")
text: Optional[str] = Field(None, description="The text content if type is 'text'")
image_url: Optional[str] = Field(
None, description="The image URL if type is 'image'"
)
class ChatMessage(BaseModel):
role: str = Field(
..., description="The role of the message sender (user or assistant)"
)
content: Union[str, List[ContentItem]] = Field(
...,
description="The content of the message, either a string or a list of content items",
)
class ChatRequest(BaseModel):
messages: Optional[List[ChatMessage]] = Field(
[], description="History of messages between the user and the assistant"
)
resources: Optional[List[Resource]] = Field(
[], description="Resources to be used for the research"
)
debug: Optional[bool] = Field(False, description="Whether to enable debug logging")
thread_id: Optional[str] = Field(
"__default__", description="A specific conversation identifier"
)
max_plan_iterations: Optional[int] = Field(
1, description="The maximum number of plan iterations"
)
max_step_num: Optional[int] = Field(
3, description="The maximum number of steps in a plan"
)
max_search_results: Optional[int] = Field(
3, description="The maximum number of search results"
)
auto_accepted_plan: Optional[bool] = Field(
False, description="Whether to automatically accept the plan"
)
interrupt_feedback: Optional[str] = Field(
None, description="Interrupt feedback from the user on the plan"
)
mcp_settings: Optional[dict] = Field(
None, description="MCP settings for the chat request"
)
enable_background_investigation: Optional[bool] = Field(
True, description="Whether to get background investigation before plan"
)
report_style: Optional[ReportStyle] = Field(
ReportStyle.ACADEMIC, description="The style of the report"
)
enable_deep_thinking: Optional[bool] = Field(
False, description="Whether to enable deep thinking"
)
enable_clarification: Optional[bool] = Field(
None,
description="Whether to enable multi-turn clarification (default: None, uses State default=False)",
)
max_clarification_rounds: Optional[int] = Field(
None,
description="Maximum number of clarification rounds (default: None, uses State default=3)",
)
class TTSRequest(BaseModel):
text: str = Field(..., description="The text to convert to speech")
voice_type: Optional[str] = Field(
"BV700_V2_streaming", description="The voice type to use"
)
encoding: Optional[str] = Field("mp3", description="The audio encoding format")
speed_ratio: Optional[float] = Field(1.0, description="Speech speed ratio")
volume_ratio: Optional[float] = Field(1.0, description="Speech volume ratio")
pitch_ratio: Optional[float] = Field(1.0, description="Speech pitch ratio")
text_type: Optional[str] = Field("plain", description="Text type (plain or ssml)")
with_frontend: Optional[int] = Field(
1, description="Whether to use frontend processing"
)
frontend_type: Optional[str] = Field("unitTson", description="Frontend type")
class GeneratePodcastRequest(BaseModel):
content: str = Field(..., description="The content of the podcast")
class GeneratePPTRequest(BaseModel):
content: str = Field(..., description="The content of the ppt")
class GenerateProseRequest(BaseModel):
prompt: str = Field(..., description="The content of the prose")
option: str = Field(..., description="The option of the prose writer")
command: Optional[str] = Field(
"", description="The user custom command of the prose writer"
)
class EnhancePromptRequest(BaseModel):
prompt: str = Field(..., description="The original prompt to enhance")
context: Optional[str] = Field(
"", description="Additional context about the intended use"
)
report_style: Optional[str] = Field(
"academic", description="The style of the report"
)