examples/aflow/README.md
AFlow is a framework for automatically generating and optimizing Agentic Workflows. It uses Monte Carlo tree search in a code-represented workflow space to find effective workflows, replacing manual development with machine effort. Our approach shows potential to outperform handcrafted workflows on various tasks.
<p align="center"> <a href="">1</sub>" width="80%"></a> </p>metagpt/actions/action_node.py for a flexible interface to control LLM, temperature, format, and prompt.metagpt/ext/aflow/operator.py for details. You can customize your own Operator by referencing the implementations in this code.metagpt/ext/aflow/workflow.py for our implementation.metagpt/ext/aflow/scripts/optimizer.py for details.metagpt/ext/aflow/scripts/evaluator.py for details.We conducted experiments on six datasets (HumanEval, MBPP, GSM8K, MATH, HotpotQA, DROP) and provide their evaluation code. The data can be found in this datasets link, or you can download them using metagpt/ext/aflow/data/download_data.py
For custom tasks, you can reference the code in the metagpt/ext/aflow/benchmark folder. Inherit the BaseBenchmark class and implement evaluate_problem, calculate_score, and get_result_columns to add your custom dataset benchmark. Then, add your benchmark name in metagpt/ext/aflow/scripts/evaluator.py and metagpt/ext/aflow/scripts/optimizer.py to find effective workflows for your custom dataset.
Configure optimization parameters:
examples/aflow/optimize.py:
--dataset # (Required) Dataset type (HumanEval/MBPP/GSM8K/MATH/HotpotQA/DROP)
--sample 4 # Sample count - number of workflows to be resampled
--optimized_path PATH # Optimized result save path
--initial_round 1 # Initial round
--max_rounds 20 # Max iteration rounds for AFLOW
--check_convergence # Whether to enable early stop
--validation_rounds 5 # Validation rounds for AFLOW
--if_first_optimize # Set True for first optimization, False afterwards
Configure LLM parameters in config/config2.yaml (see examples/aflow/config2.example.yaml for reference)
Set up operators in optimize.py and in optimized_path/template/operator.py, optimized_path/template/operator.json. You can reference our implementation to add operators for specific datasets
For first-time use, download datasets and initial rounds by setting download(["datasets", "initial_rounds"]) in examples/aflow/optimize.py
(Optional) Add your custom dataset and corresponding evaluation function following the Custom Datasets section
(Optional) If you want to use a portion of the validation data, you can set va_list in examples/aflow/evaluator.py
Run the optimization:
# Using default parameters
python -m examples.aflow.optimize --dataset MATH
# Or with custom parameters
python -m examples.aflow.optimize --dataset MATH --sample n --optimized_path xxx ...
metagpt/ext/aflow/data/download_data.py.ExperimentConfig of examples/aflow/optimize.py.If you use AFlow in your research, please cite our paper:
@misc{zhang2024aflow,
title={AFlow: Automating Agentic Workflow Generation},
author={Jiayi Zhang and Jinyu Xiang and Zhaoyang Yu and Fengwei Teng and Xionghui Chen and Jiaqi Chen and Mingchen Zhuge and Xin Cheng and Sirui Hong and Jinlin Wang and Bingnan Zheng and Bang Liu and Yuyu Luo and Chenglin Wu},
year={2024},
eprint={2410.10762},
archivePrefix={arXiv},
primaryClass={cs.AI},
url={https://arxiv.org/abs/2410.10762},
}