修复 title 总结失败bug,新增enable_thinking参数

This commit is contained in:
zcr
2026-03-23 16:52:11 +08:00
parent d5ef985e52
commit 7c23d16ea6
5 changed files with 20 additions and 15 deletions

View File

@@ -39,6 +39,7 @@ async def chat_stream(request: DeepAgentChatRequest):
#### 2. 请求参数 #### 2. 请求参数
* `message`: 用户的设计意图(如:'我想设计一个极简风格的橡木办公桌')。 * `message`: 用户的设计意图(如:'我想设计一个极简风格的橡木办公桌')。
* `enable_thinking`: 是否开启思考模式。
* `quote_image_path`: 用户引用图片地址 如:"fida-test/furniture/sketches/8a1804d1-5ac9-4d02-bf17-e65fa7272f65.png" * `quote_image_path`: 用户引用图片地址 如:"fida-test/furniture/sketches/8a1804d1-5ac9-4d02-bf17-e65fa7272f65.png"
* `input_image_paths`: 用户上传图片地址集合如:["fida-test/furniture/sketches/8a1804d1-5ac9-4d02-bf17-e65fa7272f65.png"]。 * `input_image_paths`: 用户上传图片地址集合如:["fida-test/furniture/sketches/8a1804d1-5ac9-4d02-bf17-e65fa7272f65.png"]。
* `thread_id`: (可选) 现有项目的唯一标识。若不传,系统将自动分配并返回。 * `thread_id`: (可选) 现有项目的唯一标识。若不传,系统将自动分配并返回。
@@ -106,7 +107,7 @@ async def chat_stream(request: DeepAgentChatRequest):
# 构建主agent # 构建主agent
workspace_dir = os.path.join(PROJECT_ROOT, f"agent_workspace/{target_thread_id}") workspace_dir = os.path.join(PROJECT_ROOT, f"agent_workspace/{target_thread_id}")
logger.info(f"chat request data: {request} | target_thread_id : workspace_dir: {workspace_dir}") logger.info(f"chat request data: {request} | target_thread_id : workspace_dir: {workspace_dir}")
main_agent = build_main_agent(request.use_report, workspace_dir) main_agent = build_main_agent(request.use_report, workspace_dir, request.enable_thinking)
# 2. 配置參數 # 2. 配置參數
temp = request.config_params.temperature if request.config_params else 0.7 temp = request.config_params.temperature if request.config_params else 0.7
@@ -318,7 +319,7 @@ async def chat_stream(request: DeepAgentChatRequest):
# 获取标题 # 获取标题
if need_title: if need_title:
title = await conversation_title(agent=main_agent, config=current_config) title = await conversation_title(agent=main_agent, config=current_config)
logger.info(f"[need_title] {title}") logger.info(f"[title] {title}")
yield f"data: {json.dumps({'title': title}, ensure_ascii=False)}\n\n" yield f"data: {json.dumps({'title': title}, ensure_ascii=False)}\n\n"
yield f"data: {json.dumps({'status': 'end'}, ensure_ascii=False)}\n\n" yield f"data: {json.dumps({'status': 'end'}, ensure_ascii=False)}\n\n"

View File

@@ -11,6 +11,7 @@ class AgentConfig(BaseModel):
class DeepAgentChatRequest(BaseModel): class DeepAgentChatRequest(BaseModel):
message: str = Field(..., description="用户的输入指令") message: str = Field(..., description="用户的输入指令")
enable_thinking: Optional[bool] = Field(default=False, description="是否开启思考模式")
quote_image_path: Optional[str] = Field(None, description="引用图片地址") # ✅ 新增 quote_image_path: Optional[str] = Field(None, description="引用图片地址") # ✅ 新增
input_image_paths: Optional[list[str]] = Field(None, description="上传图片地址集合") # ✅ 新增 input_image_paths: Optional[list[str]] = Field(None, description="上传图片地址集合") # ✅ 新增
thread_id: Optional[str] = Field(None, description="会话线程ID不传则开启新会话") thread_id: Optional[str] = Field(None, description="会话线程ID不传则开启新会话")

View File

@@ -9,7 +9,7 @@ from src.core.config import MONGO_URI
from src.server.deep_agent.agents.painter import build_painter_subagent from src.server.deep_agent.agents.painter import build_painter_subagent
from src.server.deep_agent.agents.researcher import build_researcher_subagent from src.server.deep_agent.agents.researcher import build_researcher_subagent
from src.server.deep_agent.agents.user_profile import user_profile_subagent from src.server.deep_agent.agents.user_profile import user_profile_subagent
from src.server.deep_agent.init_llm import main_llm from src.server.deep_agent.init_llm import build_main_llm
from src.server.deep_agent.init_prompt import build_system_prompt from src.server.deep_agent.init_prompt import build_system_prompt
client = MongoClient(MONGO_URI) client = MongoClient(MONGO_URI)
@@ -39,7 +39,7 @@ class CanvasMiddleware:
return state, agent_input return state, agent_input
def build_main_agent(use_report, workspace_dir): def build_main_agent(use_report, workspace_dir, enable_thinking):
research_subagent = build_researcher_subagent(workspace_dir) research_subagent = build_researcher_subagent(workspace_dir)
painter_subagent = build_painter_subagent(workspace_dir) painter_subagent = build_painter_subagent(workspace_dir)
subagents = [ subagents = [
@@ -48,7 +48,7 @@ def build_main_agent(use_report, workspace_dir):
user_profile_subagent user_profile_subagent
] ]
main_agent = create_deep_agent( main_agent = create_deep_agent(
model=main_llm, model=build_main_llm(enable_thinking=enable_thinking),
system_prompt=build_system_prompt(use_report=use_report), system_prompt=build_system_prompt(use_report=use_report),
subagents=subagents, subagents=subagents,
checkpointer=checkpointer, checkpointer=checkpointer,
@@ -58,7 +58,7 @@ def build_main_agent(use_report, workspace_dir):
), ),
middleware=[ middleware=[
SummarizationMiddleware( SummarizationMiddleware(
model=main_llm, model=build_main_llm(enable_thinking=enable_thinking),
trigger=("tokens", 3000), trigger=("tokens", 3000),
keep=("messages", 100), keep=("messages", 100),
), ),

View File

@@ -22,13 +22,18 @@ title_llm = ChatQwen(
api_key=settings.QWEN_API_KEY api_key=settings.QWEN_API_KEY
) )
main_llm = ChatQwen(
model="qwen3.5-flash", def build_main_llm(enable_thinking):
temperature=0.2, main_llm = ChatQwen(
max_tokens=3_000, enable_thinking=enable_thinking,
timeout=None, model="qwen3.5-flash",
max_retries=2, temperature=0.2,
api_key=settings.QWEN_API_KEY) max_tokens=3_000,
timeout=None,
max_retries=2,
api_key=settings.QWEN_API_KEY)
return main_llm
suggested_llm = ChatQwen( suggested_llm = ChatQwen(
model="qwen-plus", model="qwen-plus",

View File

@@ -22,8 +22,6 @@ async def conversation_title(agent, config):
if user_msg and ai_msg: if user_msg and ai_msg:
break break
if not user_msg or not ai_msg:
return None
prompt = f""" prompt = f"""
请根据以下首次对话内容生成一个简洁、精准的标题2-15个字 请根据以下首次对话内容生成一个简洁、精准的标题2-15个字