joonspk-research / generative_agents

Generative Agents: Interactive Simulacra of Human Behavior
Apache License 2.0
17.73k stars 2.31k forks source link

Unable to rerun simulations after initial few steps #5

Open tripathiarpan20 opened 1 year ago

tripathiarpan20 commented 1 year ago

Thanks again for open-sourcing the implementation.

I tried running the base base_the_ville_isabella_maria_klaus scenario, however, after a few steps, the simulation stops and unable to proceed after adding subsequent run commands.

image

lncohn commented 1 year ago

I have the same problem

lncohn commented 1 year ago

ction description: being used Emoji: """ Output the response to the prompt above in json. The value for the output must ONLY contain the emojis. Example output json: {"output": "πŸ›πŸ§–β€β™€οΈ"} Klaus Mueller persona.scratch.importance_trigger_curr:: 145 150 aldhfoaf/???? the Ville:Dorm for Oak Hill College:Klaus Mueller's room:bed Error.

wolfgangjblack commented 1 year ago
Klaus Mueller persona.scratch.importance_trigger_curr:: 145
150
aldhfoaf/????
the Ville:Dorm for Oak Hill College:Klaus Mueller's room:bed
Error.

Same, I get an error every time with Klaus Mueller

Problem occurs during run command on any number of steps. I do have the option to continue the sim - that is

Enter option: 

pops back up and I'm able to enter

run 1

but again, once Kaus Meuller appears I get

"""
Here is a brief description of Klaus Mueller. 
Name: Klaus Mueller
Age: 20
Innate traits: kind, inquisitive, passionate
Learned traits: Klaus Mueller is a student at Oak Hill College studying sociology. He is passionate about social justice and loves to explore different perspectives.
Currently: Klaus Mueller is writing a research paper on the effects of gentrification in low-income communities.
Lifestyle: Klaus Mueller goes to bed around 11pm, awakes up around 7am, eats dinner around 5pm.
Daily plan requirement: Klaus Mueller goes to the library at Oak Hill College early in the morning, spends his days writing, and eats at Hobbs Cafe.
Current Date: Monday February 13

On the scale of 1 to 10, where 1 is purely mundane (e.g., brushing teeth, making bed) and 10 is extremely poignant (e.g., a break up, college acceptance), rate the likely poignancy of the following event for Klaus Mueller.

Event: Klaus Mueller is sleeping
Rate (return a number between 1 to 10):
"""
Output the response to the prompt above in json. The output should ONLY contain ONE integer value on the scale of 1 to 10.
Example output json:
{"output": "5"}
Klaus Mueller persona.scratch.importance_trigger_curr:: 141
150
Error.

After the second attempt at a run command, I can't get it to run again. This time this is the output:

Enter option: run 100
Isabella Rodriguez persona.scratch.importance_trigger_curr:: 140
150
Maria Lopez persona.scratch.importance_trigger_curr:: 142
150
Klaus Mueller persona.scratch.importance_trigger_curr:: 141
150
Error.
Enter option: run 100 
Isabella Rodriguez persona.scratch.importance_trigger_curr:: 140
150
Maria Lopez persona.scratch.importance_trigger_curr:: 142
150
Klaus Mueller persona.scratch.importance_trigger_curr:: 141
150
Error.
Enter option: run 1
Isabella Rodriguez persona.scratch.importance_trigger_curr:: 140
150
Maria Lopez persona.scratch.importance_trigger_curr:: 142
150
Klaus Mueller persona.scratch.importance_trigger_curr:: 141
150
Error.
wolfgangjblack commented 1 year ago

update: I ran the simulation with all the villagers and was able to successfully pass Klaus. The simulation has been running for a few minutes (only tried to run 10 steps) so if it fails I'll update this comment. But the error appears to only be in the isabella_maria_klaus simulation

UPDATE Got the error again: This time triggered on Adam Smith. I believe adam now thinks he's a bed...

Input: Adam Smith is sleeping. 
Output: (Adam Smith, 

~~~ output    ----------------------------------------------------
('Adam Smith', 'is', 'sleep') 

=== END ==========================================================

GNS FUNCTION: <generate_act_obj_desc>
asdhfapsh8p9hfaiafdsi;ldfj as DEBUG 6
CHAT GPT PROMPT
"""
Task: We want to understand the state of an object that is being used by someone. 

