• Stars
    star
    237
  • Rank 169,885 (Top 4 %)
  • Language
    Jupyter Notebook
  • License
    Other
  • Created over 1 year ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Implementation of "Generative Agents: Interactive Simulacra of Human Behavior" paper with Guidance and Langchain. Full features and work with local LLMs.

Generative Agents with Guidance, Langchain, and local LLMs

This is the implementation of paper "Generative Agents: Interactive Simulacra of Human Behavior". This is based on the Langchain implementation. We improve and add more features to make it like the original paper as much as possible. For more explaination, please check my medium post.

Note that: I just fixed a conflict between current prompts and the guidance. I recommend using the guidance==0.063 because of the stability.

Supported Features:

  • Work with local LLM
  • Memory and Retrieval
  • Reflection
  • Planning (need to improve)
  • Reacting and re-planning
  • Dialogue generation (need to improve)
  • Agent summary
  • Interview
  • Web UI (Gradio)

How to use

Install

Python packages:

The GPTQ-for-LLaMa I used is the oobabooga's fork. You can install it with this command.

Run

Please check the notebook file. I use the wizard-mega-13B-GPTQ model. Feel free to try others.

Notebook

Define Generative Agent

description = "Sam is a Ph.D student, his major is CS;Sam likes computer;Sam lives with his friend, Bob;Sam's farther is a doctor;Sam has a dog, named Max"
sam = GenerativeAgent(guidance=guidance, 
                      name='Sam',
                      age=23, 
                      des=description, 
                      trails='funny, like football, play CSGO', 
                      embeddings_model=embeddings_model)

Add memories

sam_observations = [
    "Sam wake up in the morning",
    "Sam feels tired because of playing games",
    "Sam has a assignment of AI course",
    "Sam see Max is sick",
    "Bob say hello to Sam",
    "Bob leave the room",
    "Sam say goodbye to Bob",
]
sam.add_memories(sam_observations)

Summary

summary = sam.get_summary(force_refresh=True)
print(summary)
"""
Name: Sam (age: 23)
Summary: Sam can be described as a Ph.D student who is interested in computer science and has a dog named Max. He is also a student of AI course and has a father who is a doctor. Sam is also a gamer and lives with his friend Bob. Additionally, Sam is a caring person who feels tired due to playing games and says goodbye to his friend Bob.. Sam is a Ph.D student majoring in Computer Science. He wakes up in the morning and lives with his friend Bob. Sam has a dog named Max and he is currently feeling tired due to playing games. Sam also has an assignment for his AI course.. it is difficult to determine Sam's feeling about his recent progress in life. However, if we assume that Sam is satisfied with his progress, we can describe his feeling as content or fulfilled.
"""

Planning and update status

status = sam.update_status()

alt text

Reaction

bool_react, reaction, context = sam.react(observation='The dog bowl is empty', 
                                          observed_entity='Dog bowl', 
                                          entity_status='The dog bowl is empty')
print(f"{bool_react}\nReaction: {reaction}\nContext: {context}")
"""
Yes
Reaction: Sam could put food in the dog's bowl and then call Max over to eat.
Context: Sam has a dog named Max, and he is a Ph.D student majoring in CS. Sam's father is a doctor, and Sam lives with his friend Bob. Sam likes computers and is currently taking an AI course. Sam is tired because of playing games. Bob left the room and said hello to Sam. Sam woke up in the morning and saw that the dog bowl was empty.
"""    

alt text

Dialogue generation

bool_react, reaction, context = sam.react(observation='Bob come room with a new PC', 
                                          observed_entity=bob,
                                          entity_status='Bob is setting up his new PC')

print(sam.dialogue_list[0])
"""
Friday June 02, 2023, 18:15

Bob: Hey Sam, check this out! I got a new PC and it's amazing.
Sam: That's great, Bob. Do you need any help setting it up?
Bob: No, I got it all set up already. It's just for gaming, but I'm really excited.
Sam: That's awesome. I'm always interested in trying out new hardware. Maybe I'll stop by and check it out.
Bob: Yeah, of course. I was just thinking, maybe you could help me with a few settings. I'm not that great at this stuff.
Sam: Sure, I'd be happy to help. When do you want to get started?
Bob: How about later on tonight? I'll call you when I'm ready to get going.
Sam: No problem. Let me know when you're ready and I'll head over.
"""

Interview

response = sam.interview('Friend', 'Who do you live with?')
print(response)
"""
I live with a friend of mine, his name is Bob.
"""

License

Creative Commons Attribution-NonCommercial (CC BY-NC-4.0)