You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

README.md 9.6 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. # AutoGenBench
  2. AutoGenBench (agbench) is a tool for repeatedly running a set of pre-defined AutoGen tasks in a setting with tightly-controlled initial conditions. With each run, AutoGenBench will start from a blank slate. The agents being evaluated will need to work out what code needs to be written, and what libraries or dependencies to install, to solve tasks. The results of each run are logged, and can be ingested by analysis or metrics scripts (such as `agbench tabulate`). By default, all runs are conducted in freshly-initialized docker containers, providing the recommended level of consistency and safety.
  3. AutoGenBench works with all AutoGen 0.1.*, and 0.2.* versions.
  4. ## Technical Specifications
  5. If you are already an AutoGenBench pro, and want the full technical specifications, please review the [contributor's guide](CONTRIBUTING.md).
  6. ## Docker Requirement
  7. AutoGenBench also requires Docker (Desktop or Engine). **It will not run in GitHub codespaces**, unless you opt for native execution (which is strongly discouraged). To install Docker Desktop see [https://www.docker.com/products/docker-desktop/](https://www.docker.com/products/docker-desktop/).
  8. If you are working in WSL, you can follow the instructions below to set up your environment:
  9. 1. Install Docker Desktop. After installation, restart is needed, then open Docker Desktop, in Settings, Ressources, WSL Integration, Enable integration with additional distros – Ubuntu
  10. 2. Clone autogen and export `AUTOGEN_REPO_BASE`. This environment variable enables the Docker containers to use the correct version agents.
  11. ```bash
  12. git clone git@github.com:microsoft/autogen.git
  13. export AUTOGEN_REPO_BASE=<path_to_autogen>
  14. ```
  15. ## Installation and Setup
  16. [Deprecated currently] **To get the most out of AutoGenBench, the `agbench` package should be installed**. At present, the easiest way to do this is to install it via `pip`.
  17. If you would prefer working from source code (e.g., for development, or to utilize an alternate branch), simply clone the [AutoGen](https://github.com/microsoft/autogen) repository, then install `agbench` via:
  18. ```
  19. pip install -e autogen/python/packages/agbench
  20. ```
  21. After installation, you must configure your API keys. As with other AutoGen applications, AutoGenBench will look for the OpenAI keys in the OAI_CONFIG_LIST file in the current working directory, or the OAI_CONFIG_LIST environment variable. This behavior can be overridden using a command-line parameter described later.
  22. If you will be running multiple benchmarks, it is often most convenient to leverage the environment variable option. You can load your keys into the environment variable by executing:
  23. ```
  24. export OAI_CONFIG_LIST=$(cat ./OAI_CONFIG_LIST)
  25. ```
  26. If an OAI_CONFIG_LIST is *not* provided (by means of file or environment variable), AutoGenBench will use the OPENAI_API_KEY environment variable instead.
  27. For some benchmark scenarios, additional keys may be required (e.g., keys for the Bing Search API). These can be added to an `ENV.json` file in the current working folder. An example `ENV.json` file is provided below:
  28. ```
  29. {
  30. "BING_API_KEY": "xxxyyyzzz"
  31. }
  32. ```
  33. ## A Typical Session
  34. Once AutoGenBench and necessary keys are installed, a typical session will look as follows:
  35. Navigate to HumanEval
  36. ```bash
  37. cd autogen/python/packages/agbench/benchmarks/HumanEval
  38. ```
  39. **Note:** The following instructions are specific to the HumanEval benchmark. For other benchmarks, please refer to the README in the respective benchmark folder, e.g.,: [AssistantBench](benchmarks/AssistantBench/README.md).
  40. Create a file called ENV.json with the following (required) contents (If you're using MagenticOne), if using Azure:
  41. ```json
  42. {
  43. "CHAT_COMPLETION_KWARGS_JSON": "{}",
  44. "CHAT_COMPLETION_PROVIDER": "azure"
  45. }
  46. ```
  47. You can also use the openai client by replacing the last two entries in the ENV file by:
  48. - `CHAT_COMPLETION_PROVIDER='openai'`
  49. - `CHAT_COMPLETION_KWARGS_JSON` with the following JSON structure:
  50. ```json
  51. {
  52. "api_key": "REPLACE_WITH_YOUR_API",
  53. "model": "REPLACE_WITH_YOUR_MODEL"
  54. }
  55. ```
  56. Now initialize the tasks.
  57. ```bash
  58. python Scripts/init_tasks.py
  59. ```
  60. Note: This will attempt to download HumanEval
  61. Once the script completes, you should now see a folder in your current directory called `Tasks` that contains one JSONL file per template in `Templates`.
  62. Now to run a specific subset of HumanEval use:
  63. ```bash
  64. agbench run Tasks/human_eval_MagenticOne.jsonl
  65. ```
  66. You should see the command line print the raw logs that shows the agents in action To see a summary of the results (e.g., task completion rates), in a new terminal run the following:
  67. ```bash
  68. agbench tabulate Results/human_eval_MagenticOne
  69. ```
  70. Where:
  71. - `agbench run Tasks/human_eval_MagenticOne.jsonl` runs the tasks defined in `Tasks/human_eval_MagenticOne.jsonl`
  72. - `agbench tablue results/human_eval_MagenticOne` tabulates the results of the run
  73. Each of these commands has extensive in-line help via:
  74. - `agbench --help`
  75. - `agbench run --help`
  76. - `agbench tabulate --help`
  77. - `agbench remove_missing --help`
  78. **NOTE:** If you are running `agbench` from within the repository, you need to navigate to the appropriate scenario folder (e.g., `scenarios/HumanEval`) and run the `Scripts/init_tasks.py` file.
  79. More details of each command are provided in the sections that follow.
  80. ## Running AutoGenBench
  81. To run a benchmark (which executes the tasks, but does not compute metrics), simply execute:
  82. ```
  83. cd [BENCHMARK]
  84. agbench run Tasks/*.jsonl
  85. ```
  86. For example,
  87. ```
  88. cd HumanEval
  89. agbench run Tasks/human_eval_MagenticOne.jsonl
  90. ```
  91. The default is to run each task once. To run each scenario 10 times, use:
  92. ```
  93. agbench run --repeat 10 Tasks/human_eval_MagenticOne.jsonl
  94. ```
  95. The `agbench` command-line tool allows a number of command-line arguments to control various parameters of execution. Type ``agbench -h`` to explore these options:
  96. ```
  97. 'agbench run' will run the specified autogen scenarios for a given number of repetitions and record all logs and trace information. When running in a Docker environment (default), each run will begin from a common, tightly controlled, environment. The resultant logs can then be further processed by other scripts to produce metrics.
  98. positional arguments:
  99. scenario The JSONL scenario file to run. If a directory is specified,
  100. then all JSONL scenarios in the directory are run. (default:
  101. ./scenarios)
  102. options:
  103. -h, --help show this help message and exit
  104. -c CONFIG, --config CONFIG
  105. The environment variable name or path to the OAI_CONFIG_LIST (default: OAI_CONFIG_LIST).
  106. -r REPEAT, --repeat REPEAT
  107. The number of repetitions to run for each scenario (default: 1).
  108. -s SUBSAMPLE, --subsample SUBSAMPLE
  109. Run on a subsample of the tasks in the JSONL file(s). If a decimal value is specified, then run on
  110. the given proportion of tasks in each file. For example "0.7" would run on 70% of tasks, and "1.0"
  111. would run on 100% of tasks. If an integer value is specified, then randomly select *that* number of
  112. tasks from each specified JSONL file. For example "7" would run tasks, while "1" would run only 1
  113. task from each specified JSONL file. (default: 1.0; which is 100%)
  114. -m MODEL, --model MODEL
  115. Filters the config_list to include only models matching the provided model name (default: None, which
  116. is all models).
  117. --requirements REQUIREMENTS
  118. The requirements file to pip install before running the scenario.
  119. -d DOCKER_IMAGE, --docker-image DOCKER_IMAGE
  120. The Docker image to use when running scenarios. Can not be used together with --native. (default:
  121. 'agbench:default', which will be created if not present)
  122. --native Run the scenarios natively rather than in docker. NOTE: This is not advisable, and should be done
  123. with great caution.
  124. ```
  125. ## Results
  126. By default, the AutoGenBench stores results in a folder hierarchy with the following template:
  127. ``./results/[scenario]/[task_id]/[instance_id]``
  128. For example, consider the following folders:
  129. ``./results/default_two_agents/two_agent_stocks/0``
  130. ``./results/default_two_agents/two_agent_stocks/1``
  131. ...
  132. ``./results/default_two_agents/two_agent_stocks/9``
  133. This folder holds the results for the ``two_agent_stocks`` task of the ``default_two_agents`` tasks file. The ``0`` folder contains the results of the first instance / run. The ``1`` folder contains the results of the second run, and so on. You can think of the _task_id_ as mapping to a prompt, or a unique set of parameters, while the _instance_id_ defines a specific attempt or run.
  134. Within each folder, you will find the following files:
  135. - *timestamp.txt*: records the date and time of the run, along with the version of the autogen-agentchat library installed
  136. - *console_log.txt*: all console output produced by Docker when running AutoGen. Read this like you would a regular console.
  137. - *[agent]_messages.json*: for each Agent, a log of their messages dictionaries
  138. - *./coding*: A directory containing all code written by AutoGen, and all artifacts produced by that code.
  139. ## Contributing or Defining New Tasks or Benchmarks
  140. If you would like to develop -- or even contribute -- your own tasks or benchmarks, please review the [contributor&#39;s guide](CONTRIBUTING.md) for complete technical details.