Giter Site home page Giter Site logo

scene-based-generative-agent's Introduction

Vland scene-based generative agent

This is a scene-based generative agent demo, based on the Vland platform and the paper Generative Agents: Interactive Simulacra of Human Behavior by Park, et. al.

Thanks to Harrison Chase for the agent_simulations demo based on his own Langchain. We then packaged and fine-tuned on this basis. Looking forward to more interested developers can develop more in-depth based on this demo. Such as simulated town, social science experimental research, etc.

You can watch Demo video.

demo.mp4

Welome to join our discord group.

Discord

Quick Start

First, you need to configure your own OPENAI_API_KEY. You can get it from OpenAI API Key. It is recommended that you use a paid account, otherwise you will receive frequency restrictions during use. For details, please refer to OpenAI rate limits

Set it in agent/config.py.

os.environ["OPENAI_API_KEY"] = "your own key"

Next, you need to configure your own Vland config in main.py.

You can get apiId, apiKey, eventId, spaceId in Vland platform.

  • The apiId is your user id. It is displayed in the account in the upper right corner of the page.

Vland config

  • The apiKey is for each different vland events. You can create and copy it in Manage events

Vland config

  • The eventId and spaceId is for each different space in the event. You can find them in the link after entering the space.

Vland config

wsconfig = {
    "apiId": "your vland id",
    "apiKey": "event api key",
    "eventId": "event id",
    "spaceId": "space id",
    "listener": get_server_response
}

We preset the data of 4 agents for you. You can modify the data in vland/data.py according to your needs.

The avatar in the data represents the number of the Vland avatar. You can fill in according to your preferences.

Vland avatars

agentData = {
    "vlandagent1": {
        "name": "Tommie",
        "personality": "anxious, likes design, talkative",
        "age": 25,
        "memories": [
            "Tommie remembers his dog, Bruno, from when he was a kid",
            "Tommie feels tired from driving so far",
            "Tommie sees the new home",
            "The new neighbors have a cat",
            "The road is noisy at night",
            "Tommie is hungry",
            "Tommie tries to get some rest."
        ],
        "current_status": "looking for a job",
        "avatar": 1
    },
    ...
}

Then you need enter the Vland space, so that you can observe later.

Finally, run your main.py

python main.py
# maybe your command to run python is different

Screenshots

If you see the following in the console, it means that you have connected to the server and successfully generated the agent.

Console Screenshot

And these agents will appear in your vland space.

Space Screenshot

You need to check the network and your Vland config, if it doesn't happen according to plan.

Then these agents will run according to your logic and ChatGPT

Space Screenshot

Create your own space in Vland

The destination of the agent's movement is selected from the marked area in the space.

You can follow the steps below to create a space and edit the area.

  1. Sign up and log in to Vland.

  2. Create a space in the upper right corner of the page. Step

  3. Enter your event name. Step

  4. Add a new space under your event. Step

  5. We provide many exquisite templates for you to quickly create your space. You can also create an empty map and use the materials we provide to decorate your space Step

  6. Select the space you want to edit Step

  7. Select the Special interaction in the Effect. Frame the area you want to mark on the map and enter a unique name. Step

  8. Finally, remember to save the map, then you can enter your own space. Step

DIY your script

Use the interface provided by vland and the method of generating agents.

You can define the logic that your agent runs in main.py like

'''
Call the interface provided by vland to get all the agents in the current area.
Record the acquired data into agent's observations.
And respond to the observation.
Then tell other agents about this action.
'''        
async def _observe_an_area(self):
    # call vland.get_all_in_area(area="living room") to get agents info in the current area
    self.currentArea = await self.vland.get_all_in_area(area="living room")

    # create an observation
    observation = "In the " + self.currentArea["name"] +  ", you met "
    hasOthers = False
    for pid in self.currentArea["data"]:
        if pid != self.playerInfo["pid"] and pid in agentData:
            observation += agentData[pid]["name"] + ", "
            hasOthers = True
    if hasOthers:
        # save this observation to memory
        self.memory.add_memory(observation)
        # generate reaction by observation
        _, reaction, area = self.player.generate_reaction(observation, self.areaList["names"])
        print(colored(observation, "green"), colored(area, "blue"), reaction)
        # call vland.operate_robot to command the agent to act
        self.vland.operate_robot(self.playerInfo["pid"], area=area, message=reaction)
            
        notice = {}
        notice["pid"] = self.playerInfo["pid"]
        notice["action"] = reaction
        # push to other agents
        self.eventbus.publish("action", notice)

The Vland interface related to generating agents is written in vland/vlandapi

We will continue to add more interfaces.

And the functions that can be realized can also refer to Vland websocket sdk (node.js)

Support

For support, you can join our discord group Discord. Or email [email protected]

References

  1. https://arxiv.org/abs/2304.03442
  2. https://python.langchain.com/en/latest/use_cases/agent_simulations/characters.html#create-a-generative-character

scene-based-generative-agent's People

Contributors

celineycn avatar jasoncaocjx avatar vlandlive avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

scene-based-generative-agent's Issues

IndexError: list index out of range

I have run the code and get the error below.

ーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーー
connect success
handshakeack success
Tommie generated successfully!
Traceback (most recent call last):
File "/content/drive/MyDrive/scene-based-generative-agent-main/main.py", line 163, in
generate_agents_by_data()
File "/content/drive/MyDrive/scene-based-generative-agent-main/main.py", line 157, in generate_agents_by_data
agent = VlandAgent(player, vland, eventbus)
File "/content/drive/MyDrive/scene-based-generative-agent-main/main.py", line 58, in init
self.vland.born_in_space(self.playerInfo, area="living room")
File "/content/drive/MyDrive/scene-based-generative-agent-main/vland/vlandapi.py", line 179, in born_in_space
area = random.choice(self.areaList["names"])
File "/usr/lib/python3.10/random.py", line 378, in choice
return seq[self._randbelow(len(seq))]
IndexError: list index out of range
ーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーー

Can anyone help me figure out what is causing this?

Agents do not work autonomously.

Please excuse my question.
I generated an agent by running this code, but no matter how much I run it, the agent only speaks the same lines.
Maybe the code below is not executed and hasOthers is not set to True.

if pid != self.playerInfo["pid"] and pid in agentData: observation += agentData[pid]["name"] + ", " hasOthers = True

Sorry for the newbie question, but how do I set up the agent to run autonomously?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.