FoundationAgents/MetaGPT · error · FileNotFoundError
Workflow file not found: {graph_path}
Error message
Workflow file not found: {graph_path} What it means
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).
Source
Thrown at metagpt/ext/aflow/scripts/interface.py:68
dataset: 数据集名称
question: 输入问题
round: 指定使用的轮次,如果为None则使用最佳轮次
llm_name: 使用的LLM模型名称
optimized_path: 优化结果保存路径
Returns:
(答案, 成本)的元组
"""
# 如果没有指定轮次,使用最佳轮次
if round is None:
round = load_best_round(dataset, optimized_path)
logger.info(f"Using round {round} for inference")
# 构建工作流路径并加载
graph_path = Path(optimized_path) / dataset / "workflows" / f"round_{round}" / "graph.py"
if not graph_path.exists():
raise FileNotFoundError(f"Workflow file not found: {graph_path}")
# 动态加载工作流类
WorkflowClass = load_workflow_class(str(graph_path))
# 创建工作流实例
llm_config = ModelsConfig.default().get(llm_name)
workflow = WorkflowClass(
name=f"{dataset}_workflow",
llm_config=llm_config,
dataset=dataset,
)
# 执行推理
if dataset in ["MBPP", "HumanEval"]:
# 代码类任务需要额外的entry_point参数
answer, cost = await workflow(question, entry_point=entry_point)
else:
answer, cost = await workflow(question)View on GitHub (pinned to 11cdf466d0)
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.
Example fix
# before
result, cost = await run_workflow(dataset="HotpotQA", question=q, optimized_path="../optimized", round=5)
# FileNotFoundError: Workflow file not found: ../optimized/HotpotQA/workflows/round_5/graph.py
# after
from pathlib import Path
rounds = sorted(int(p.name.split("_")[1]) for p in Path("../optimized/HotpotQA/workflows").glob("round_*") if p.joinpath("graph.py").exists())
assert rounds, "no completed workflow rounds; run optimization first"
result, cost = await run_workflow(dataset="HotpotQA", question=q, optimized_path="../optimized", round=rounds[-1]) Defensive patterns
Strategy: validation
Validate before calling
from pathlib import Path
def latest_complete_round(optimized_path: str, dataset: str) -> int | None:
wf_dir = Path(optimized_path) / dataset / "workflows"
rounds = sorted(int(p.name.split("_")[1]) for p in wf_dir.glob("round_*") if (p / "graph.py").is_file())
return rounds[-1] if rounds else None
rnd = round if round is not None else latest_complete_round(optimized_path, dataset)
if rnd is None:
raise FileNotFoundError(f"no completed rounds under {optimized_path}/{dataset}; run optimization first") Try / catch
try:
result, cost = await run_workflow(dataset=dataset, question=q, optimized_path=optimized_path, round=rnd)
except FileNotFoundError as e:
raise FileNotFoundError(f"round {rnd} has no graph.py; list rounds via ls {optimized_path}/{dataset}/workflows") from e Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- No requirement document found.
- Unsupported dataset: {dataset}
- Missing fields: {missing_fields}
- use `review` after `fill`
- File {path} not found.
AI-assisted analysis of FoundationAgents/MetaGPT@11cdf466d0 (2026-08-14).
Data as JSON: /api/errors/df8e8ee5773a72c2.
Report an issue: GitHub.