With the rapid advancement of large language models (LLMs), recent years have witnessed many promising studies on leveraging LLM-based agents to simulate human social behavior. While prior work has demonstrated significant potential across various domains, much of it has focused on specific scenarios involving a limited number of agents and has lacked the ability to adapt when errors occur during simulation. To overcome these limitations, we propose a novel LLM-agent-based simulation platform called GenSim, which: (1) Abstracts a set of general functions to simplify the simulation of customized social scenarios; (2) Supports one hundred thousand agents to better simulate large-scale populations in real-world contexts; (3) Incorporates error-correction mechanisms to ensure more reliable and long-term simulations. To evaluate our platform, we assess both the efficiency of large-scale agent simulations and the effectiveness of the error-correction mechanisms. To our knowledge, GenSim represents an initial step toward a general, large-scale, and correctable social simulation platform based on LLM agents, promising to further advance the field of social science.
π‘ GenSim provides a general programming framework for customized social simulations
π‘ GenSim supports large-scale social simulations (up to 10w agents)
π‘ GenSim has error-correction mechanisms for more reliable social simulations
Figure 2: The platform interface
Install from source code (https://github.com/pan-x-c/AgentScope/tree/feature/pxc/async_create_agent).
-
Add two lines of code in the
__init__
function ofOpenAIWrapperBase
in the filesrc/agentscope/models/openai_model.py
:self.api_key = api_key self.client_args = client_args or {}
git clone https://github.com/TangJiakai/GenSim.git
pip install -r requirements.txt
bash embedding_service/launch_multi_emb_models.sh
to launch the embedding model services.
p.s. You can use embedding models like m3e.
Get the embedding_api
(for example, http://localhost:8001/), and fill that URL into simulation/examples/<scenario>/configs/simulation_config.yml
.
p.s.
- You can set multiply embedding models.
bash llm_service/launch_all_llm.sh
to launch the LLM model server.
p.s.
- You can set multiply LLM models.
- You can also use other LLM APIs based on vllm inference framework.
Get the llm_api
(for example, http://localhost:8083/v1), and fill that URL into simulation/examples/<scenario>/configs/model_configs.json
. You can set multiply LLM models.
Configure the following files in the configs directory of the specific scenario (e.g., simulation/examples/<scenario>/configs
):
- simulation_config.yml
- memory_config.json
- model_configs.json
- xAgent_configs.json
- yAgent_configs.json
- ...
p.s.
- The
x
andy
in the file names are placeholders for the specific agent class.
Run the following command to launch the distributed server:
bash simulation/launch_server.sh <server_num_per_host> <base_port> <scenario>
p.s.
<server_num_per_host>
is the number of servers per host (Typically less than or equal to the number of CPU cores on your computer);<base_port>
is the starting port number (GenSim will allocate agent servers on ports ranging frombase_port
tobase_port + server_num_per_host - 1
);<scenario>
is the name of the scenario you want to simulate.
Run the following command to launch the simulator:
python simulation/examples/<scenario>/simulator.py
After the simulation is completed, you can kill the distributed server.
Run the following command to kill the distributed server:
bash simulation/kill_all_server.sh
Figure 3: The time costs of different numbers of agents
Figure 4: The time costs of different numbers of LLM
Figure 5: The effects of our error-correction mechanism in single (a) and multi (b) rounds, respectively
We explore the evolution and enhancement of the model using two methods: SFT and PPO.
-
Figure 5(a) shows the impact of the number of training samples on the performance of the LLM-based agent. It is evident that the model demonstrates effective performance improvements across various sizes of training data.
-
Figure 5(b) illustrates the performance of continuous evolution enhancement in a multi-round setting, and it can be observed that our method has a good self-correction effect.
πΉ Gratitude is extended to the developers of AgentScope, whose outstanding work has made this project possible. Their contributions have provided a solid foundation and essential tools that greatly enhanced the development process.
π Special thanks also go to @GaoHeYang, @WangLei, @PanXuChen, @TanHaoRan and @ChenYuShuo for their valuable contributions, feedback, and support throughout the course of this project. Their collaboration and insights have been instrumental in refining and improving the project.
β€οΈ Sincere appreciation is expressed to everyone who has contributed to the success of this project.
GenSim uses MIT License. All data and code in this project can only be used for academic purposes.
If you find our work helpful for your research or application, please cite our papers.
GenSim: A General Social Simulation Platform with Large Language Model based Agents
@misc{tang2024gensimgeneralsocialsimulation,
title={GenSim: A General Social Simulation Platform with Large Language Model based Agents},
author={Jiakai Tang and Heyang Gao and Xuchen Pan and Lei Wang and Haoran Tan and Dawei Gao and Yushuo Chen and Xu Chen and Yankai Lin and Yaliang Li and Bolin Ding and Jingren Zhou and Ji-Rong Wen},
year={2024},
eprint={2410.04360},
archivePrefix={arXiv},
primaryClass={cs.MA},
url={https://arxiv.org/abs/2410.04360},
}