Learning AI-DLC building a game, part 17: AI rivals that explain

Part 17 of the AI-DLC game series: the rules decide a proposal first, only match facts go to Amazon Nova Lite, our checks and a content filter screen the sentence, and the player sees a reason bubble under the proposal or today's fixed words, with 10 real calls at about $0.0002 each and 493 rounds under load

This is part 17 of a series on learning AI-DLC by building a game, World Rift Conflict, in Godot with an AWS backend. Part 1 set it up, and part 16 got the agents working in Claude Code's auto mode again. This one is about the feature those agents then built: the first piece of the game that calls an AI model.

Parts so far:

The idea

In World Rift Conflict, two to four players run countries, and the empty seats are played by the computer. Until now a computer-run country answered a proposal with a status line and nothing else: "You to Kenya: treaty accepted". Players could not tell why.

The new feature adds one sentence under that line, in the player's language, written by a model:

With this treaty, we enhance our economy by 15 points, securing a projected lead of 12 over our competitors.

That is a real answer from the test backend. The Spanish one for the same decision read "Gracias a este tratado, mejoramos nuestra economía en 15 puntos y consolidamos nuestra ventaja de 12 puntos en la competición."

The piece of work ran from 10 to 27 November as one AI-DLC intent, 261110-ai-rivals-signin, with five units: the reason function on the backend, its delivery through the live server, the bubble on screen, a sign-in cleanup, and the test kit.

The rules decide, the words come after

The most useful answer of the whole intent came early, at the practices interview, when AI-DLC asked what "the same seed gives the same match" should mean once a model is involved. My answer: outcomes and scores only. The rules decide first, with no model, and the words are written afterwards from that decision. The words never feed back into a rule, a score or a computer-run country's next move.

That one line kept everything else simple. Tests of the match logic stay exact, because two runs with the same seed give the same results and may give different sentences. A model that is slow, down or switched off cannot change who wins.

The path of one sentence

A Godot game client talks to the live server on EC2 over a WebSocket; the live server invokes a Lambda function, which reserves a call in DynamoDB, asks Amazon Bedrock Nova Lite, screens the sentence with Bedrock Guardrails, and counts every answer in CloudWatch, whose alarms email the owner through SNS
  1. A player's proposal is resolved by the rules on the live server, which already runs the match.
  2. The server sends that player "pending", which shows three still dots under the row, and asks the reason function through its sidecar. Only the server's role may invoke the function. In Build and Test, a signed-in player's credentials and a guest's were both refused (AccessDeniedException).
  3. The function reads the owner's switch (off, stand-in or model) and reserves one call against a monthly limit and a per-player daily limit. No reservation, no call.
  4. It sends Amazon Nova Lite only match facts: the countries, their stats, the proposal and the numbers behind the decision. Never an email, an account, a display name or anything a player typed. That was a hard rule from the same interview.
  5. The reply is read strictly in a fixed shape and checked by plain code: length, at most two sentences, the asked language, no links or markup. Then the sentence goes through Bedrock Guardrails with the ApplyGuardrail API, which screens it for hate, insults, sexual content, violence and misconduct.
  6. Within 5 seconds the player gets the sentence as a bubble, or "dropped" and today's fixed words. A round never waits for a sentence.

Every answer adds to a count by result and cause. Alarms at 80% and 100% of the monthly limit, and alarms for failing texts and a failing function, email me.

Spending limits before the model is ever on

The project has a running-cost ceiling of about $50 a month, and AI-DLC kept asking about it at every stage that could spend money. What came out of those answers:

  • The model starts switched off in production. I turn it on with an owner command once the real cost per call is measured.
  • The monthly limit for production is 20,000 calls, worked out from the published prices so the month stays at or under $5.
  • The test backend has its own limit, and most end-to-end tests use a stand-in: the same function and limiter, answering with fixed text. Two named scenarios, one English and one Spanish, call the real model, at most 10 calls a run.

The stand-in turned out to matter for another reason, which comes up below.

What Build and Test found

