Gaming Integration
Use appraisal vectors to give NPCs real emotions in game events.
Gaming Integration
Games are full of events that are not text -- combat hits, item drops, level ups, NPC deaths, environmental changes. The appraisal endpoint (POST /v1/turn/appraisal) lets you translate these game events directly into emotional state changes without any LLM calls. This guide shows how to map game events to appraisal vectors and use the results for NPC dialogue and behavior.
Why Appraisal Vectors for Games?
The standard POST /v1/turn endpoint takes a text description and runs it through cognitive appraisal internally. This works for conversational apps, but games have structured events that you already understand. With the appraisal endpoint, you:
- Skip the text interpretation step -- faster response times, lower cost
- Control exactly how events are perceived -- you decide how relevant or surprising an event is to the NPC
- Map any game mechanic -- combat, economy, social systems, environmental events
- Keep it deterministic -- the same appraisal vector always produces the same emotional shift
Mapping Game Events to Appraisals
The 6-dimensional appraisal vector captures how a character perceives an event:
| Dimension | Range | Game Meaning |
|---|---|---|
goal_relevance | [0, 1] | How much does this event matter to the NPC? |
goal_congruence | [-1, 1] | Does this help (+) or harm (-) the NPC's goals? |
expectedness | [0, 1] | Was this event anticipated? |
controllability | [0, 1] | Can the NPC do anything about it? |
agency | [-1, 1] | Who caused it? -1 = external, +1 = self |
norm_compatibility | [-1, 1] | Does this align with the NPC's values? |
Common Game Event Mappings
| Game Event | goal_relevance | goal_congruence | expectedness | controllability | agency | norm_compatibility |
|---|---|---|---|---|---|---|
| Enemy critical hit | 0.8 | -0.9 | 0.3 | 0.2 | -0.4 | 0.0 |
| Level up | 0.9 | 0.9 | 0.5 | 0.8 | 0.8 | 0.7 |
| Ally death | 1.0 | -1.0 | 0.1 | 0.1 | -0.8 | -0.5 |
| Treasure found | 0.6 | 0.8 | 0.2 | 0.5 | 0.3 | 0.5 |
| Betrayal by ally | 1.0 | -0.9 | 0.1 | 0.1 | -0.9 | -1.0 |
| Boss defeated | 1.0 | 1.0 | 0.4 | 0.7 | 0.9 | 0.8 |
| Ambush | 0.9 | -0.7 | 0.0 | 0.2 | -0.8 | -0.3 |
| Healing received | 0.5 | 0.7 | 0.6 | 0.3 | -0.5 | 0.6 |
Use these as starting points and adjust for your specific game mechanics and NPC personalities.
Code Example: Processing a Game Event
curl
JavaScript
Building an Event Mapper
Rather than hardcoding appraisal values each time, create a mapping function:
Dynamic Appraisals
For more nuance, scale appraisal values based on game context:
Using prompt_data for NPC Dialogue
The response includes prompt_data.formatted -- a pre-built text block you can feed directly into your dialogue system or LLM:
Using Emotion Data for Non-Dialogue Behavior
You do not need an LLM for every use case. Use the raw emotion data to drive game mechanics directly:
Persistent NPC State
Sessions persist across game sessions automatically. When a player saves and returns later, the NPC remembers its emotional history:
Tip: Use deterministic session IDs based on your NPC identity, such as npc_{npcId} or {saveSlot}_npc_{npcId}, so the same NPC always maps to the same emotional session.
Batch Processing Multiple NPCs
When a game event affects multiple NPCs (like an explosion in a town square), process them in parallel:
WebSocket for Real-time Games
For games that need frequent emotion updates (action RPGs, real-time combat), use a WebSocket connection instead of REST calls. See the WebSocket guide for setup details.