Skip to content

Commit 3c50782

Browse files
feat: DISABLE_WORKFLOW_GEN
1 parent 546a8f1 commit 3c50782

File tree

2 files changed

+46
-11
lines changed

2 files changed

+46
-11
lines changed

backend/service/mcp_client.py

Lines changed: 44 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
FilePath: /comfyui_copilot/backend/service/mcp-client.py
77
Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
88
'''
9-
from ..utils.globals import BACKEND_BASE_URL, get_comfyui_copilot_api_key
9+
from ..utils.globals import BACKEND_BASE_URL, get_comfyui_copilot_api_key, DISABLE_WORKFLOW_GEN
1010
from .. import core
1111
import asyncio
1212
import os
@@ -199,6 +199,28 @@ def rewrite_handoff_input_filter(data: HandoffInputData) -> HandoffInputData:
199199
on_handoff=on_handoff,
200200
)
201201

202+
# Construct instructions based on DISABLE_WORKFLOW_GEN
203+
if DISABLE_WORKFLOW_GEN:
204+
workflow_creation_instruction = """
205+
**CASE 2: SEARCH WORKFLOW**
206+
IF the user wants to find or generate a NEW workflow.
207+
- Keywords: "create", "generate", "search", "find", "recommend", "生成", "查找", "推荐".
208+
- Action: Use `recall_workflow`.
209+
"""
210+
workflow_constraint = """
211+
- [Critical!] When the user's intent is to get workflows or generate images with specific requirements, you MUST call `recall_workflow` tool to find existing similar workflows.
212+
"""
213+
else:
214+
workflow_creation_instruction = """
215+
**CASE 2: CREATE NEW / SEARCH WORKFLOW**
216+
IF the user wants to find or generate a NEW workflow from scratch.
217+
- Keywords: "create", "generate", "search", "find", "recommend", "生成", "查找", "推荐".
218+
- Action: Use `recall_workflow` AND `gen_workflow`.
219+
"""
220+
workflow_constraint = """
221+
- [Critical!] When the user's intent is to get workflows or generate images with specific requirements, you MUST ALWAYS call BOTH recall_workflow tool AND gen_workflow tool to provide comprehensive workflow options. Never call just one of these tools - both are required for complete workflow assistance. First call recall_workflow to find existing similar workflows, then call gen_workflow to generate new workflow options.
222+
"""
223+
202224
agent = create_agent(
203225
name="ComfyUI-Copilot",
204226
instructions=f"""You are a powerful AI assistant for designing image processing workflows, capable of automating problem-solving using tools and commands.
@@ -220,10 +242,7 @@ def rewrite_handoff_input_filter(data: HandoffInputData) -> HandoffInputData:
220242
- DO NOT call any other tools (like search_node, gen_workflow).
221243
- DO NOT ask for more details. Just handoff.
222244
223-
**CASE 2: CREATE NEW / SEARCH WORKFLOW**
224-
IF the user wants to find or generate a NEW workflow from scratch.
225-
- Keywords: "create", "generate", "search", "find", "recommend", "生成", "查找", "推荐".
226-
- Action: Use `recall_workflow` AND `gen_workflow`.
245+
{workflow_creation_instruction}
227246
228247
### CONSTRAINT CHECKLIST
229248
You must adhere to the following constraints to complete the task:
@@ -241,7 +260,7 @@ def rewrite_handoff_input_filter(data: HandoffInputData) -> HandoffInputData:
241260
- Printing the entire content of a file is strictly prohibited, as such actions have high costs and can lead to unforeseen consequences.
242261
- Ensure that when you call a tool, you have obtained all the input variables for that tool, and do not fabricate any input values for it.
243262
- Respond with markdown, using a minimum of 3 heading levels (H3, H4, H5...), and when including images use the format ![alt text](url),
244-
- [Critical!] When the user's intent is to get workflows or generate images with specific requirements, you MUST ALWAYS call BOTH recall_workflow tool AND gen_workflow tool to provide comprehensive workflow options. Never call just one of these tools - both are required for complete workflow assistance. First call recall_workflow to find existing similar workflows, then call gen_workflow to generate new workflow options.
263+
{workflow_constraint}
245264
- When the user's intent is to query, return the query result directly without attempting to assist the user in performing operations.
246265
- When the user's intent is to get prompts for image generation (like Stable Diffusion). Use specific descriptive language with proper weight modifiers (e.g., (word:1.2)), prefer English terms, and separate elements with commas. Include quality terms (high quality, detailed), style specifications (realistic, anime), lighting (cinematic, golden hour), and composition (wide shot, close up) as needed. When appropriate, include negative prompts to exclude unwanted elements. Return words divided by commas directly without any additional text.
247266
- 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.
@@ -572,10 +591,25 @@ async def process_stream_events(stream_result):
572591
finished = True
573592

574593
elif "recall_workflow" in tool_results and "gen_workflow" not in tool_results:
575-
# Only recall_workflow was called, don't return ext, keep finished=false
576-
log.info("Only recall_workflow was called, waiting for gen_workflow, not returning ext")
577-
ext = None
578-
finished = False # This is the key: keep finished=false to wait for gen_workflow
594+
if DISABLE_WORKFLOW_GEN:
595+
# If generation is disabled, we don't wait for gen_workflow
596+
log.info("Only recall_workflow was called and generation is disabled, returning its result")
597+
recall_result = tool_results["recall_workflow"]
598+
if recall_result["data"] and len(recall_result["data"]) > 0:
599+
ext = [{
600+
"type": "workflow",
601+
"data": recall_result["data"]
602+
}]
603+
log.info(f"Returning {len(recall_result['data'])} workflows from recall_workflow")
604+
else:
605+
ext = None
606+
log.error("recall_workflow failed or returned no data")
607+
finished = True
608+
else:
609+
# Only recall_workflow was called, don't return ext, keep finished=false
610+
log.info("Only recall_workflow was called, waiting for gen_workflow, not returning ext")
611+
ext = None
612+
finished = False # This is the key: keep finished=false to wait for gen_workflow
579613

580614
elif "gen_workflow" in tool_results and "recall_workflow" not in tool_results:
581615
# Only gen_workflow was called, return its result normally

backend/utils/globals.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Author: ai-business-hql [email protected]
33
Date: 2025-08-08 17:14:52
44
LastEditors: ai-business-hql [email protected]
5-
LastEditTime: 2025-09-30 10:18:44
5+
LastEditTime: 2025-11-27 11:12:18
66
FilePath: /comfyui_copilot/backend/utils/globals.py
77
Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
88
'''
@@ -112,6 +112,7 @@ def set_comfyui_copilot_api_key(api_key: str) -> None:
112112
WORKFLOW_LLM_BASE_URL = os.getenv("WORKFLOW_LLM_BASE_URL") or None
113113
# If WORKFLOW_LLM_MODEL is not set, fall back to WORKFLOW_MODEL_NAME
114114
WORKFLOW_LLM_MODEL = os.getenv("WORKFLOW_LLM_MODEL") or WORKFLOW_MODEL_NAME
115+
DISABLE_WORKFLOW_GEN = os.getenv("DISABLE_WORKFLOW_GEN") or False
115116

116117

117118
def apply_llm_env_defaults(config: Optional[Dict[str, Any]] = None) -> Dict[str, Any]:

0 commit comments

Comments
 (0)