{"record":{"id":"df8e8ee5773a72c2","repo":"FoundationAgents/MetaGPT","slug":"workflow-file-not-found-graph-path","errorCode":null,"errorMessage":"Workflow file not found: {graph_path}","messagePattern":"Workflow file not found: (.+?)","errorType":"exception","errorClass":"FileNotFoundError","httpStatus":null,"severity":"error","filePath":"metagpt/ext/aflow/scripts/interface.py","lineNumber":68,"sourceCode":"        dataset: 数据集名称\n        question: 输入问题\n        round: 指定使用的轮次，如果为None则使用最佳轮次\n        llm_name: 使用的LLM模型名称\n        optimized_path: 优化结果保存路径\n\n    Returns:\n        (答案, 成本)的元组\n    \"\"\"\n    # 如果没有指定轮次，使用最佳轮次\n    if round is None:\n        round = load_best_round(dataset, optimized_path)\n\n    logger.info(f\"Using round {round} for inference\")\n\n    # 构建工作流路径并加载\n    graph_path = Path(optimized_path) / dataset / \"workflows\" / f\"round_{round}\" / \"graph.py\"\n    if not graph_path.exists():\n        raise FileNotFoundError(f\"Workflow file not found: {graph_path}\")\n\n    # 动态加载工作流类\n    WorkflowClass = load_workflow_class(str(graph_path))\n\n    # 创建工作流实例\n    llm_config = ModelsConfig.default().get(llm_name)\n    workflow = WorkflowClass(\n        name=f\"{dataset}_workflow\",\n        llm_config=llm_config,\n        dataset=dataset,\n    )\n\n    # 执行推理\n    if dataset in [\"MBPP\", \"HumanEval\"]:\n        # 代码类任务需要额外的entry_point参数\n        answer, cost = await workflow(question, entry_point=entry_point)\n    else:\n        answer, cost = await workflow(question)","sourceCodeStart":50,"sourceCodeEnd":86,"githubUrl":"https://github.com/FoundationAgents/MetaGPT/blob/11cdf466d042aece04fc6cfd13b28e1a70341b1f/metagpt/ext/aflow/scripts/interface.py#L50-L86","documentation":"AFlow's interface builds the workflow path as <optimized_path>/<dataset>/workflows/round_<round>/graph.py and raises FileNotFoundError when it does not exist. The round is either the one you passed or load_best_round()'s pick, so the error means that round's optimized workflow artifact was never produced (or lives under a different dataset/root path).","triggerScenarios":"Calling run_aflow or the interface's inference entry with optimized_path/dataset/round combinations where no round_<N>/graph.py exists: round=5 when optimization only completed 3 rounds; wrong optimized_path root; dataset name not matching the folder created during optimization.","commonSituations":"Inference run before/with an interrupted optimization loop; round=None and the metadata best-round file points at a missing round (crashed optimization); directory renamed or dataset string casing differs from the folder name; copying optimized dirs between machines incompletely.","solutions":["List the actual rounds: ls <optimized_path>/<dataset>/workflows/ and pass an existing round number explicitly.","Verify optimized_path and dataset strings match the real folder names exactly (path is case-sensitive on Linux).","If optimization was interrupted before writing graph.py for the best round, rerun optimization or point at the last complete round.","Check load_best_round's source (best.json/experience file) and correct it if it references a round that was never written."],"exampleFix":"# before\nresult, cost = await run_workflow(dataset=\"HotpotQA\", question=q, optimized_path=\"../optimized\", round=5)\n# FileNotFoundError: Workflow file not found: ../optimized/HotpotQA/workflows/round_5/graph.py\n\n# after\nfrom pathlib import Path\nrounds = sorted(int(p.name.split(\"_\")[1]) for p in Path(\"../optimized/HotpotQA/workflows\").glob(\"round_*\") if p.joinpath(\"graph.py\").exists())\nassert rounds, \"no completed workflow rounds; run optimization first\"\nresult, cost = await run_workflow(dataset=\"HotpotQA\", question=q, optimized_path=\"../optimized\", round=rounds[-1])","handlingStrategy":"validation","validationCode":"from pathlib import Path\n\ndef latest_complete_round(optimized_path: str, dataset: str) -> int | None:\n    wf_dir = Path(optimized_path) / dataset / \"workflows\"\n    rounds = sorted(int(p.name.split(\"_\")[1]) for p in wf_dir.glob(\"round_*\") if (p / \"graph.py\").is_file())\n    return rounds[-1] if rounds else None\n\nrnd = round if round is not None else latest_complete_round(optimized_path, dataset)\nif rnd is None:\n    raise FileNotFoundError(f\"no completed rounds under {optimized_path}/{dataset}; run optimization first\")","typeGuard":null,"tryCatchPattern":"try:\n    result, cost = await run_workflow(dataset=dataset, question=q, optimized_path=optimized_path, round=rnd)\nexcept FileNotFoundError as e:\n    raise FileNotFoundError(f\"round {rnd} has no graph.py; list rounds via ls {optimized_path}/{dataset}/workflows\") from e","preventionTips":["Before inference, enumerate round_* dirs that actually contain graph.py and pass one of those numbers.","Keep dataset strings identical between optimization and inference (folder names are case-sensitive).","After an interrupted optimization, fix the best-round metadata to point at the last complete round."],"tags":["python","aflow","file-not-found","workflow","path-configuration"],"backgroundTag":null,"analyzedSha":"11cdf466d042aece04fc6cfd13b28e1a70341b1f","analyzedAt":"2026-08-14T23:20:02.994Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}