Let's think step by step. 
We want to know about bed's state. 
Step 1. Adam Smith is at/using the sleeping.
Step 2. Describe the bed's state: bed is
"""
Output the response to the prompt above in json. The output should ONLY contain the phrase that should go in <fill in>.
Example output json:
{"output": "being fixed"}
GNS FUNCTION: <generate_action_pronunciatio>
asdhfapsh8p9hfaiafdsi;ldfj as DEBUG 4
CHAT GPT PROMPT
"""
Convert an action description to an emoji (important: use two or less emojis).

Action description: being slept in
Emoji:
"""
Output the response to the prompt above in json. The value for the output must ONLY contain the emojis.
Example output json:
{"output": "πŸ›πŸ§–β€β™€οΈ"}
GNS FUNCTION: <generate_act_obj_event_triple>
=== persona/prompt_template/v2/generate_event_triple_v1.txt
~~~ persona    ---------------------------------------------------
Adam Smith 

~~~ gpt_param ----------------------------------------------------
{'engine': 'text-davinci-003', 'max_tokens': 30, 'temperature': 0, 'top_p': 1, 'stream': False, 'frequency_penalty': 0, 'presence_penalty': 0, 'stop': ['\n']} 

~~~ prompt_input    ----------------------------------------------
['bed', 'being slept in', 'bed'] 

~~~ prompt    ----------------------------------------------------
Task: Turn the input into (subject, predicate, object). 

Input: Sam Johnson is eating breakfast. 
Output: (Dolores Murphy, eat, breakfast) 
--- 
Input: Joon Park is brewing coffee.
Output: (Joon Park, brew, coffee)
---
Input: Jane Cook is sleeping. 
Output: (Jane Cook, is, sleep)
---
Input: Michael Bernstein is writing email on a computer. 
Output: (Michael Bernstein, write, email)
---
Input: Percy Liang is teaching students in a classroom. 
Output: (Percy Liang, teach, students)
---
Input: Merrie Morris is running on a treadmill. 
Output: (Merrie Morris, run, treadmill)
---
Input: bed is being slept in. 
Output: (bed, 

~~~ output    ----------------------------------------------------
('bed', 'be', 'slept') 

=== END ==========================================================

Adam Smith persona.scratch.importance_trigger_curr:: 243
250
aldhfoaf/????
the Ville:Adam Smith's house:main room:bed
Error.

After the error I tried

run 1

And got (after a bunch of other people)


On the scale of 1 to 10, where 1 is purely mundane (e.g., brushing teeth, making bed) and 10 is extremely poignant (e.g., a break up, college acceptance), rate the likely poignancy of the following event for Adam Smith.

Event: Adam Smith is sleeping
Rate (return a number between 1 to 10):
"""
Output the response to the prompt above in json. The output should ONLY contain ONE integer value on the scale of 1 to 10.
Example output json:
{"output": "5"}
asdhfapsh8p9hfaiafdsi;ldfj as DEBUG 7
CHAT GPT PROMPT
"""
Here is a brief description of Adam Smith. 
Name: Adam Smith
Age: 36
Innate traits: thoughtful, reflective, intellectual
Learned traits: Adam Smith is a philosopher who loves to explore different ideas. He is always looking for ways to challenge people’s preconceptions.
Currently: Adam Smith is writing a book about the importance of creativity and how it can shape the world. Adam is also curious about who will be running for the local mayor election next month.
Lifestyle: Adam Smith goes to bed around 8pm, awakes up around 4am, eats dinner around 5pm.
Daily plan requirement: 
Current Date: Monday February 13

On the scale of 1 to 10, where 1 is purely mundane (e.g., brushing teeth, making bed) and 10 is extremely poignant (e.g., a break up, college acceptance), rate the likely poignancy of the following event for Adam Smith.

Event: bed is being slept in
Rate (return a number between 1 to 10):
"""
Output the response to the prompt above in json. The output should ONLY contain ONE integer value on the scale of 1 to 10.
Example output json:
{"output": "5"}
Adam Smith persona.scratch.importance_trigger_curr:: 241
250
Error.

