Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NewVersion: Fixes & Improvements (e.g. Cost Assessment&Tracking, Azure, +more) #152

Open
wants to merge 62 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
3da4834
fix(backend): replace deprecated models.
drudilorenzo Apr 26, 2024
c7d7968
feat: simplify execution w/ scripts.
drudilorenzo Apr 26, 2024
0de1b36
feat: add cost logging.
drudilorenzo Apr 27, 2024
09d7ae2
fix: fix scripts.
drudilorenzo May 3, 2024
bb269be
feat: cost logging improvement.
drudilorenzo May 3, 2024
c7932d9
feat: add cost logger singleton.
drudilorenzo May 3, 2024
afb52d8
feat: thread-safe singleton.
drudilorenzo May 3, 2024
ece4f11
fix: remove clustrmaps.
drudilorenzo May 6, 2024
11e4aaa
fix: create movement directory.
drudilorenzo May 6, 2024
67ff092
feat: improve project config.
drudilorenzo May 7, 2024
7a599b5
tbd: add current bug.
drudilorenzo May 7, 2024
735c15e
feat: untrack temp file.
drudilorenzo May 7, 2024
9c8d2f6
Add readme.
drudilorenzo May 7, 2024
3e93bde
Update README.md
drudilorenzo May 7, 2024
433fdd2
Update README.md
drudilorenzo May 7, 2024
11f385e
Update README.md
drudilorenzo May 7, 2024
4dda6d2
(docs): improve readme.
drudilorenzo May 13, 2024
4a36e0b
feat: log on file.
drudilorenzo May 14, 2024
b71edf6
feat: create directory.
drudilorenzo May 14, 2024
e017db1
(exec): add skip-morning simulation.
drudilorenzo May 15, 2024
b4f59aa
(scripts): improve backend scripts.
drudilorenzo May 15, 2024
e8a73ad
feat: restart execution in case of failure.
drudilorenzo May 15, 2024
b9f160f
(docs): improve readme.
drudilorenzo May 15, 2024
f1cec26
Update README.md
drudilorenzo May 15, 2024
5b61652
Update README.md
drudilorenzo May 15, 2024
012fe0e
add tracing func, add fake get for frontend refresh, add data files
Laz4rz May 16, 2024
69e5a6c
add setup info
Laz4rz May 16, 2024
39aa57b
feat: save checkpoints.
drudilorenzo May 17, 2024
8ae36ef
add test elections setup with 5 voters
Laz4rz May 18, 2024
fae94f0
fix base files in .gitignore
Laz4rz May 18, 2024
3441f2c
fix elections setup
Laz4rz May 18, 2024
91f7e06
feat: execution w/o ui.
drudilorenzo May 22, 2024
aedbea9
Update README.md
drudilorenzo May 22, 2024
46d5bcf
feat: track utils file.
drudilorenzo May 22, 2024
6845136
fix: fix requirements.
drudilorenzo May 22, 2024
b8ec715
fix: fix logger version.
drudilorenzo May 22, 2024
aec198e
add browser path support
Laz4rz May 22, 2024
2fa41d4
add survey ipynb, add direct access to agent analysis
Laz4rz May 22, 2024
510d586
add single and multisurveys, expand on direct interview access
Laz4rz May 22, 2024
708bbfa
update potential election setup problems
Laz4rz May 23, 2024
54b8b80
finish test 2 + 5 results
Laz4rz May 23, 2024
cbe62b1
fix steps diff count for filtered
Laz4rz May 23, 2024
905a6bd
fix: update curr time.
drudilorenzo May 24, 2024
bdd6714
feat: improve autorun script.
drudilorenzo May 24, 2024
723383f
fix steps diff count for filtered
Laz4rz May 24, 2024
1d59997
fix test setup
Laz4rz May 24, 2024
9f84da3
add ideas and todo
Laz4rz May 24, 2024
e49b730
add reversed setup
Laz4rz May 24, 2024
bbfef12
feat: Add port config.
drudilorenzo May 25, 2024
30f8fce
fix: issue 111.
drudilorenzo May 25, 2024
1ddd137
fix: fix log file name.
drudilorenzo May 25, 2024
c0c5e1f
add zoom on Z and X
ketsapiwiq May 20, 2024
c9fd23a
fix: close thread.
drudilorenzo May 25, 2024
2e14d27
feat: limit cpu usage.
drudilorenzo May 25, 2024
a94028b
Merge pull request #3 from ketsapiwiq/zoom
drudilorenzo May 27, 2024
e41d767
fix(ui): lower zoom speed.
drudilorenzo May 27, 2024
076a1b5
Update README.md
drudilorenzo May 27, 2024
4811e90
fix: no ui run.
drudilorenzo May 27, 2024
913f73f
Refactor.
drudilorenzo May 28, 2024
1cb6562
Update README.md
drudilorenzo May 28, 2024
2529d08
Update README.md
drudilorenzo May 28, 2024
0db6021
fix output parsing
drudilorenzo Jun 3, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
The diff you're trying to view is too large. We only load the first 3000 changed files.
22 changes: 19 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,15 +1,31 @@
reverie/backend_server/utils.py
# OpenAI API key
openai_config.json

