AWS Builder Center
Weekend Creative Challenge: Carrot in a Box

Weekend Creative Challenge: Carrot in a Box

Two boxes.One carrot. You know the truth; the AI only knows your words. Bluff well, survive its questions, and make it choose wrong.

Vision and what the app does

Carrot in a Box is a live, single-player bluffing game in which a human competes against an AI opponent for ownership of one very important carrot. The concept is intentionally simple: there are two boxes and exactly one carrot. The human, Player 1, is allowed to look inside their own box. Player 2 -
the AI - cannot see either box and must determine whether to keep its current box or swap with the human.
The human’s challenge is not to answer a trivia question or solve a puzzle. It is to create a convincing performance using language. After privately seeing whether the carrot is in their box, the player writes a short bluff between 4 and 30 words. The AI can ask up to two follow-up questions, analyze the player’s answers, and then make a final  KEEP  or  SWAP  decision. Whoever finishes with the carrot wins.
A second AI role acts as the Host. The Host welcomes both players, explains the rules, gives Player 1 permission to look inside, reacts between messages, adds comedic psychological pressure during periods of silence, and announces the final result. This means each round creates a small piece of interactive theatre: the human supplies the deception, Player 2 supplies suspicion and deduction, and the Host supplies timing, tension, and humor. The creative output is therefore a unique dramatic conversation generated from the player’s choices rather than a fixed script.
The frontend presents the experience as a polished single-page game. Opening Host messages are staged one second apart instead of appearing all at once. Each new chat message plays a lightweight notification tone using the browser’s Web Audio API, with a mute control for accessibility and user preference. The interface includes two visual boxes, a private carrot reveal, a live conversation panel, word-count feedback, AI decision presentation, and a final winner screen.
Game play


How I built it

I started by defining the game’s trust boundaries before writing the interface. The most important rule is that Player 2 must never receive the hidden box assignment. The assignment is stored separately from the public game transcript, and only trusted backend functions can read it. The AI opponent receives Player 1’s statements, its own previous questions, and the remaining question count—but no private reveal data and no database credentials.
The first architecture used AWS Step Functions and Amazon Bedrock Agents. During implementation, I realized that a long-running Step Functions workflow was not a natural fit for a WebSocket conversation. The game spends most of its time waiting for unpredictable human input. I replaced the workflow with an event-driven design where DynamoDB holds the authoritative state, Lambda functions handle individual events, and delayed SQS messages trigger Host comments when a player takes too long.
A larger challenge appeared during deployment: Amazon Bedrock Agents Classic was unavailable to the AWS account. Rather than abandon the two-agent experience, I moved both AI roles to the Amazon Bedrock Runtime Converse API. The Host and Player 2 now use separate system prompts and independently constructed conversation contexts. The Host still behaves like a tool-using agent: it can request  createGame  and  resolveGame  tools through Converse, but the backend validates each tool request, ignores model-supplied session identifiers, and invokes trusted Lambda code with authoritative values. This preserved the creative behavior without relying on Bedrock Agents Classic.
I used application-managed memory instead of hidden provider-side memory. The public transcript is stored in DynamoDB. Before invoking Player 2, the Orchestrator filters the transcript so the model sees only Player 1 and Player 2 messages. Host narration and the private reveal are excluded. Starting a new game creates a new session and removes the previous transcript, resume token, and secret assignment.
The Angular frontend was built as a strict, standalone-component application using Angular 20, which satisfies the Angular 17+ requirement and uses Angular’s Vite-powered development server. Signals represent game state, computed signals control available actions, and RxJS handles WebSocket events and bounded reconnection. Both the frontend and backend enforce the inclusive 4–30-word rule. The backend remains authoritative, while the frontend provides immediate feedback and disables invalid submissions.
Several smaller bugs became valuable lessons. A native form submission initially reloaded the single-page application when a bluff was sent; explicitly preventing the browser’s default submit behavior fixed the reset. I also made sure stale delayed events could not interrupt a later turn by attaching an expected game status and monotonically increasing  turnVersion  to every nudge. If the player has already acted, the delayed event becomes a safe no-op.

AWS services used and architecture overview

The application uses the following AWS services:
  • AWS Amplify Hosting hosts the compiled Angular single-page application from a manually uploaded ZIP file.
  • Amazon API Gateway WebSocket API maintains the real-time connection between the browser and backend.
  • AWS Lambda handles connections, routing, private reveals, AI orchestration, Host tools, and inactivity comments.
  • Amazon Bedrock Runtime Converse API runs the Host and Player 2 roles using an active Amazon Nova Pro inference profile.
  • Amazon DynamoDB stores public session state, connection mappings, resume-token hashes, and conversation history.
  • A separate DynamoDB table stores the private carrot assignment so public orchestration code cannot accidentally read it.
  • Amazon SQS provides delayed inactivity events, allowing the Host to comment without keeping a Lambda function running.
  • An SQS dead-letter queue captures repeatedly failing nudge events.
  • AWS Identity and Access Management (IAM) enforces least-privilege boundaries between functions.
  • Amazon CloudWatch Logs and AWS X-Ray tracing provide operational visibility into Lambda execution and asynchronous flows.
  • AWS CloudFormation through AWS SAM defines and deploys the complete backend infrastructure.

The backend uses explicit states such as  CREATING ,  AWAITING_PLAYER1_REVEAL ,  AWAITING_PLAYER1_BLUFF ,  PLAYER2_THINKING ,  AWAITING_PLAYER1_ANSWER ,  RESOLVING , and  COMPLETE . DynamoDB conditional updates prevent duplicate or stale requests from advancing the game twice.
Reconnection is supported without requiring a full authentication system for the prototype. The server returns a random resume token when a game starts, stores only its SHA-256 hash, and lets a new WebSocket connection resume an active session by presenting the original token. A production public release would add Amazon Cognito or a WebSocket Lambda authorizer.

What I learned

This challenge reinforced that an “agent” is an architectural behavior, not necessarily one managed service. By combining strong system prompts, filtered application-managed memory, structured JSON responses, Converse tool use, and deterministic backend validation, I created two clearly separated AI roles without giving either model uncontrolled access to infrastructure.
I also learned to choose orchestration based on interaction patterns. Step Functions is excellent for durable, known workflows, but an event-driven Lambda and DynamoDB state machine was simpler for a conversation that can pause at any moment. SQS delay messages were especially useful because they provide short inactivity timers without sleeping inside a Lambda invocation.
The project also deepened my understanding of WebSocket lifecycle management. A connection ID is temporary, while a game session must survive reconnects. Separating those identities, storing a hashed resume capability, and validating every state transition made the prototype much more reliable.
Finally, I learned how much presentation affects an AI experience. The one-second Host message cadence, notification sounds, visual box reveal, and short message limit turn a set of server events into a playful dramatic scene. The technical system produces responses, but timing and interface design make those responses feel like a game.

Try the app or view the source

Submission reminder: Replace the placeholder below with the public Amplify URL or public GitHub repository before publishing. The challenge requires a working link for the article to pass completeness review.
Any opinions in this article are those of the individual author and may not reflect the opinions of AWS.
Enjoyed reading this content? Let the author know!

Your likes, comments, shares, and saves help creators reach more builders.

Loading recommendations

Loading article