feat: 整体优化上下文问题
This commit is contained in:
@@ -177,6 +177,27 @@ async def comfyui_agent_invoke(messages: List[Dict[str, Any]], images: List[Imag
|
||||
|
||||
When handing off to workflow rewrite agent or other agents, this session ID should be used for workflow data management.
|
||||
|
||||
### PRIMARY DIRECTIVE: INTENT CLASSIFICATION & HANDOFF
|
||||
You act as a router. Your FIRST step is to classify the user's intent.
|
||||
|
||||
**CASE 1: MODIFY/UPDATE/FIX CURRENT WORKFLOW (HIGHEST PRIORITY)**
|
||||
IF the user wants to:
|
||||
- Modify, enhance, update, or fix the CURRENT workflow/canvas.
|
||||
- Add nodes/features to the CURRENT workflow (e.g., "add LoRA", "add controlnet", "fix the error").
|
||||
- Change parameters in the CURRENT workflow.
|
||||
- Keywords: "modify", "update", "add", "change", "fix", "current", "canvas", "修改", "更新", "添加", "画布", "加一个", "换一个", "调一下".
|
||||
|
||||
**ACTION:**
|
||||
- You MUST IMMEDIATELY handoff to the `Workflow Rewrite Agent`.
|
||||
- DO NOT call any other tools (like search_node, gen_workflow).
|
||||
- DO NOT ask for more details. Just handoff.
|
||||
|
||||
**CASE 2: CREATE NEW / SEARCH WORKFLOW**
|
||||
IF the user wants to find or generate a NEW workflow from scratch.
|
||||
- Keywords: "create", "generate", "search", "find", "recommend", "生成", "查找", "推荐".
|
||||
- Action: Use `recall_workflow` AND `gen_workflow`.
|
||||
|
||||
### CONSTRAINT CHECKLIST
|
||||
You must adhere to the following constraints to complete the task:
|
||||
|
||||
- [Important!] Respond must in the language used by the user in their question. Regardless of the language returned by the tools being called, please return the results based on the language used in the user's query. For example, if user ask by English, you must return
|
||||
@@ -198,8 +219,6 @@ You must adhere to the following constraints to complete the task:
|
||||
- If you cannot find the information needed to answer a query, consider using bing_search to obtain relevant information. For example, if search_node tool cannot find the node, you can use bing_search to obtain relevant information about those nodes or components.
|
||||
- If search_node tool cannot find the node, you MUST use bing_search to obtain relevant information about those nodes or components.
|
||||
|
||||
- [Critical!] **WORKFLOW REWRITE Intent** - When the user's intent is to functionally modify, enhance, or add NEW features to the current workflow OR modify the current canvas (keywords: "修改当前工作流", "更新工作流", "在当前工作流中添加", "添加功能", "enhance current workflow", "modify workflow", "add to current workflow", "update current workflow", "添加LoRA", "加个upscale", "add upscaling", "修改当前画布", "更新画布", "在画布中", "modify current canvas", "update canvas", "change canvas"), you MUST always handoff to the Workflow Rewrite Agent immediately.
|
||||
|
||||
- **ERROR MESSAGE ANALYSIS** - When a user pastes specific error text/logs (containing terms like "Failed", "Error", "Traceback", or stack traces), prioritize providing troubleshooting help rather than invoking search tools. Follow these steps:
|
||||
1. Analyze the error to identify the root cause (error type, affected component, missing dependencies, etc.)
|
||||
2. Explain the issue in simple terms
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
Author: ai-business-hql qingli.hql@alibaba-inc.com
|
||||
Date: 2025-07-24 17:10:23
|
||||
LastEditors: ai-business-hql ai.bussiness.hql@gmail.com
|
||||
LastEditTime: 2025-11-24 20:50:57
|
||||
LastEditTime: 2025-11-24 20:56:38
|
||||
FilePath: /comfyui_copilot/backend/service/workflow_rewrite_agent.py
|
||||
Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
|
||||
'''
|
||||
@@ -61,7 +61,7 @@ def create_workflow_rewrite_agent():
|
||||
{}
|
||||
""".format(language, json.dumps(get_rewrite_export_schema())) + """
|
||||
|
||||
你可以根据用户的需求,从上面的专家经验中选择一个或多个经验(call get_rewrite_expert_by_name(name_list)),并结合经验内容进行工作流改写。
|
||||
你必须先根据用户的需求,从上面的专家经验中选择经验(call get_rewrite_expert_by_name(name_list)),再结合经验内容进行工作流改写,但如果没有任何相关经验,则不参考专家经验。
|
||||
|
||||
## 复杂工作流处理原则
|
||||
复杂工作流实际上是多个简单的功能性工作流的组合。例如:文生图→抠图取主体→图生图生成背景。
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
import json
|
||||
import time
|
||||
import copy
|
||||
from typing import Dict, Any, Optional
|
||||
|
||||
try:
|
||||
@@ -98,13 +99,28 @@ async def get_node_info(node_class: str) -> str:
|
||||
|
||||
@function_tool
|
||||
async def get_node_infos(node_class_list: list[str]) -> str:
|
||||
"""获取多个节点的详细信息,包括输入输出参数。只做最小化有必要的查询,不要查询所有节点。尽量不要超过5个"""
|
||||
"""获取多个节点的详细信息,包括输入输出参数。只做最小化有必要的查询,不要查询很常见的LLM已知用法的节点。尽量不要超过5个"""
|
||||
try:
|
||||
object_info = await get_object_info()
|
||||
node_infos = {}
|
||||
for node_class in node_class_list:
|
||||
if node_class in object_info:
|
||||
node_infos[node_class] = object_info[node_class]
|
||||
# Deep copy to avoid modifying the original cached object info
|
||||
node_data = copy.deepcopy(object_info[node_class])
|
||||
|
||||
# Truncate long lists in input parameters to save context
|
||||
input_data = node_data.get("input", {})
|
||||
for req_opt in ["required", "optional"]:
|
||||
params = input_data.get(req_opt, {})
|
||||
for param_name, param_config in params.items():
|
||||
# param_config is typically [type_or_list, config_dict]
|
||||
if isinstance(param_config, list) and len(param_config) > 0:
|
||||
# Check if the first element is a list (which means it's a selection list)
|
||||
if isinstance(param_config[0], list):
|
||||
if len(param_config[0]) > 3:
|
||||
param_config[0] = param_config[0][:3]
|
||||
|
||||
node_infos[node_class] = node_data
|
||||
return json.dumps(node_infos)
|
||||
except Exception as e:
|
||||
return json.dumps({"error": f"Failed to get node infos of {','.join(node_class_list)}: {str(e)}"})
|
||||
@@ -116,8 +132,9 @@ async def search_node_local(node_class: str = "", keywords: list[str] = None, li
|
||||
1. 优先使用 node_class 按节点类名精确查询。
|
||||
2. 如果没有命中,则在全部节点中使用 node_class 和 keywords 做联合模糊搜索:
|
||||
- 关键词会在节点类名、名称、显示名、分类、描述以及输入参数名中匹配。
|
||||
- 关键词是英文。
|
||||
- 关键词应该尽量具体(例如 "brightness"、"contrast"、"saturation"、"sharpness"),
|
||||
避免使用过于宽泛的词(例如 "image"、"图像" 等),以减少噪声结果。
|
||||
避免使用过于宽泛的词(例如 "image" 等),以减少噪声结果。
|
||||
"""
|
||||
try:
|
||||
node_class_str = (node_class or "").strip()
|
||||
|
||||
Reference in New Issue
Block a user