Abstract
Large language models (LLMs) have demonstrated remarkable potential insolving complex tasks across diverse domains, typically by employing agenticworkflows that follow detailed instructions and operational sequences. However,constructing these workflows requires significant human effort, limitingscalability and generalizability. Recent research has sought to automate thegeneration and optimization of these workflows, but existing methods still relyon initial manual setup and fall short of achieving fully automated andeffective workflow generation. To address this challenge, we reformulateworkflow optimization as a search problem over code-represented workflows,where LLM-invoking nodes are connected by edges. We introduce AFlow, anautomated framework that efficiently explores this space using Monte Carlo TreeSearch, iteratively refining workflows through code modification,tree-structured experience, and execution feedback. Empirical evaluationsacross six benchmark datasets demonstrate AFlow's efficacy, yielding a 5.7%average improvement over state-of-the-art baselines. Furthermore, AFlow enablessmaller models to outperform GPT-4o on specific tasks at 4.55% of its inferencecost in dollars. The code is available at https://github.com/geekan/MetaGPT.