Inspiration
The AI Storytelling Game was inspired by a passion for merging classic tabletop role-playing games (TTRPGs) like Dungeons & Dragons with cutting-edge AI technology. We wanted to create an immersive, accessible storytelling experience that captures the magic of collaborative narrative-building without requiring a human Dungeon Master. The advent of powerful AI models like Claude 3 on Amazon Bedrock, combined with AWS's scalable infrastructure, sparked the idea to build a dynamic, interactive fantasy adventure that could be enjoyed solo or showcased at hackathons. Our goal was to democratize storytelling, making it engaging for gamers, developers, and AWS enthusiasts alike, while demonstrating the potential of AI-driven creativity in a serverless, cloud-native environment.
What it does
The AI Storytelling Game is an interactive fantasy adventure where players embark on dynamic, AI-generated quests through a chat-based interface. Powered by Amazon Bedrock (Claude 3), the game acts as an AI Dungeon Master, crafting rich, context-aware storylines based on player inputs. Key features include:
Dynamic Storytelling: Players type actions or dialogue, and the AI responds with evolving narratives, NPCs, and world events. Character Management: Tracks player stats (health, mana, level, experience) and inventory, stored in DynamoDB for session persistence. Dice Rolling System: Supports D4, D6, D8, D10, D12, D20, and D100 dice rolls for skill checks, combat, and random events, adding unpredictability. Responsive UI: A React-based frontend, hosted on Amplify, ensures a seamless experience on desktop and mobile. AWS Integration: Leverages Lambda, API Gateway, DynamoDB, and Bedrock for a scalable, serverless architecture.
Players can start new adventures, engage in real-time chats with the AI, roll dice for outcomes, and explore branching storylines, all while showcasing AWS's capabilities in a fun, gamified format.
How we built it
We built the AI Storytelling Game using a serverless, cloud-native architecture on AWS, combined with a modern frontend stack. Here's the breakdown:
Frontend: Developed a React application hosted on AWS Amplify, featuring a chat interface, game stats display, and dice roller components. The UI is responsive, styled with CSS, and uses a GameContext for state management. Backend: Built a Lambda function (Python) to handle game logic, process player inputs, and manage dice rolls. The function integrates with Amazon Bedrock (Claude 3) for AI-driven storytelling and DynamoDB for session persistence. API: Used API Gateway to create a RESTful endpoint (POST /story) for communication between the frontend and backend, handling actions like starting a game, chatting, or rolling dice. Storage: DynamoDB stores game state, including player stats, inventory, and session data, ensuring continuity across sessions. Deployment: Leveraged AWS SAM CLI for backend deployment (Lambda, API Gateway, DynamoDB) and Amplify CLI for frontend hosting. The SAM template defined the infrastructure, while Amplify streamlined the frontend build and deployment process. AI: Utilized Amazon Bedrock's Claude 3 model to generate dynamic, context-aware story responses, enabling rich NPC interactions and branching narratives.
The project was structured for modularity, with clear separation between frontend (frontend/ directory) and backend (lambda_function.py, template.yaml). We followed best practices for security (CORS, input validation) and performance (optimized Lambda timeout, CDN caching).
Challenges we ran into
Building the AI Storytelling Game came with several challenges:
AI Response Consistency: Ensuring Claude 3 generated coherent, contextually relevant story responses required careful prompt engineering and handling of session context to maintain narrative continuity. Session Persistence: Designing a robust system to save and retrieve game state in DynamoDB was tricky, especially handling concurrent updates and ensuring data consistency across sessions. Dice System Integration: Implementing a dice-rolling system that felt natural within the AI-driven narrative required balancing randomness with meaningful outcomes (e.g., critical successes/failures). CORS and API Issues: Configuring API Gateway for CORS to allow seamless frontend-backend communication was initially problematic, requiring precise settings in the SAM template. Performance Optimization: Managing Lambda cold starts and Bedrock response times to keep the game responsive was challenging, especially for real-time chat interactions. Learning Curve: For team members new to AWS services like Bedrock or SAM, there was a steep learning curve in understanding service limits, IAM permissions, and deployment workflows.
We overcame these by iterating on prompt designs, using DynamoDB's conditional writes, fine-tuning CORS settings, and leveraging AWS documentation and community resources.
Accomplishments that we're proud of
We're thrilled with several achievements in the AI Storytelling Game:
Seamless AI Integration: Successfully harnessed Claude 3 via Amazon Bedrock to create immersive, dynamic narratives that feel like a real TTRPG experience. Scalable Architecture: Built a fully serverless, cost-efficient system using Lambda, API Gateway, DynamoDB, and Amplify, demonstrating AWS's power for hackathon projects. Engaging Gameplay: Developed a polished, responsive UI with real-time chat, dice rolling, and stat tracking, making the game accessible and fun for all users. Session Persistence: Implemented robust state management with DynamoDB, allowing players to pause and resume adventures without losing progress. Hackathon-Ready Demo: Created a compelling demo (as seen in the YouTube video) that showcases both the game's creativity and AWS's technical capabilities. Community Focus: Designed the project to be open-source (MIT License), encouraging contributions and inspiring other developers to build on AWS.
What we learned
The development process taught us valuable lessons:
AI Prompt Engineering: Crafting effective prompts for Claude 3 to balance creativity and coherence was critical for storytelling quality. AWS Ecosystem: Gained hands-on experience with Bedrock, SAM, Amplify, and DynamoDB, deepening our understanding of serverless architectures and IAM permissions. State Management: Learned to design scalable, persistent state systems using DynamoDB, handling edge cases like session conflicts. Frontend-Backend Integration: Mastered secure API communication with API Gateway, including CORS and input validation, to ensure a smooth user experience. Team Collaboration: Coordinated across frontend, backend, and AI components under tight hackathon timelines, improving our agile development and testing skills. Performance Tuning: Discovered strategies to optimize Lambda performance and reduce latency, such as minimizing cold starts and caching responses.
What's next for AI agent - Story Telling Game
The AI Storytelling Game has exciting potential for growth. Our roadmap includes:
Multiplayer Support: Enable collaborative adventures where multiple players can join the same session, interacting with the AI and each other. Character Customization: Allow players to create detailed characters with custom names, classes, and backstories, enhancing personalization. Save/Load Multiple Games: Support multiple save slots per user, letting players explore different storylines simultaneously. Voice Input/Output: Integrate Amazon Polly for text-to-speech and voice input for a hands-free experience, leveraging Grok's voice mode as inspiration (available on iOS/Android apps). Image Generation: Add AI-generated scene visuals using future Bedrock capabilities or other AWS-compatible tools (pending user confirmation for image generation). Advanced Combat System: Expand the dice system with detailed combat mechanics, status effects, and enemy stats. Quest Tracking: Implement a quest log to track objectives, rewards, and progress, enhancing the RPG experience. Achievement System: Introduce achievements and badges to reward creative choices, milestones, or dice roll outcomes. Global Deployment: Optimize for multi-region deployment to reduce latency and improve accessibility for a global audience.
We also plan to refine the UI, enhance NPC memory for deeper interactions, and engage the AWS community by showcasing the game at more hackathons and events.
Log in or sign up for Devpost to join the conversation.