Again, I had the option to run, so i did

run 1

which finally gave me

Enter option: run 1   
Latoya Williams persona.scratch.importance_trigger_curr:: 243
250
Rajiv Patel persona.scratch.importance_trigger_curr:: 241
250
Abigail Chen persona.scratch.importance_trigger_curr:: 244
250
Francisco Lopez persona.scratch.importance_trigger_curr:: 243
250
Hailey Johnson persona.scratch.importance_trigger_curr:: 243
250
Arthur Burton persona.scratch.importance_trigger_curr:: 238
250
Ryan Park persona.scratch.importance_trigger_curr:: 241
250
Isabella Rodriguez persona.scratch.importance_trigger_curr:: 242
250
Giorgio Rossi persona.scratch.importance_trigger_curr:: 234
250
Carlos Gomez persona.scratch.importance_trigger_curr:: 241
250
Klaus Mueller persona.scratch.importance_trigger_curr:: 241
250
Maria Lopez persona.scratch.importance_trigger_curr:: 242
250
Ayesha Khan persona.scratch.importance_trigger_curr:: 243
250
Wolfgang Schulz persona.scratch.importance_trigger_curr:: 242
250
Mei Lin persona.scratch.importance_trigger_curr:: 239
250
John Lin persona.scratch.importance_trigger_curr:: 241
250
Eddy Lin persona.scratch.importance_trigger_curr:: 244
250
Tom Moreno persona.scratch.importance_trigger_curr:: 240
250
Jane Moreno persona.scratch.importance_trigger_curr:: 242
250
Tamara Taylor persona.scratch.importance_trigger_curr:: 243
250
Carmen Ortiz persona.scratch.importance_trigger_curr:: 244
250
Sam Moore persona.scratch.importance_trigger_curr:: 239
250
Jennifer Moore persona.scratch.importance_trigger_curr:: 235
250
Yuriko Yamamoto persona.scratch.importance_trigger_curr:: 234
250
Adam Smith persona.scratch.importance_trigger_curr:: 241
250
Error.

if I continue to run, I get the above again

Note: running this cost $9

liaopeiyuan commented 1 year ago

It appears that the movement folder needs to be created before the persona's current movement can be written to the file (and subsequently sent to the frontend):

https://github.com/joonspk-research/generative_agents/blob/c7e0c16d88cba8f3611378bea57dbcac08b9d235/reverie/backend_server/reverie.py#L399

# We then write the personas' movements to a file that will be sent 
# to the frontend server. 
# Example json output: 
# {"persona": {"Maria Lopez": {"movement": [58, 9]}},
#  "persona": {"Klaus Mueller": {"movement": [38, 12]}}, 
#  "meta": {curr_time: <datetime>}}
curr_move_file = f"{sim_folder}/movement/{self.step}.json"
with open(curr_move_file, "w") as outfile: 
  outfile.write(json.dumps(movements, indent=2))

(among a few other places)

