Behavior AI Intermediate
While dialogue systems handle what NPCs say, behavior AI determines what they do. This lesson covers how to combine traditional behavior trees with LLM-powered reasoning to create NPCs that can plan, react to world changes, and adapt their behavior based on player interactions.
Behavior Trees + LLMs
The hybrid architecture uses behavior trees as the execution layer and LLMs as the reasoning layer. The behavior tree handles reliable, frame-by-frame actions (movement, combat, animations), while the LLM makes high-level decisions during "thinking" moments.
Decision Architecture
| Layer | Engine | Update Rate | Examples |
|---|---|---|---|
| Reflexes | Behavior Tree | Every frame | Dodge, flee from danger, follow path |
| Tactics | Utility AI | Every few seconds | Choose target, select weapon, take cover |
| Strategy | LLM | On trigger | Plan daily schedule, decide loyalty, set goals |
LLM Decision Calls
When the NPC reaches a decision point (e.g., a player asks for help, a new threat appears), query the LLM with the NPC's current state, goals, and options. The LLM returns a structured decision that the behavior tree can execute.
Emergent Behavior
When NPCs share information through the memory system and make LLM-driven decisions, emergent social dynamics arise naturally. NPCs may form alliances, spread rumors, or avoid locations based on past experiences - creating living worlds without explicit scripting.
Schedules and Routines
Use the LLM to generate daily schedules for NPCs based on their role and personality. A blacksmith NPC might work at the forge in the morning, eat lunch at the tavern, and close shop at sunset. The behavior tree executes the schedule while the LLM handles interruptions.
Ready to Go Deeper?
Live instructor-led courses from our partners. Affiliate disclosure.
AI & ML Courses - 30% Off
Live instructor-led AI, machine learning, data science, and cloud courses for working professionals. Use code Limited30 at checkout.
EdurekaDataCamp - AI & Data Science
Hands-on Python, machine learning, and AI courses with interactive exercises and real projects.
DataCampedX - Top AI Courses
University-level AI courses from MIT, Harvard, Stanford. Earn certificates that employers recognize.
edX