molroomolroo
API Reference

Turn (Appraisal)

Process game events and non-text interactions through direct appraisal vectors.

Turn (Appraisal)

Bypass the automatic text-based cognitive appraisal and supply your own 6-dimensional appraisal vector directly. This is ideal for game events, sensor data, and any non-text interaction where you compute the appraisal yourself.


Process Appraisal Turn

POST /v1/turn/appraisal

Send a pre-computed appraisal vector to the emotion engine. Instead of the API interpreting a natural language event description, you provide the exact cognitive appraisal values. The engine then computes the emotional state change, updates body budget, soul stage, and returns the full result including prompt data for your LLM.

Headers

HeaderTypeRequiredDescription
AuthorizationstringYesBearer YOUR_API_KEY
Content-TypestringYesapplication/json

Request Body

FieldTypeRequiredDescription
sessionIdstringYesSession ID
appraisalobjectYes6-dimensional appraisal vector
appraisal.goal_relevancenumberYesHow relevant is this event to the character's goals [0, 1]
appraisal.goal_congruencenumberYesDoes the event help (+) or hinder (-) goals [-1, 1]
appraisal.expectednessnumberYesHow expected was this event [0, 1]
appraisal.controllabilitynumberYesHow much control the character has [0, 1]
appraisal.agencynumberYesWho caused the event: negative = external, positive = self [-1, 1]
appraisal.norm_compatibilitynumberYesAlignment with character's values [-1, 1]
contextstringNoDescription of what happened (for prompt_data enrichment)
elapsedSecondsnumberNoTime in seconds since last interaction

Appraisal Vector Ranges

DimensionRangeDescription
goal_relevance[0, 1]0 = irrelevant, 1 = highly relevant to the character's goals
goal_congruence[-1, 1]-1 = completely blocks goals, +1 = perfectly advances goals
expectedness[0, 1]0 = total surprise, 1 = fully anticipated
controllability[0, 1]0 = no control, 1 = full control over the situation
agency[-1, 1]-1 = purely external cause, +1 = purely self-caused
norm_compatibility[-1, 1]-1 = violates values, +1 = perfectly aligns with values

Response

The response is identical to the Process Turn endpoint:

FieldTypeDescription
appraisalobjectThe appraisal vector (echoed back)
prediction_errornumberDifference between expected and actual appraisal
emotion_deltaobjectChange in emotional state { V, A, D }
new_emotionobjectUpdated emotional state { V, A, D }
emotion_intensitynumberOverall intensity of the emotional state [0, 1]
discrete_emotionstringClosest discrete emotion label (e.g., "fear", "anger")
soul_stageobjectCurrent developmental/narrative phase
body_budgetobjectEnergy and stress levels { energy, stress }
stage_transitionobject|nullSoul stage transition info, if one occurred
prompt_dataobjectPre-built context for your LLM prompt

Use Cases

  • Game events — An enemy attack, a level-up, a treasure discovery
  • Sensor data — Physiological signals translated into appraisal dimensions
  • Non-text interactions — Button presses, gesture inputs, timer events
  • Custom appraisal logic — When your application has its own event interpretation

Examples

curl

An NPC getting hit by critical damage: high goal relevance, very negative goal congruence, low expectedness.

curl -X POST https://api.molroo.io/v1/turn/appraisal \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "sessionId": "session_xyz",
    "appraisal": {
      "goal_relevance": 0.95,
      "goal_congruence": -0.9,
      "expectedness": 0.15,
      "controllability": 0.1,
      "agency": -0.8,
      "norm_compatibility": -0.5
    },
    "context": "Player character took a critical hit from a dragon (850 damage, 20% HP remaining)",
    "elapsedSeconds": 3
  }'

JavaScript

const response = await fetch("https://api.molroo.io/v1/turn/appraisal", {
  method: "POST",
  headers: {
    Authorization: "Bearer YOUR_API_KEY",
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    sessionId: "session_xyz",
    appraisal: {
      goal_relevance: 0.95,
      goal_congruence: -0.9,
      expectedness: 0.15,
      controllability: 0.1,
      agency: -0.8,
      norm_compatibility: -0.5,
    },
    context:
      "Player character took a critical hit from a dragon (850 damage, 20% HP remaining)",
    elapsedSeconds: 3,
  }),
});
 
const result = await response.json();
// result.new_emotion = { V: -0.65, A: 0.82, D: -0.41 }
// result.discrete_emotion = "fear"
// result.emotion_intensity = 0.85
// result.body_budget = { energy: 0.55, stress: 0.78 }

Python

import requests
 
response = requests.post(
    "https://api.molroo.io/v1/turn/appraisal",
    headers={"Authorization": "Bearer YOUR_API_KEY"},
    json={
        "sessionId": "session_xyz",
        "appraisal": {
            "goal_relevance": 0.95,
            "goal_congruence": -0.9,
            "expectedness": 0.15,
            "controllability": 0.1,
            "agency": -0.8,
            "norm_compatibility": -0.5,
        },
        "context": "Player character took a critical hit from a dragon (850 damage, 20% HP remaining)",
        "elapsedSeconds": 3,
    },
)
 
result = response.json()
print(result["discrete_emotion"])  # "fear"
print(result["new_emotion"])       # {"V": -0.65, "A": 0.82, "D": -0.41}
print(result["prompt_data"])       # Pre-built LLM context with emotional state

Example: Level Up (Positive Event)

A positive game event where the NPC levels up after a hard-fought battle:

{
  "sessionId": "session_xyz",
  "appraisal": {
    "goal_relevance": 0.8,
    "goal_congruence": 0.9,
    "expectedness": 0.6,
    "controllability": 0.7,
    "agency": 0.8,
    "norm_compatibility": 0.7
  },
  "context": "Character leveled up to level 15 after defeating the forest guardian"
}

This would produce a positive emotional shift (joy/pride) because the event is goal-congruent, self-caused (high agency), and controllable.

Errors

CodeStatusDescription
UNAUTHORIZED401Invalid or missing API key
VALIDATION_ERROR400Invalid appraisal values (out of range)
NOT_FOUND404Session not found
RATE_LIMIT429Too many requests

On this page