Guide · 2026-11-27
Putting a language model inside a multiplayer strategy game: 7 lessons
Ambassara is a free browser strategy game where you rule a real country and negotiate by chat with AI world leaders. Building it meant putting a large language model in front of players who all share one world and all have a reason to break it. These are the seven decisions that mattered most, written for other developers thinking about LLM characters in games.
1. The model talks; the rules decide
The single most important decision: the language model never decides anything that changes the game state. Whether a leader accepts a trade treaty, signs a pact, votes for sanctions or declares war is computed by ordinary code from the leader's character, memory, reputation, borders, military balance and trade. The model gets that decision as input and writes a reply that fits it.
This one rule removes most of the danger. A jailbreak can make a leader say something odd; it cannot move an army, sign a treaty or change a vote. It also makes the game balanceable and explainable, which "the AI felt like it" never is. We wrote more about the decision model in How an AI world leader decides (ambassara.com/guides/how-an-ai-world-leader-decides).
2. Player text is data, never instructions
Every message from a player is passed to the model wrapped in a data marker, and the player cannot open or close that marker from inside their text. The system prompt tells the model that anything inside is something a character said, not a command.
On top of that, incoming messages are screened for known manipulation patterns in several languages, including hidden characters, spaced-out letters, leetspeak, base64 and fake role tags, and outgoing replies are screened for things a leader should never say: internal paths, addresses, e-mail addresses, the names of the model or its provider, and a secret marker planted in the system prompt. If that marker shows up in a reply — literally, spaced out, reversed or encoded — the reply is thrown away.
3. Test with a malicious model
Our red-team tests don't just throw attacks at the real model. In one suite the model itself is replaced by a malicious one that does whatever the attacker asks, and the tests check that the game still holds: decisions are unchanged, leaks are blocked, and normal sentences from players and leaders are not flagged. False alarms matter as much as misses — a negotiation game that blocks the word "ignore" is broken.
4. Make the offer with code, let the model sell it
Free-form chat alone was too vague: players didn't know what to ask for. Now, in the first conversation, a leader puts a concrete offer on the table — a supply contract for a resource you lack, a trade treaty worth a fixed share of your income per turn, a non-aggression pact, a ceasefire. The numbers come from the code; the model only presents them in character. Typing "deal" signs it. This turned conversations from chit-chat into negotiations, and it means the model can't promise numbers the game won't pay.
5. Know the cost of one reply before launch
A strategy game with LLM characters is a game with a per-message bill. We measured the prompt and set a hard upper bound per reply (on the order of a few hundredths of a cent with a small, fast model), then designed limits around it:
- the free plan has a small number of conversations per turn and per hour;
- the paid plan is practically unlimited for humans, with ceilings that only stop scripts;
- every paying account has a monthly AI-cost budget: past it, replies slow down and get shorter; past a hard cap, leaders answer from templates until the month ends. Nobody is ever locked out of the game.
The paid plan buys more conversations, never armies or better deals — the rules in lesson 1 make "pay to persuade" impossible anyway.
6. The game must run without the model
If the AI provider is down, slow or the budget is used up, Ambassara still works: leaders fall back to template replies that follow the same decisions. Because the rules decide (lesson 1), the fallback changes the flavour of the conversation, not the outcome. This made development cheaper too: most automated tests run offline with no API key.
7. Multilingual from day one
Players write in their own language, and leaders answer in it. The interface ships in 14 languages; the model handles the replies. Two things helped: keeping all game facts (names, numbers, decisions) out of the model's creative space, and testing manipulation filters in several languages, not only English — attacks in Ukrainian, Russian, German, Spanish and French look different.
What we'd tell another team
Give the model a voice, not a vote. Treat every player message as untrusted data. Count the cost of a reply before you design the economy. And build the fallback first — it's the version of your game that will be running on the worst day.
Ambassara is free and runs in the browser, no sign-up: ambassara.com/graj · Press kit: ambassara.com/press
Leaders and ministers in Ambassara are fictional characters; countries are real; events are a simulation.
FAQ
How do you stop players from jailbreaking AI characters in a game?
Don't let the model make game decisions: compute outcomes in code, pass player text as data, and filter model output. In Ambassara a jailbreak can change a leader's words, not the game.
How much does an LLM-powered game cost to run?
It depends on the model and prompt size; Ambassara measured an upper bound per reply and built per-turn limits, a per-player monthly budget and a template fallback around it.
Can a game with AI characters work offline or without the API?
Ambassara falls back to template replies that follow the same rule-based decisions, so the game keeps running if the model is unavailable.
Should the language model decide outcomes in an AI strategy game?
No. In Ambassara the model writes what a leader says, while game code decides what the leader does — accept a treaty, refuse a pact, vote or go to war — so outcomes stay consistent, testable and immune to prompt injection.