We are currently running into issues where the simulation hangs (>1min) after the movement is written. Will report back with more findings. (we have ample rate limit quota & budget so it shouldn't be a problem)

wolfgangjblack commented 1 year ago

I have a modest rate limit quota and will have some time tomorrow, lmk if there is a particular route I can help investigate. I'll also try to create a new sim following the instructions and will report back with any issues

liaopeiyuan commented 1 year ago

After creating the folder before attempting to write it, I was able to run it for 4000 ticks with no interruptions.

btcioner commented 1 year ago

          sim_folder_path = sim_folder
          if not os.path.exists(sim_folder_path):
              os.makedirs(sim_folder_path)

          movement_folder_path = os.path.join(sim_folder_path, 'movement')
          if not os.path.exists(movement_folder_path):
              os.makedirs(movement_folder_path)

          curr_move_file = f"{movement_folder_path}/{self.step}.json"
          with open(curr_move_file, "w") as outfile:
              outfile.write(json.dumps(movements, indent=2))
lncohn commented 1 year ago

It works! Thanks!

wolfgangjblack commented 1 year ago

interesting - I'm unable to run still.

Just to verify - are you creating the file movement in ./environment/frontend_server/storage/base_the_ville_isabella_maria_klaus

before running python reverie.py?

Also, I inserted


          sim_folder_path = sim_folder
          if not os.path.exists(sim_folder_path):
              os.makedirs(sim_folder_path)

          movement_folder_path = os.path.join(sim_folder_path, 'movement')
          if not os.path.exists(movement_folder_path):
              os.makedirs(movement_folder_path)

          curr_move_file = f"{movement_folder_path}/{self.step}.json"
          with open(curr_move_file, "w") as outfile:
              outfile.write(json.dumps(movements, indent=2))

in reverie.py at line 399 but still am failing to run anything for Klaus...

Neither method worked for me - did ya'll do something differently to get it to work?

Skiddoh commented 1 year ago

i created the folder and added the code at the position, but i also cant get the characters to move - frontend seems fine, backend shows the output of each character, but there is no json-file that has been written to the movement folder.

zackzhuang1996 commented 1 year ago

same here. I added the create folder code but still it shows

Enter option: run 10 Isabella Rodriguez persona.scratch.importance_trigger_curr:: 142 150 Maria Lopez persona.scratch.importance_trigger_curr:: 141 150 Klaus Mueller persona.scratch.importance_trigger_curr:: 143 150

zoan37 commented 1 year ago

+1 I'm getting same issue after inserting the create folder code, the simulation hangs here:

Klaus Mueller persona.scratch.importance_trigger_curr:: 145
150
aldhfoaf/????
the Ville:Dorm for Oak Hill College:Klaus Mueller's room:bed
www-Ye commented 1 year ago

image same issue, how to solve it

leachy14 commented 1 year ago

interesting - I'm unable to run still.

Just to verify - are you creating the file movement in ./environment/frontend_server/storage/base_the_ville_isabella_maria_klaus

before running python reverie.py?

Also, I inserted


          sim_folder_path = sim_folder
          if not os.path.exists(sim_folder_path):
              os.makedirs(sim_folder_path)

          movement_folder_path = os.path.join(sim_folder_path, 'movement')
          if not os.path.exists(movement_folder_path):
              os.makedirs(movement_folder_path)

          curr_move_file = f"{movement_folder_path}/{self.step}.json"
          with open(curr_move_file, "w") as outfile:
              outfile.write(json.dumps(movements, indent=2))

in reverie.py at line 399 but still am failing to run anything for Klaus...

Neither method worked for me - did ya'll do something differently to get it to work?

I was having issues with the movement folder, I created it after the initial forking of base_the_ville_isabella_maria_klaus. So after it creates my new sim I add the movement folder. I had a sim going for around 2 in game days before I either hit rate limits or it hung.

image same issue, how to solve it

If my sim seems to hang, I'll press cntrl-c once and it seems to interrupt GPT and continue. I did have a sim hang after two days of in game time that I couldn't get to continue working. Not sure if it was rate limits or something else.

leachy14 commented 1 year ago

I did some more digging, it appears that is has trouble finding the curr_env_file. After it fails to find it, it continues and gets stuck in the starting server loop. I'm getting sleepy but I can probably look more into this tomorrow night I'll attach the output of my console: Screen Shot 2023-08-13 at 12 23 21 AM

www-Ye commented 1 year ago

I have reviewed the code and noticed that this issue may be due to the agent not having any new actions after a period of time, persistently performing the current action and therefore no new idea output will appear. After a longer period, the agent will resume normal operations when it starts to act again.

liaopeiyuan commented 1 year ago

While a better structure of relaying information between the game engine (frontend) and the simulation engine (LLM-powered backend) is preferred, a temporary solution is to create the folder on-demand:

https://github.com/liaopeiyuan/generative_agents/commit/7852068e350eae4f5086bd7e3386761d567ad08f

Potential reasons for "getting stuck" is due to the pattern of how simulation proceeds: you need to keep the frontend tab open (I think this is a browser- and setting-specific behavior, see https://stackoverflow.com/questions/56787440/keep-my-code-running-in-the-background-on-one-browsertab) so that it constantly pulls potential updates from the backend using the update_environment method, again, as a byproduct of the file-system-based design:

https://github.com/joonspk-research/generative_agents/blob/fe05a71d3e4ed7d10bf68aa4eda6dd995ec070f4/environment/frontend_server/templates/home/main_script.html#L411

wolfgangjblack commented 1 year ago

I'm seeing this behavior regardless of frontend tab being open. I can't run a single step without the errors

things I've tried that have not fixed the issue -

  1. adding the following code snippet into reverie.py at line 399

         sim_folder_path = sim_folder
          if not os.path.exists(sim_folder_path):
              os.makedirs(sim_folder_path)
    
          movement_folder_path = os.path.join(sim_folder_path, 'movement')
          if not os.path.exists(movement_folder_path):
              os.makedirs(movement_folder_path)
    
          curr_move_file = f"{movement_folder_path}/{self.step}.json"
          with open(curr_move_file, "w") as outfile:
              outfile.write(json.dumps(movements, indent=2))
  2. creating an empty movement folder in my forked simulation (after its named and BEFORE i type in run step)
  3. copying the movement folder from July1_....3-1 into base_the_ville_isabella_maria_klaus
  4. running a forked simulation off of base_the_ville_isabella_maria_klaus one step, it fails but writes the movement folder AND 0.json. After it fails, I save it, and then try to rerun - it seems to look for 1.json.
Gimel12 commented 1 year ago

Hi, I hope I can fix this issue for you guys, the main problem is that people solve the problem for themselves but do not explain properly, something so simple prevent the software to run. I hope this help:

Go to the file reverie.py file, use an editor like vscode so you can see the line count. go to line 401, it will look something like this:

      curr_move_file = f"{sim_folder}/movement/{self.step}.json"
      with open(curr_move_file, "w") as outfile: 
        outfile.write(json.dumps(movements, indent=2))

on top of that line 400 add this lines of code:

curr_move_path = f"{sim_folder}/movement"

If the folder doesn't exist, we create it.

      if not os.path.exists(curr_move_path):
        os.makedirs(curr_move_path)

The code should look like this: from line 394 to 406

      # We then write the personas' movements to a file that will be sent 
      # to the frontend server. 
      # Example json output: 
      # {"persona": {"Maria Lopez": {"movement": [58, 9]}},
      #  "persona": {"Klaus Mueller": {"movement": [38, 12]}}, 
      #  "meta": {curr_time: <datetime>}}
      curr_move_path = f"{sim_folder}/movement"
      # If the folder doesn't exist, we create it.
      if not os.path.exists(curr_move_path):
        os.makedirs(curr_move_path)
      curr_move_file = f"{sim_folder}/movement/{self.step}.json"
      with open(curr_move_file, "w") as outfile: 
        outfile.write(json.dumps(movements, indent=2))

After that the problem will go away, I hope this help.

mikeyang01 commented 1 year ago

Potential reasons for "getting stuck" is due to the pattern of how simulation proceeds: you need to keep the frontend tab open (I think this is a browser- and setting-specific behavior, see https://stackoverflow.com/questions/56787440/keep-my-code-running-in-the-background-on-one-browsertab) so that it constantly pulls potential updates from the backend using the update_environment method, again, as a byproduct of the file-system-based design:

Thanks a lot! To solve chrome issue, add "--disable-background-timer-throttling" to chrome