Game Systems
Building NPC Reasoning
Create intelligent NPCs that can reason about their environment and make decisions based on goals, beliefs, and context.
Quick Start Guide
Start with 2-3 clear goals that drive your NPC's behavior
Include relevant information about the environment
Start with simple decisions and expand complexity
Key components of NPC reasoning
-
Goals & Beliefs
Define what drives your NPCs and how they view the world.
-
Action Selection
Help NPCs choose appropriate actions based on their context.
-
ReACT System
Implement continuous reasoning for dynamic NPC behavior.
-
Game Integration
Connect reasoning systems to your game's mechanics.
Goals & Beliefs
Define your NPC's motivations and worldview to drive their decision-making process.
Example NPC Definition
System: You are a guard captain responsible for town security. Consider these goals and beliefs when making decisions. Goals: - Maintain order in the town - Protect citizens from threats - Train and coordinate the guard force - Build trust with the community Beliefs: - Prevention is better than punishment - Every citizen deserves fair treatment - The guard force must maintain high standards - Cooperation with other town officials is essential Current Context: - Recent increase in petty theft - Limited guard personnel available - Upcoming festival will strain resources
Goal Types
- Primary Goals: Core objectives that drive main behavior
- Secondary Goals: Supporting objectives that influence decisions
- Maintenance Goals: Ongoing states to maintain
Belief Systems
- Core Beliefs: Fundamental values that shape decisions
- Situational Beliefs: Context-specific assumptions
- Learned Beliefs: Knowledge gained from experience
Action Selection
Help NPCs choose appropriate actions by analyzing their context and available options.
Available Actions
PATROL: Move through an area watching for trouble INVESTIGATE: Examine a suspicious situation INTERACT: Talk with citizens or other NPCs PURSUE: Chase after a suspect GUARD: Stand watch at a specific location ASSIST: Help citizens or other guards REST: Take a break to recover stamina
Example Decision Request
Current Situation: - Suspicious person loitering near market stalls - Two guards currently on patrol nearby - Market is crowded with shoppers Response: { "selected_action": "INVESTIGATE", "target": "suspicious_person", "reasoning": "Large crowd presents opportunity for theft. Better to investigate now than risk incident.", "coordination": { "assign_guards": "maintain_patrol", "backup_needed": false } }
ReACT System
ReACT (Reasoning and ACTion) is a continuous decision-making system that helps NPCs respond to their environment in real-time.
System Components
- Perception: Gather information about nearby entities and state
- Analysis: Evaluate current situation against goals and beliefs
- Planning: Choose appropriate actions to achieve goals
- Execution: Carry out selected actions and monitor results
Example ReACT Cycle
Perception Update: - Player approaching with drawn weapon - Two civilian NPCs nearby - Guard post within running distance Analysis & Decision: { "threat_level": "moderate", "primary_concern": "civilian_safety", "selected_action": "INTERACT", "action_details": { "approach": "cautious", "dialogue_type": "de-escalation", "backup_plan": "escort_civilians" } }
Performance Optimization Tips
Update Frequency
- • High Priority: 0.1-0.5 seconds
- • Medium Priority: 0.5-2 seconds
- • Low Priority: 2-5 seconds
Optimization Techniques
- • Batch similar decisions
- • Cache recent results
- • Use decision timeouts
Common Issues & Solutions
Unnecessary Actions
When NPCs always decide to do an action, even when it's not needed.
Solution: Always include a "NONE" action to choose from. LLM's have a hard time choosing nothing from a list of actions, unless nothing is explicitly an option.
Conflicting Goals
When multiple goals suggest different actions
Solution: Implement clear goal hierarchies and weighting systems
Game Integration
Connect your reasoning systems to your game's mechanics and systems.
Integration Tips
- State Management: Keep NPC state synchronized with game world
- Performance: Use appropriate update intervals for different reasoning types
- Fallbacks: Implement default behaviors when reasoning system is busy
- Debug Tools: Create visualization tools for NPC decision-making
Additional Tips
- Start with simple goal/belief systems and expand as needed
- Use consistent action types across similar NPCs
- Consider performance impact of reasoning frequency
- Implement graceful fallbacks for complex decisions
- Test reasoning systems with various edge cases
Common Reasoning Patterns
Do ✓
- Keep goals simple and focused
- Update context frequently
- Implement fallback behaviors
Don't ✗
- Overload with too many goals
- Ignore performance implications
- Make decisions without context
Want to learn more?
Check out our guides on building NPCs and creating dialogue.