修复对话背景信息配置

This commit is contained in:
zcr
2026-05-05 14:25:10 +08:00
parent 536be96d10
commit b4c1b5169b
2 changed files with 45 additions and 32 deletions

View File

@@ -210,9 +210,9 @@ async def chat_stream(request: DeepAgentChatRequest):
subgraphs=True, subgraphs=True,
context=Context(use_report=request.use_report, context=Context(use_report=request.use_report,
language=request.language, language=request.language,
type=config_content_type, type=request.config_params.type ,
region=config_content_region, region=request.config_params.region,
style=config_content_style, style=request.config_params.style,
), ),
): ):
_, mode, chunks = stream _, mode, chunks = stream

View File

@@ -97,11 +97,33 @@ async def report_control(request: ToolCallRequest, handler: Callable[[ToolCallRe
@dynamic_prompt @dynamic_prompt
def user_role_prompt(request: ModelRequest) -> str: def user_role_prompt(request: ModelRequest) -> str:
"""Generate system prompts based on use_report status and language preference.""" """Generate system prompts based on use_report status and language preference."""
use_report = request.runtime.context.use_report
language = request.runtime.context.language
# ==================== 报告功能状态提示(支持中英文) ==================== ctx = request.runtime.context
if use_report: # ==================== 调试日志(强烈建议保留) ====================
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_status = """
【Report Function Status】Current use_report = True 【Report Function Status】Current use_report = True
The research-subagent is fully enabled. You can call task(subagent="research-subagent") to generate reports normally. 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." "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. - 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 language_prompt = f"""
{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"""
## Custom Language Rules ## 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. - No mixed languages, no bilingual contrast, no extra English annotations.
- Maintain native, fluent, professional expression conforming to the language habits of {language}. - 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 {language} specification. - 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"] # ==================== 最终组合(设计背景放最前面) ====================
final_prompt = (
logger.info( design_context +
f"Dynamic prompt generated | use_report={use_report} | " "\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 return final_prompt
@@ -172,9 +188,6 @@ class LanguageDetectionMiddleware(AgentMiddleware):
content = last_msg.content if hasattr(last_msg, "content") else str(last_msg) content = last_msg.content if hasattr(last_msg, "content") else str(last_msg)
content = content[0].get("text").strip() content = content[0].get("text").strip()
if len(content) < self.min_length:
return None
try: try:
detected_lang = "en" detected_lang = "en"
confidence = 0 confidence = 0