
Weekend Creative Challenge: Once Upon an AI Adventure
A weekend-built text adventure game where nothing is scripted — Amazon Bedrock (Claude Haiku 4.5) writes every scene and choice live, based on what you pick. Genre selection, a riddle-posing spectral guardian, and a real ending, all generated on the fly. Built entirely in an AWS Builder Center sandbox, including diagnosing an IAM permission wall along the way.
Vision & What the App Does
I wanted to build something that makes people smile, and nothing does that faster than a choose-your-own-adventure story where you genuinely don't know what happens next — not even the app knows, until the moment you make a choice.
Once Upon an AI Adventure is a tiny terminal-based text adventure game. You pick a genre — fantasy quest, space explorer, detective mystery, or "surprise me" — and Amazon Bedrock generates a brand-new opening scene on the spot, along with three choices for what to do next. Every choice you make gets fed back into the story so far, and Bedrock writes the next beat of the adventure in response — building a genuinely unique narrative each playthrough, with a proper ending after a few turns rather than trailing off. No two runs are the same, because nothing is pre-written except the game loop itself; every word of the actual story is generated live. In one real playthrough, a spectral guardian at an ancient archway posed a riddle, accepted a wrong answer as a "test of resolve" instead of a failure, and the story adapted accordingly — the kind of branching that's only possible because the model is actually writing in the moment, not selecting from a pre-built tree.

How I Built It
The whole app is one Python script, on purpose — the challenge's own advice was to keep it simple and do one creative thing well, and a text adventure doesn't need more than a loop and a model call.
Key decisions:
- A strict output format in the prompt. Early on I needed the model's response split cleanly into "the scene text" and "the three choices," so the game loop can print them and accept a 1/2/3 input. I had Bedrock return a fixed
SCENE: ... / CHOICES: 1. ... 2. ... 3. ...format and wrote a small parser around it, rather than trying to free-parse whatever came back.
- Carrying story state forward as plain text, not structured memory. Each turn's prompt includes a running "story so far" string plus the player's latest choice, so Bedrock has full context without needing any database — the entire game state lives in one Python string for the duration of a playthrough.
- A hard turn limit with a distinct "final turn" prompt. Open-ended generation loops risk never actually ending. On the last turn, the game sends a different prompt explicitly asking for a conclusive ending instead of more choices, so every playthrough reaches a genuine "THE END" rather than trailing off mid-story.
- Saving a full transcript automatically. Every playthrough — the scenes, the choices offered, and what I picked — gets written to a timestamped file, so there's always a concrete record of a real game that was actually played, not just the code that could theoretically run it.
The trickiest part was making sure the choice parsing was resilient: if a player types something unexpected, the game falls back to the first choice rather than crashing, since the whole point is a fun, low-friction toy, not a strict input validator.
The other real snag was discovering which model this particular workshop sandbox actually lets you call. My first version targeted Amazon Nova Lite, which worked flawlessly in a previous sandbox from an earlier project — but this workshop's IAM role denied it outright. Reading the role's attached inline policy (named, helpfully,
BedrockInvokeAnthropic ) showed it scopes bedrock:InvokeModel to Anthropic models only. Even then, the newest Claude Haiku model rejected direct on-demand invocation with a message pointing at inference profiles instead — Bedrock's mechanism for routing certain newer models across regions. Prefixing the model ID with us. (the standard cross-region inference profile format) resolved it. Two unrelated permission puzzles, solved by reading the actual error messages carefully rather than guessing.
AWS Services Used / Architecture Overview
- Amazon Bedrock (Claude Haiku 4.5, via a cross-region inference profile) — the only AWS service the app needs. It generates every scene and choice set, live, via
invoke_modelcalls tous.anthropic.claude-haiku-4-5-20251001-v1:0.
Player picks a genre | vBedrock (Claude Haiku 4.5) generates opening scene + 3 choices | vPlayer picks a choice <----------------+ | | v |Bedrock generates next scene + choices | | (repeat for a few turns) -----+ vBedrock generates a proper ending | vFull playthrough saved to transcript_<time>.txtThe app is triggered by running the script directly — appropriate for an interactive toy you play on demand, not something that needs to run unattended.
What I Learned
This was a good lesson in prompt engineering as interface design: the model isn't just generating prose here, it's effectively returning structured data that a program has to parse reliably. Being explicit and rigid about the output format (rather than hoping for consistent free-text) made the difference between a game loop that works every time and one that occasionally breaks on a weird response. I also learned that different workshop sandboxes genuinely have different IAM scopes — one grants Amazon Nova access, another grants Anthropic-only access via an inference profile — so the right move at the start of any sandbox project is a quick permission probe, not an assumption carried over from the last one. Reading the actual policy document and error messages (rather than guessing at model IDs) turned a dead end into a five-minute fix.
Link to App or Repo
The repo includes the full game script (
adventure.py ) and a real saved transcript from a complete playthrough, showing the generated story, choices, and ending.Enjoyed reading this content? Let the author know!
Your likes, comments, shares, and saves help creators reach more builders.
Loading recommendations
Loading article