AI-DLC's Build and Test stage runs everything on the real test backend: the Godot tests, the TypeScript tests, and the end-to-end suite on Linux, Chromium, Firefox and WebKit. It took seven runs. Each run's failures were diagnosed before anything was changed, and most of them were in the tests, not the game.

A real bug that a warm copy hid. The function reads its settings with a 150 ms limit and fails closed, as "switched off", when the read is late. In one run a request got the fixed words because the read took 318 ms, on a copy of the function that was warm, with no cold start, but had been idle for five minutes. The connection to the table had to be opened again. With few players, most real requests come after an idle spell like that, so this would have hit production often. The fix gives the first read after a minute of idle the same 1 second limit as a cold start's first read, with a regression test.

The test backend ran out of money on paper. Stand-in answers go through the real limiter, so they count. One full four-platform run used the whole test limit of 400 calls, and the real-model scenarios then skipped themselves. The kit now clears the test month's count before each platform.

Tests that passed by luck. Two of them:

  • A check that the last round's sentence arrives after the match ends looked for "pending" after the end message. The server sends "pending" before it. The test had passed only because its search started at the previous match's end message. Fixing a different bug, making searches start at the current match, exposed it.
  • A check of the bubble on a computer's proposal watched only the English player. In one run the computer-run countries proposed only to the Spanish player, all match long. The test now watches every player.

When the cause of a failure was unclear, a seat dropped as silent after round one in one run, the agent asked me whether to find the cause or patch the test. I chose the cause. The kit now writes a timed copy of the server log and every slow test command. That drop has not come back, and its cause is still unknown.

The numbers

  • Real model: 10 calls, 0.68 to 1.26 seconds each, at most 237 tokens in and 43 out, about $0.0002 a call at the published prices. Nine were texts. One Spanish answer failed our own check, so that player would have seen the fixed words.
  • Cold starts: 20 requests at once after an hour idle, all 20 cold, the slowest 1.6 seconds end to end.
  • The limit under a burst: with the monthly limit at 5 and 25 requests at once, exactly 5 got a text. Both limit alarms fired.
  • Load: 20 bot players for 30 minutes with reasons on: 493 rounds, every round result within 222 ms, against a 2 second limit.
  • Download: the web build grew by 9,314 bytes, and its first screen still loads in 5.2 seconds on a throttled connection.

The content filter needed one more step. My AWS role was not allowed to call it directly, so I added that permission myself. Then a test phrase for each category was blocked under that category, and an ordinary game sentence passed.

What is still open

AI-DLC's Build and Test does not round up. Out of 135 measurable targets, 130 were met, and it marked the stage as failed until I accepted the rest knowingly:

  • The model provider keeps a copy. One requirement says the provider should not store what we send or what it answers. My account has Bedrock model invocation logging switched on with text included, set up earlier for another project, and that setting covers every model call in the account and Region. What is kept is match facts and one-sentence replies, with no player data, but the requirement is not met. Turning it off affects the other project, so it is my decision to make.
  • The screen reader check. The bubble is announced to the accessibility layer, and tests check that. Whether a real screen reader reads it after the status word, once, needs a person listening.
  • A week of real traffic, for the 95% texts target, which can only be measured once the model is on in production.

Checking the download size turned up one more thing, older than this work: the cloud build runs the Godot tests before exporting, and the export was packing the test report's logo into the public web build, about 43 KB. It is a one-line fix to the export filters.

What I would tell myself

  • Decide what the model may not change before you call it. "The rules decide, the words follow" made determinism, fallbacks and tests easy.
  • Put the spending limit and the off switch in the first design, not after the bill. A fake that goes through the real limiter also tests the limiter.
  • A warm function is not a warm connection. If you time-limit a first read, time-limit the first read after an idle spell too.
  • Read failures before fixing them, and ask whether the test or the product is wrong. Most of the seven runs' failures were the tests'. The one product bug was found the same way.

What is next

Pushing this to production with the model still switched off, then measuring a real match's cost before turning it on.