I experimented with creating an intelligent conversational NPC powered by a large language model. It has a distinct character identity, responds to natural-language input from the user, and plays animations that match the emotion of its reply. The NPC also has a memory system: it can remember personal information about the user and answer accurately when asked about those specific details.

For this project, I built the backend with Python's FastAPI library and used LangChain to call the language model. Memories are stored in a local vector database. Unity serves as the frontend, handling user input and 3D rendering.

Below are some key code excerpts and demonstrations running in Unity:

Calling DeepSeek-V3.2 through its API.

Python code reading an API key from an environment variable and configuring a DeepSeek model callView full image
Calling the language model01

The system prompt gives the language model its character identity.

A Chinese system prompt describing the NPC character identity and personalityView full image
Defining the character02

Building the local vector database with ChromaDB.

Python code loading local text and splitting it into overlapping chunksView full image
Preparing local memory documents03

The system prompt strictly requires the model to include an "emotion tag" with every response. The C# code in Unity reads this tag and plays the corresponding animation.

The Unity Animator.

Animation states and transitions in the Unity AnimatorView full image
Connecting emotion and animation04

The Unity frontend code.

Unity C# code handling player input and sending a dialogue requestView full image
The Unity frontend05

Demonstration.

A character responding through a dialogue interface in UnityView full image
A conversation in Unity06

Testing the memory system.

The Unity dialogue interface showing a memory recall testView full image
Testing memory recall07