import asyncio import json import sys import os # 将 Agent 根目录加入 sys.path sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..'))) from agent.llm.qwen import qwen_llm_call async def main(): case_path = os.path.join(os.path.dirname(__file__), 'output', '04_parallel', 'case.json') out_path = os.path.join(os.path.dirname(__file__), 'output', '04_parallel', 'strategy.json') if not os.path.exists(case_path): print(f"Error: {case_path} does not exist.") return print("Loading case.json...") with open(case_path, 'r', encoding='utf-8') as f: case_data = json.load(f) # 提取精简的提示词 prompt = f""" 你是一个工序调研协调器。你面前已经有了 54 个子 Agent 刚刚从各大平台收集回来的调研案例(见下方 JSON)。 这里的核心需求是:生成带有明显颗粒感或纸张纹理的插画风格图片。 请分析这些案例并总结、提取、设计制作最终的打法策略,按照下方强制的 JSON 格式输出,不要包含 Markdown 代码块(如 ```json 等),纯粹返回合法的 JSON 字符串。 强制输出格式: {{ "selected_strategy": {{ "name": "端到端策略命名(如:分层生成 + 颗粒噪点叠加 + FLUX局部精修)", "source": "指明主要受到这批采集回来的哪些 case 的启发", "workflow_outline": [ {{ "phase": "阶段1:底层结构与材质生成", "description": "这个阶段要完成的子目标...", "capabilities": [ {{ "capability_id": null, "capability_name": "原子能力名称", "is_new": true, "suggested_tools": ["提取自Case的建议工具"], "case_references": ["来源于哪个case的反馈"] }} ] }} ] }} }} 调研案例 JSON 内容如下: {json.dumps(case_data, ensure_ascii=False)} """ print("Submitting to Qwen-Plus for strategy generation...") messages = [{"role": "user", "content": prompt}] try: response = await qwen_llm_call(messages, model="qwen-plus", temperature=0.3) content = response.get("content", "").strip() # 清理多余的 Markdown 标记 if content.startswith("```json"): content = content[7:] elif content.startswith("```"): content = content[3:] if content.endswith("```"): content = content[:-3] content = content.strip() with open(out_path, 'w', encoding='utf-8') as f: f.write(content) print(f"\\n✅ Strategy successfully saved to: {out_path}") except Exception as e: print(f"\\n❌ Generation failed: {str(e)}") if __name__ == "__main__": asyncio.run(main())