Game studios spend weeks manually writing NPC dialogue and quest lines that stay consistent with their world bible. I built a small pipeline that generates structured quest data and matching NPC dialogue from a short world description, then checks that the outputs do not contradict each other. It runs entirely on Oxlo.ai using the OpenAI SDK, so you can drop it into an existing toolchain without managing tokens per request.
What you'll need
- Python 3.10 or newer
- An Oxlo.ai API key from https://portal.oxlo.ai
- The OpenAI SDK:
pip install openai
Step 1: Configure the Oxlo.ai client
Create a file named game_tool.py and initialize the client. Oxlo.ai exposes an OpenAI-compatible endpoint, so the only difference is the base URL and your Oxlo.ai API key.
from openai import OpenAI
client = OpenAI(base_url="https://api.oxlo.ai/v1", api_key="YOUR_OXLO_API_KEY")
Step 2: Define the system prompt
The system prompt forces JSON output and locks the model into the role of a senior game designer.
SYSTEM_PROMPT = """You are a senior RPG systems designer. You generate quest and NPC data in JSON format. All names, factions, and locations must remain consistent with the provided world bible. Do not invent new factions unless the user explicitly asks for them. Output valid JSON only."""
Step 3: Generate a quest from a world seed
We pass a short world description and ask for a structured quest object. Using Oxlo.ai's request-based pricing means I do not need to worry about the length of the world bible I paste in. I can iterate with long context without the cost scaling.
WORLD_BIBLE = """
The world of Aethon is a post-magical-industrial city-state built inside a crater.
The ruling faction is the Brass Council.
Magic is powered by blood-amber crystals mined from the crater walls.
"""
def generate_quest(world_bible):
user_message = (
f"World bible: {world_bible}\n\n"
"Generate one side quest involving a missing blood-amber shipment. "
"Return JSON with keys: quest_name, giver_name, location, objective, reward_item."
)
response = client.chat.completions.create(
model="llama-3.3-70b",
messages=[
{"role": "system", "content": SYSTEM_PROMPT},
{"role": "user", "content": user_message},
],
)
return response.choices[0].message.content
quest_json = generate_quest(WORLD_BIBLE)
print(quest_json)
Step 4: Generate an NPC with dialogue
Now we feed the generated quest back in and ask for an NPC who gives the quest. This tests whether the model respects its own prior output.
def generate_npc(quest_data, world_bible):
user_message = (
f"World bible: {world_bible}\n\n"
f"Based on this quest JSON: {quest_data}\n\n"
"Generate an NPC who gives this quest. "
"Return JSON with keys: npc_name, race, faction, dialogue_lines (list of 3 strings), motivation."
)
response = client.chat.completions.create(
model="llama-3.3-70b",
messages=[
{"role": "system", "content": SYSTEM_PROMPT},
{"role": "user", "content": user_message},
],
)
return response.choices[0].message.content
npc_json = generate_npc(quest_json, WORLD_BIBLE)
print(npc_json)
Step 5: Validate lore consistency
Finally, we ask the model to compare the two JSON objects and flag any contradictions against the world bible. I use qwen-3-32b here because its agentic reasoning works well for verification tasks.
def validate_consistency(world_bible, quest_data, npc_data):
user_message = (
f"World bible: {world_bible}\n\n"
f"Quest: {quest_data}\n\n"
f"NPC: {npc_data}\n\n"
"List any contradictions between the quest, NPC, and world bible. If none, say 'CONSISTENT'."
)
response = client.chat.completions.create(
model="qwen-3-32b",
messages=[
{"role": "system", "content": "You are a lore consistency checker. Be concise."},
{"role": "user", "content": user_message},
],
)
return response.choices[0].message.content
check = validate_consistency(WORLD_BIBLE, quest_json, npc_json)
print(check)
Run it
Wrap the functions in a small CLI block and execute the script.
if __name__ == "__main__":
print("=== QUEST ===")
quest = generate_quest(WORLD_BIBLE)
print(quest)
print("\n=== NPC ===")
npc = generate_npc(quest, WORLD_BIBLE)
print(npc)
print("\n=== CONSISTENCY CHECK ===")
result = validate_consistency(WORLD_BIBLE, quest, npc)
print(result)
Example output:
=== QUEST ===
{
"quest_name": "The Shimmering Gap",
"giver_name": "Foreman Velka",
"location": "Crater Ward 7",
"objective": "Locate the missing blood-amber shipment before the furnaces die",
"reward_item": "Council Seal Ring"
}
=== NPC ===
{
"npc_name": "Foreman Velka",
"race": "Human",
"faction": "Brass Council",
"dialogue_lines": [
"The furnaces are choking. Without that shipment, we freeze by dawn.",
"Blood-amber does not mine itself, and the Council does not tolerate excuses.",
"Bring me the manifest, and this seal ring is yours."
],
"motivation": "Prevent a city-wide blackout to maintain Council authority"
}
=== CONSISTENCY CHECK ===
CONSISTENT
Wrap-up and next steps
You can extend this by wiring the JSON output directly into a game engine like Godot or Unity, or by adding a loop that generates an entire quest chain. If you need longer world bibles, switch to deepseek-v4-flash or kimi-k2.6 on Oxlo.ai, both of which handle extended context without inflating your bill because pricing is per request. See https://oxlo.ai/pricing for plan details.
Top comments (0)