environment/frontend_server/storage/*
environment/frontend_server/temp_storage*/*
reverie/backend_server/cost-logs/*

# Logs folder
logs/*

frontend_server/settings/local.py
storage/*
static_dirs/*

!storage/base_the_ville_isabella_maria_klaus/*
!storage/base_the_ville_n25/*
!environment/frontend_server/storage/base_the_ville_isabella_maria_klaus/*
!environment/frontend_server/storage/base_the_ville_n25/*
!environment/frontend_server/storage/base_the_ville_smol_elections_5_voters
!environment/frontend_server/storage/base_the_ville_smol_elections_5_voters_swapped_personalities

# Keep the skip-morning-s simulation
!environment/frontend_server/storage/skip-morning-s-14
!logs/skip-morning_2024-05-15_13-54-44.txt

bin/
include/
pip-selfcheck.json
.DS_Store
.vscode/

# Byte-compiled / optimized / DLL files
__pycache__/
Expand Down
246 changes: 138 additions & 108 deletions README.md

Large diffs are not rendered by default.

141 changes: 141 additions & 0 deletions README_origin.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@


# Generative Agents: Interactive Simulacra of Human Behavior

<p align="center" width="100%">
<img src="cover.png" alt="Smallville" style="width: 80%; min-width: 300px; display: block; margin: auto;">
</p>

This repository accompanies our research paper titled "[Generative Agents: Interactive Simulacra of Human Behavior](https://arxiv.org/abs/2304.03442)." It contains our core simulation module for generative agents—computational agents that simulate believable human behaviors—and their game environment. Below, we document the steps for setting up the simulation environment on your local machine and for replaying the simulation as a demo animation.

## <img src="https://joonsungpark.s3.amazonaws.com:443/static/assets/characters/profile/Isabella_Rodriguez.png" alt="Generative Isabella"> Setting Up the Environment
To set up your environment, you will need to generate a `utils.py` file that contains your OpenAI API key and download the necessary packages.

### Step 1. Generate Utils File
In the `reverie/backend_server` folder (where `reverie.py` is located), create a new file titled `utils.py` and copy and paste the content below into the file:
```
# Copy and paste your OpenAI API Key
openai_api_key = "<Your OpenAI API>"
# Put your name
key_owner = "<Name>"

maze_assets_loc = "../../environment/frontend_server/static_dirs/assets"
env_matrix = f"{maze_assets_loc}/the_ville/matrix"
env_visuals = f"{maze_assets_loc}/the_ville/visuals"

fs_storage = "../../environment/frontend_server/storage"
fs_temp_storage = "../../environment/frontend_server/temp_storage"

collision_block_id = "32125"

# Verbose
debug = True
```
Replace `<Your OpenAI API>` with your OpenAI API key, and `<name>` with your name.

### Step 2. Install requirements.txt
Install everything listed in the `requirements.txt` file (I strongly recommend first setting up a virtualenv as usual). A note on Python version: we tested our environment on Python 3.9.12.

## <img src="https://joonsungpark.s3.amazonaws.com:443/static/assets/characters/profile/Klaus_Mueller.png" alt="Generative Klaus"> Running a Simulation
To run a new simulation, you will need to concurrently start two servers: the environment server and the agent simulation server.

### Step 1. Starting the Environment Server
Again, the environment is implemented as a Django project, and as such, you will need to start the Django server. To do this, first navigate to `environment/frontend_server` (this is where `manage.py` is located) in your command line. Then run the following command:

python manage.py runserver

Then, on your favorite browser, go to [http://localhost:8000/](http://localhost:8000/). If you see a message that says, "Your environment server is up and running," your server is running properly. Ensure that the environment server continues to run while you are running the simulation, so keep this command-line tab open! (Note: I recommend using either Chrome or Safari. Firefox might produce some frontend glitches, although it should not interfere with the actual simulation.)

### Step 2. Starting the Simulation Server
Open up another command line (the one you used in Step 1 should still be running the environment server, so leave that as it is). Navigate to `reverie/backend_server` and run `reverie.py`.

python reverie.py
This will start the simulation server. A command-line prompt will appear, asking the following: "Enter the name of the forked simulation: ". To start a 3-agent simulation with Isabella Rodriguez, Maria Lopez, and Klaus Mueller, type the following:

base_the_ville_isabella_maria_klaus
The prompt will then ask, "Enter the name of the new simulation: ". Type any name to denote your current simulation (e.g., just "test-simulation" will do for now).

test-simulation
Keep the simulator server running. At this stage, it will display the following prompt: "Enter option: "

### Step 3. Running and Saving the Simulation
On your browser, navigate to [http://localhost:8000/simulator_home](http://localhost:8000/simulator_home). You should see the map of Smallville, along with a list of active agents on the map. You can move around the map using your keyboard arrows. Please keep this tab open. To run the simulation, type the following command in your simulation server in response to the prompt, "Enter option":

run <step-count>
Note that you will want to replace `<step-count>` above with an integer indicating the number of game steps you want to simulate. For instance, if you want to simulate 100 game steps, you should input `run 100`. One game step represents 10 seconds in the game.


Your simulation should be running, and you will see the agents moving on the map in your browser. Once the simulation finishes running, the "Enter option" prompt will re-appear. At this point, you can simulate more steps by re-entering the run command with your desired game steps, exit the simulation without saving by typing `exit`, or save and exit by typing `fin`.

The saved simulation can be accessed the next time you run the simulation server by providing the name of your simulation as the forked simulation. This will allow you to restart your simulation from the point where you left off.

### Step 4. Replaying a Simulation
You can replay a simulation that you have already run simply by having your environment server running and navigating to the following address in your browser: `http://localhost:8000/replay/<simulation-name>/<starting-time-step>`. Please make sure to replace `<simulation-name>` with the name of the simulation you want to replay, and `<starting-time-step>` with the integer time-step from which you wish to start the replay.

For instance, by visiting the following link, you will initiate a pre-simulated example, starting at time-step 1:
[http://localhost:8000/replay/July1_the_ville_isabella_maria_klaus-step-3-20/1/](http://localhost:8000/replay/July1_the_ville_isabella_maria_klaus-step-3-20/1/)

### Step 5. Demoing a Simulation
You may have noticed that all character sprites in the replay look identical. We would like to clarify that the replay function is primarily intended for debugging purposes and does not prioritize optimizing the size of the simulation folder or the visuals. To properly demonstrate a simulation with appropriate character sprites, you will need to compress the simulation first. To do this, open the `compress_sim_storage.py` file located in the `reverie` directory using a text editor. Then, execute the `compress` function with the name of the target simulation as its input. By doing so, the simulation file will be compressed, making it ready for demonstration.

To start the demo, go to the following address on your browser: `http://localhost:8000/demo/<simulation-name>/<starting-time-step>/<simulation-speed>`. Note that `<simulation-name>` and `<starting-time-step>` denote the same things as mentioned above. `<simulation-speed>` can be set to control the demo speed, where 1 is the slowest, and 5 is the fastest. For instance, visiting the following link will start a pre-simulated example, beginning at time-step 1, with a medium demo speed:
[http://localhost:8000/demo/July1_the_ville_isabella_maria_klaus-step-3-20/1/3/](http://localhost:8000/demo/July1_the_ville_isabella_maria_klaus-step-3-20/1/3/)

### Tips
We've noticed that OpenAI's API can hang when it reaches the hourly rate limit. When this happens, you may need to restart your simulation. For now, we recommend saving your simulation often as you progress to ensure that you lose as little of the simulation as possible when you do need to stop and rerun it. Running these simulations, at least as of early 2023, could be somewhat costly, especially when there are many agents in the environment.

## <img src="https://joonsungpark.s3.amazonaws.com:443/static/assets/characters/profile/Maria_Lopez.png" alt="Generative Maria"> Simulation Storage Location
All simulations that you save will be located in `environment/frontend_server/storage`, and all compressed demos will be located in `environment/frontend_server/compressed_storage`.

## <img src="https://joonsungpark.s3.amazonaws.com:443/static/assets/characters/profile/Sam_Moore.png" alt="Generative Sam"> Customization

There are two ways to optionally customize your simulations.

### Author and Load Agent History
First is to initialize agents with unique history at the start of the simulation. To do this, you would want to 1) start your simulation using one of the base simulations, and 2) author and load agent history. More specifically, here are the steps:

#### Step 1. Starting Up a Base Simulation
There are two base simulations included in the repository: `base_the_ville_n25` with 25 agents, and `base_the_ville_isabella_maria_klaus` with 3 agents. Load one of the base simulations by following the steps until step 2 above.

#### Step 2. Loading a History File
Then, when prompted with "Enter option: ", you should load the agent history by responding with the following command:

call -- load history the_ville/<history_file_name>.csv
Note that you will need to replace `<history_file_name>` with the name of an existing history file. There are two history files included in the repo as examples: `agent_history_init_n25.csv` for `base_the_ville_n25` and `agent_history_init_n3.csv` for `base_the_ville_isabella_maria_klaus`. These files include semicolon-separated lists of memory records for each of the agents—loading them will insert the memory records into the agents' memory stream.

#### Step 3. Further Customization
To customize the initialization by authoring your own history file, place your file in the following folder: `environment/frontend_server/static_dirs/assets/the_ville`. The column format for your custom history file will have to match the example history files included. Therefore, we recommend starting the process by copying and pasting the ones that are already in the repository.

### Create New Base Simulations
For a more involved customization, you will need to author your own base simulation files. The most straightforward approach would be to copy and paste an existing base simulation folder, renaming and editing it according to your requirements. This process will be simpler if you decide to keep the agent names unchanged. However, if you wish to change their names or increase the number of agents that the Smallville map can accommodate, you might need to directly edit the map using the [Tiled](https://www.mapeditor.org/) map editor.


## <img src="https://joonsungpark.s3.amazonaws.com:443/static/assets/characters/profile/Eddy_Lin.png" alt="Generative Eddy"> Authors and Citation

**Authors:** Joon Sung Park, Joseph C. O'Brien, Carrie J. Cai, Meredith Ringel Morris, Percy Liang, Michael S. Bernstein

Please cite our paper if you use the code or data in this repository.
```
@inproceedings{Park2023GenerativeAgents,
author = {Park, Joon Sung and O'Brien, Joseph C. and Cai, Carrie J. and Morris, Meredith Ringel and Liang, Percy and Bernstein, Michael S.},
title = {Generative Agents: Interactive Simulacra of Human Behavior},
year = {2023},
publisher = {Association for Computing Machinery},
address = {New York, NY, USA},
booktitle = {In the 36th Annual ACM Symposium on User Interface Software and Technology (UIST '23)},
keywords = {Human-AI interaction, agents, generative AI, large language models},
location = {San Francisco, CA, USA},
series = {UIST '23}
}
```

## <img src="https://joonsungpark.s3.amazonaws.com:443/static/assets/characters/profile/Wolfgang_Schulz.png" alt="Generative Wolfgang"> Acknowledgements

We encourage you to support the following three amazing artists who have designed the game assets for this project, especially if you are planning to use the assets included here for your own project:
* Background art: [PixyMoon (@_PixyMoon\_)](https://twitter.com/_PixyMoon_)
* Furniture/interior design: [LimeZu (@lime_px)](https://twitter.com/lime_px)
* Character design: [ぴぽ (@pipohi)](https://twitter.com/pipohi)

In addition, we thank Lindsay Popowski, Philip Guo, Michael Terry, and the Center for Advanced Study in the Behavioral Sciences (CASBS) community for their insights, discussions, and support. Lastly, all locations featured in Smallville are inspired by real-world locations that Joon has frequented as an undergraduate and graduate student---he thanks everyone there for feeding and supporting him all these years.


Loading