From b4c1b5169bdc7d7e7ea47e559248acf3a6fbd189 Mon Sep 17 00:00:00 2001 From: zcr Date: Tue, 5 May 2026 14:25:10 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=AF=B9=E8=AF=9D=E8=83=8C?= =?UTF-8?q?=E6=99=AF=E4=BF=A1=E6=81=AF=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/routers/deep_agent_chat.py | 6 +- src/server/deep_agent/agents/main_agent.py | 71 +++++++++++++--------- 2 files changed, 45 insertions(+), 32 deletions(-) diff --git a/src/routers/deep_agent_chat.py b/src/routers/deep_agent_chat.py index 3b6d41a..b9bc830 100755 --- a/src/routers/deep_agent_chat.py +++ b/src/routers/deep_agent_chat.py @@ -210,9 +210,9 @@ async def chat_stream(request: DeepAgentChatRequest): subgraphs=True, context=Context(use_report=request.use_report, language=request.language, - type=config_content_type, - region=config_content_region, - style=config_content_style, + type=request.config_params.type , + region=request.config_params.region, + style=request.config_params.style, ), ): _, mode, chunks = stream diff --git a/src/server/deep_agent/agents/main_agent.py b/src/server/deep_agent/agents/main_agent.py index e909ecf..225f927 100755 --- a/src/server/deep_agent/agents/main_agent.py +++ b/src/server/deep_agent/agents/main_agent.py @@ -97,11 +97,33 @@ async def report_control(request: ToolCallRequest, handler: Callable[[ToolCallRe @dynamic_prompt def user_role_prompt(request: ModelRequest) -> str: """Generate system prompts based on use_report status and language preference.""" - use_report = request.runtime.context.use_report - language = request.runtime.context.language - # ==================== 报告功能状态提示(支持中英文) ==================== - if use_report: + ctx = request.runtime.context + # ==================== 调试日志(强烈建议保留) ==================== + logger.info(f"Dynamic Prompt Context | " + f"type={ctx.type}, region={ctx.region}, style={ctx.style}, " + f"use_report={ctx.use_report}, language={ctx.language}") + + # ==================== 家具设计背景(加强版) ==================== + design_context = f""" + [Highest priority directive - must be strictly followed] + The furniture design background currently selected by the user is as follows: + + - Category/Type: {ctx.type or 'unspecified'} + - Region: {ctx.region or 'unspecified'} + - Style / Style: {ctx.style or 'unspecified'} + + 【Core Execution Rules】 + 1. When the user requires the generation of any visual content such as line drafts, sketches, design drawings, renderings, pictures, renderings, etc., the design must be 100% based on the above three settings. + 2. When thinking about tasks related to generating images, the first step must be to state: [Current design background] Type: {ctx.type} | Region: {ctx.region} | Style: {ctx.style} + 3. When generating plain text (reports, analyses, suggestions), there is no need to repeatedly emphasize the above settings, just reply in a normal professional tone. + 4. If the user wants pictures + reports at the same time, they must be processed separately. + + Now the user says: "Design it" → Please start designing directly based on the above background, and do not ask for known information such as type, style, region, etc. + """ + + # ==================== Report 状态 ==================== + if ctx.use_report: report_status = """ 【Report Function Status】Current use_report = True The research-subagent is fully enabled. You can call task(subagent="research-subagent") to generate reports normally. @@ -120,31 +142,25 @@ def user_role_prompt(request: ModelRequest) -> str: "To ensure everything works properly, I need you to confirm that the button has been successfully activated. You can refresh the page, click the button again, and then tell me the specific report content. I'll handle it immediately." - Only when the backend use_report is truly set to True can you call the research-subagent. """ - - backend_prompt = f"""Furniture design background settings selected by the current user:\n - {request.runtime.context.type} - {request.runtime.context.region} - {request.runtime.context.style} - 【Important instructions】 - - The above three settings** are only used for tasks related to furniture line drawing/picture generation**. - - When users require the generation of visual content such as line drafts, sketches, design drawings, renderings, etc., the design must be strictly based on the above three settings. - - When users request to generate text content such as reports, analyses, explanations, suggestions, summaries, etc., there is no need to deliberately emphasize or focus on these three settings. They can be described normally and professionally. - - If the user requires the generation of pictures and reports at the same time, please handle them separately: the picture part strictly follows the settings, and the report part is output normally. - - CRITICAL: - - Be sure to use the above settings when generating line drawings/images. - - Do not refer to these three settings repeatedly when generating reports or text-only answers.""" - langguage_prompt = f""" + # ==================== 最终组合(设计背景放最前面) ==================== + language_prompt = f""" ## Custom Language Rules - - All content of the final report and all reply content MUST be fully written in: {language} + - All content of the final report and all reply content MUST be fully written in: {ctx.language} - No mixed languages, no bilingual contrast, no extra English annotations. - - Maintain native, fluent, professional expression conforming to the language habits of {language}. - - All professional terms, captions, notes and reference descriptions must follow the unified {language} specification. + - Maintain native, fluent, professional expression conforming to the language habits of {ctx.language}. + - All professional terms, captions, notes and reference descriptions must follow the unified {ctx.language} specification. """ - final_prompt = backend_prompt + SYSTEM_PROMPT_MAPPING[f'SYSTEM_BASE_PROMPT_en'] + report_status + SYSTEM_PROMPT_MAPPING[f"SYSTEM_RULES_PROMPT_en"] - - logger.info( - f"Dynamic prompt generated | use_report={use_report} | " + # ==================== 最终组合(设计背景放最前面) ==================== + final_prompt = ( + design_context + + "\n\n" + + language_prompt + + "\n\n" + + SYSTEM_PROMPT_MAPPING.get('SYSTEM_BASE_PROMPT_en', '') + + "\n\n" + + report_status + + "\n\n" + + SYSTEM_PROMPT_MAPPING.get('SYSTEM_RULES_PROMPT_en', '') ) return final_prompt @@ -172,9 +188,6 @@ class LanguageDetectionMiddleware(AgentMiddleware): content = last_msg.content if hasattr(last_msg, "content") else str(last_msg) content = content[0].get("text").strip() - if len(content) < self.min_length: - return None - try: detected_lang = "en" confidence = 0