| Author | sudo-0x2a |
|---|---|
| First upload | 09/08/2025 |
Explore a RPG game engine that brings NPCs to life using Large Language Models (LLMs) with persistent memory, intelligently interacting with the game engine, and dynamic storytelling.
This project is not a complete game. It is just a demo.
- Natural Conversations: Chat with NPCs using natural language
- Dynamic Relationships: NPC attitudes change based on a relationship score (The score update has not been implemented yet).
- Smart Trading: Trade items through conversation
- Persistent Memory: NPCs remember past interactions using RAG (Retrieval-Augmented Generation)
Movements: WASD
Left Click the NPC to see the action menu.
The player initially has 100 golds and 10 health potions. Let's purchase 2 health potions and 1 iron sword from the merchant.
LLM: Qwen3-4B-Thinking-2507 AWQ-4bit, VRAM usage is under 3GB.
-
Clone the repository
git clone https://github.com/yourusername/rpg-llm.git cd rpg-llm -
Install Python dependencies
pip install -r requirements.txt
-
Install JavaScript dependencies
cd phaser_JS npm install cd ..
-
Configure your AI provider
Create a
.envfile in the root directory:For Local LLM (LM Studio):
OPENAI_API_KEY="lm-studio" OPENAI_BASE_URL="http://localhost:1234/v1"
For OpenAI:
OPENAI_API_KEY="your-openai-api-key" OPENAI_BASE_URL="https://api.openai.com/v1"
-
Run the game
python server.py
-
Run the demo Open your browser and navigate to
http://localhost:8000
$ python server.pyโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ
โ Frontend โ โ Backend โ โ AI System โ
โ (Phaser.js) โโโโโบโ (FastAPI) โโโโโบโ (LangGraph) โ
โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ
โ โ
โผ โผ
โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ
โ Game Engine โ โ Vector DB โ
โ (State Mgmt) โ โ (ChromaDB) โ
โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ
core/game_engine.py- Main game orchestratorbackend/api_main.py- FastAPI web server and REST endpointsai_agents/agents.py- LLM-powered NPC agentsai_agents/npc_memory.py- Vector database for persistent memoryentities/characters.py- Character and inventory managementcore/state_manager.py- Game state and event handling
main.js- Game initialization and configurationscenes.js- Phaser.js game scenes and renderingui.js- User interface and interaction handlingservices_events.js- API communication with backend
characters/- NPC and player JSON configurationsitems/- Item definitions and properties
-
Create NPC configuration in
config/characters/NPC_XXX/{ "id": 102, "name": "Luna", "role": "Wizard", "attributes": { "level": 5, "health": 80, "relationship": 0.0 }, "inventory": [ {"Magic_Scroll": 5}, {"Mana_Potion": 3} ], "ai_agent_config": { "system_message_path": "luna_prompt.txt", "tools": ["check_relationship", "check_shop_shelf", "make_trade"] } } -
Create system prompt (
luna_prompt.txt)You are Luna, a wise wizard who runs a magic shop in the mystical town of Arcana. You specialize in selling magical scrolls and potions to adventurers. You should always check your relationship with the player first. Maintain a mysterious but helpful personality.
Create item configuration in config/items/:
{
"id": 3001,
"name": "Magic Scroll",
"type": "consumable",
"tradable": true,
"description": "A scroll containing a powerful spell.",
"price": 15,
"effect": {
"mana": 30
}
}Each NPC can have different AI tools enabled:
check_relationship- Monitor player relationship statuscheck_shop_shelf- Display available items for salemake_trade- Execute buy/sell transactionsmemory_recall- Retrieve past conversation memoriescheck_inventory- View NPC's current inventory
GET /api/characters- Get all NPCs and playersGET /api/player- Get player data and inventoryGET /api/map- Get map configuration
POST /api/chat- Send message to NPCPOST /api/chat/close- End conversation (triggers memory save)
GET /api/health- Health check and system status
- Enhance the trading system so the price can be negotiated.
- Implement a weather system and the NPCs would react to weathers.
Graphics: Phaser 3
Arts Assets: Pipoya RPG Tilesets
Backend API: Fast API
Vector Database: Chroma DB
Embedding Model: google/embeddinggemma-300m
AI Agent Framework: LangGraph


