|
2 | 2 | Author: ai-business-hql [email protected] |
3 | 3 | Date: 2025-06-16 16:50:17 |
4 | 4 | LastEditors: ai-business-hql [email protected] |
5 | | -LastEditTime: 2025-11-17 15:09:44 |
| 5 | +LastEditTime: 2025-11-18 19:18:30 |
6 | 6 | FilePath: /comfyui_copilot/backend/service/mcp-client.py |
7 | 7 | Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE |
8 | 8 | ''' |
@@ -63,6 +63,51 @@ async def comfyui_agent_invoke(messages: List[Dict[str, Any]], images: List[Imag |
63 | 63 | tuple: (text, ext) where text is accumulated text and ext is structured data |
64 | 64 | """ |
65 | 65 | try: |
| 66 | + # ------------------------------------------------------------------ |
| 67 | + # Sanitize messages to avoid provider validation errors |
| 68 | + # Some backends (e.g. Bedrock via ConverseStream) reject requests if |
| 69 | + # the final assistant message content ends with trailing whitespace. |
| 70 | + # We defensively strip only *trailing* whitespace from assistant text |
| 71 | + # segments, preserving internal spaces and formatting. |
| 72 | + # ------------------------------------------------------------------ |
| 73 | + def _strip_trailing_whitespace_from_messages( |
| 74 | + msgs: List[Dict[str, Any]] |
| 75 | + ) -> List[Dict[str, Any]]: |
| 76 | + cleaned: List[Dict[str, Any]] = [] |
| 77 | + for msg in msgs: |
| 78 | + role = msg.get("role") |
| 79 | + # Only touch assistant messages to minimize impact |
| 80 | + if role != "assistant": |
| 81 | + cleaned.append(msg) |
| 82 | + continue |
| 83 | + |
| 84 | + msg_copy = dict(msg) |
| 85 | + content = msg_copy.get("content") |
| 86 | + |
| 87 | + # Simple string content |
| 88 | + if isinstance(content, str): |
| 89 | + msg_copy["content"] = content.rstrip() |
| 90 | + # OpenAI / Agents style list content blocks |
| 91 | + elif isinstance(content, list): |
| 92 | + new_content = [] |
| 93 | + for part in content: |
| 94 | + if isinstance(part, dict): |
| 95 | + part_copy = dict(part) |
| 96 | + # Common text block key is "text" |
| 97 | + text_val = part_copy.get("text") |
| 98 | + if isinstance(text_val, str): |
| 99 | + part_copy["text"] = text_val.rstrip() |
| 100 | + new_content.append(part_copy) |
| 101 | + else: |
| 102 | + new_content.append(part) |
| 103 | + msg_copy["content"] = new_content |
| 104 | + |
| 105 | + cleaned.append(msg_copy) |
| 106 | + |
| 107 | + return cleaned |
| 108 | + |
| 109 | + messages = _strip_trailing_whitespace_from_messages(messages) |
| 110 | + |
66 | 111 | # Get session_id and config from request context |
67 | 112 | session_id = get_session_id() |
68 | 113 | config = get_config() |
@@ -141,9 +186,7 @@ async def on_handoff(ctx: RunContextWrapper[None], input_data: HandoffRewriteDat |
141 | 186 | - 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. |
142 | 187 | - If search_node tool cannot find the node, you MUST use bing_search to obtain relevant information about those nodes or components. |
143 | 188 |
|
144 | | -- **DEBUG Intent** - When the user's intent is to debug workflow execution problems, runtime errors, or troubleshoot failed workflows (keywords: "debug", "调试", "工作流报错", "执行失败", "workflow failed", "node error", "runtime error", "不能运行", "出错了"), respond with: "Please click the 🪲 button in the bottom right corner to trigger debug" |
145 | | -
|
146 | | -- **WORKFLOW REWRITE Intent** - [Critical!] 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 handoff to the Workflow Rewrite Agent immediately. This is for feature enhancements, not error fixes. |
| 189 | +- [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. |
147 | 190 |
|
148 | 191 | - **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: |
149 | 192 | 1. Analyze the error to identify the root cause (error type, affected component, missing dependencies, etc.) |
|
0 commit comments