1.
Introduction
Traditional NPCs often feel like robots, stuck repeating the same lines and offering scripted responses, no matter how the player interacts with them. This can lead to boring gameplay experiences where players keep mashing "skip" to get through the dialogue as quickly as possible.
Generative NPC harnesses the power of Large Language Models (LLMs) to create truly dynamic and interactive NPCs that feel like real characters.
Imagine this:
- Each NPC in your game is powered by its own LLM agent, capable of dynamically generating unique dialogue, behaviors, and even personality traits based on player actions. They can also communicate to each other to make a lively world
- No more scripted responses! NPCs will react to player choices in surprising and engaging ways, forging relationships with players and each other that evolve over time.
Generative NPC is a project that investigates the potential of interactive storytelling in video games. By developing intelligent agents that learn and adapt, the project aims to create a more dynamic and engaging experience.
2.
A quick look
NPCs in the game right now can do the following tasks for themself:
- Create a dynamic daily schedule based on there own traits
- Have conversations with others based on their memories and actions.
- Have their own thought and review about the world
3.
How to run
The quick way:
docker compose up -d
Development environment
Create an virtual environment of your choice, Here I'm using Conda for its convenient:
conda create -n free_guy python=3.10
conda activate free_guy
pip install -r requirements.txt
Start the Ollama server with ROCm:
docker run -d --device /dev/kfd --device /dev/dri -v ollama:/root/.ollama -p 11434:11434 --name ollama_server ollama/ollama:rocm
Start the frontend:
cd frontend_server
python manage.py runserver
Start the backend:
cd backend_server
python reverie.py
Now you will need to enter the checkpoint from the last run to continue or choose one of the base town setup to start
Enter the name of the forked simulation: <your_last_checkpoint_or_base>
Enter the name of the new simulation: <the_name_for_this_checkpoint_of_your_choice>
Enter option: run <number_of_step>
each step is equivalent to 10 seconds in game
4.
An overview
About the agent
An NPC will start their day with a set of summary activities that they usually do in the day. Asking the LLM, they will get detail stuffs for the whole day, this will then be the requirements to decide the next actions in the future
Each agent will have a summary of themself including their traits, hobbies, jobs, daily schedule. These information is the requirements for a more detail schedule:
An example of Abigail Chen
"first_name": "Abigail",
"last_name": "Chen",
"age": 25,
"innate": "open-minded, curious, determined",
"learned": "Abigail Chen is a digital artist and animator who loves to explore how technology can be used to express ideas. She is always looking for new ways to combine art and technology.",
"currently": "Abigail Chen is working on an animation project for a client. She is also experimenting with different tools and techniques to create interactive art.",
"lifestyle": "Abigail Chen goes to bed around midnight, awakes up around 8am, eats dinner around 6pm.",
"living_area": "the Ville:artist's co-living space:Abigail Chen's room",
They also have their own memory, reflection, observation and plan mechanism. The concept and explanation of these concepts are included in this paper
5.
How it works
For the backend, Ollama is the heart of the project, every decision, behavior or dialogue of NPCs comes from this place. It's provides a ChatGPT compatibility, so it's actually quite easy to adopt the implementations.
- Creating a client:
client = OpenAI(
base_url = 'http://localhost:11434/v1',
api_key='ollama', # required, but unused)
ollama_client = Client(host='http://localhost:11434/')
- Get a completion:
completion = client.chat.completions.create(
model="gemma2",
messages=[{"role": "user", "content": prompt}])
response = completion["choices"][0]["message"]["content"]
All prompt templates are stored at backend_server/persona/prompt_template. Let's take a look at some of the tasks:
- To generate a morning schedule:
Name: Isabella Rodriguez
Age: 34
Innate traits: friendly, outgoing, hospitable
Learned traits: Isabella Rodriguez is a cafe owner of Hobbs Cafe who loves to make people feel welcome. She is always looking for ways to make the cafe a place where people can come to relax and enjoy themselves.
Currently: Isabella Rodriguez is planning on having a Valentine's Day party at Hobbs Cafe with her customers on February 14th, 2023 at 5pm. She is gathering party material, and is telling everyone to join the party at Hobbs Cafe on February 14th, 2023, from 5pm to 7pm.
Lifestyle: Isabella Rodriguez goes to bed around 11pm, awakes up around 6am.
Daily plan requirement: Isabella Rodriguez opens Hobbs Cafe at 8am everyday, and works at the counter until 8pm, at which point she closes the cafe.
Current Date: Monday February 13
Today is February 13, 2023. From 00:00AM ~ 06:00AM, Isabella Rodriguez is planning on sleeping, 06:00AM ~ 07:00AM, Isabella Rodriguez is planning on waking up and completing the morning routine, 07:00AM ~ 08:00AM, Isabella Rodriguez is planning on preparing for the Valentine's Day party at Hobbs Cafe.
In 5 min increments, list the subtasks Isabella does when Isabella is waking up and completing the morning routine from 06:00AM ~ 07:00AM (total duration in minutes 60). Strictly follows this format: <index>) <activity> (duration: <duration_in_minutes>).:
1)
1) Wake up (duration: 5)
2) Stretch and do some light yoga (duration: 10)
3) Make bed (duration: 5)
4) Go to the bathroom, wash face, brush teeth (duration: 10)
5) Put on comfortable clothes (duration: 5)
6) Make a cup of coffee or tea (duration: 5)
7) Enjoy coffee/tea and read a few news articles (duration: 10)
8) Plan out the day, including Valentine's Day party tasks (duration: 5)
9) Pack a healthy lunch for work (duration: 10)
10) Take out the trash and recycling (duration: 5)
- Determine the next action:
Sam Kim lives in {Sam Kim's house} that has Sam Kim's room, bathroom, kitchen.
Sam Kim is currently in {Sam Kim's house} that has Sam Kim's room, bathroom, kitchen.
Area options: {Sam Kim's house, The Rose and Crown Pub, Hobbs Cafe, Oak Hill College, Johnson Park, Harvey Oak Supply Store, The Willows Market and Pharmacy}.
For taking a walk, Sam Kim should go to the following area: {Johnson Park}
There are more of the tasks needed to complete a whole day work. With the same concept and a bit of postprocessing, An agent will end up living themself on their own
7.
Future work
- Player Integration: Implement a robust system for user accounts and player profiles, enabling users to log in, track their progress, and interact with each other. The world of NPCs will still live with or without players
- Database Migration: Transition from the current file-based storage system to a PostgreSQL database to enhance data management, scalability, and security. This will resolve a bug of miscommunication between BE and FE at the moment and also strengthen the system in general
- Modular Backend Development: Develop a more generalized backend architecture with well-defined APIs. This will facilitate seamless integration with a wider range of games and applications
8.
Reference
https://arxiv.org/abs/2304.03442
https://arxiv.org/abs/2307.07924
Comments