AWS Builder Center
Weekend Creative Agent Challenge: PlotTwist Autopilot

Weekend Creative Agent Challenge: PlotTwist Autopilot

I turned my interactive PlotTwist storytelling app into an always-on autonomous story agent using Amazon EventBridge Scheduler, AWS Lambda, Amazon Bedrock, DynamoDB, API Gateway, and AWS Amplify. PlotTwist Autopilot now keeps writing stories even when nobody is using the website.

AWS Student Builder Group Leader at University of Jaffna

From Interactive Storytelling to an Always-On Agent

Last weekend, I built PlotTwist, an interactive branching storytelling application where every decision changes what happens next.
The original version focused on user-driven storytelling. A user selected a genre, created a character, made choices, and followed the story through different branches and endings.
For this weekend's AWS Creative Agent Challenge, I wanted to take that idea one step further.
Instead of waiting for someone to open the app and start a story, I asked a different question:
What if PlotTwist could keep writing even when nobody was there?
That became PlotTwist Autopilot, an autonomous storytelling agent that generates new stories on a schedule and keeps them ready for the next time a user visits.
The core idea is simple:
PlotTwist does not wait for the user anymore. It keeps writing while the user is away.



Vision and What It Does

PlotTwist Autopilot is an always-on creative story agent.
The original PlotTwist still allows users to create interactive branching adventures. Autopilot adds a completely separate experience where stories are generated automatically in the background.
A user can close the website, return later, open the Autopilot section, and discover stories that were created while they were away.
The autonomous agent also changes its creative direction depending on the time of day.
Morning generations lean towards exploration, adventure, and discovery. Afternoon stories can become more action-driven or science-fiction focused. Evening stories favour fantasy, mystery, and drama, while late-night generations can move towards horror, supernatural fiction, or darker themes.
This allows the agent to do more than simply send the same prompt to an AI model every few hours. It creates a small creative context before every generation.
The frontend also includes an Agent Overview showing its current status, the most recent generation, the number of autonomous stories created, and the current schedule.
Another feature is While You Were Away. The browser remembers the user's previous visit time and compares it with the timestamps of stories returned by the API. If new stories were created after the user's last visit, PlotTwist can tell them exactly how many appeared while they were gone.



How I Built It

I reused my existing  plottwist-ai  repository instead of rebuilding the project from scratch.
However, I did not want this challenge experiment to affect the existing PlotTwist deployment.
I created a separate Git branch called:
 weekend-creative-challenge 
The existing  main  branch remains connected to the original PlotTwist application, while the challenge branch is deployed through a completely separate AWS Amplify application.
This gave me a safe way to evolve the project while keeping the original live application untouched.

Architecture

The autonomous flow is:
Architecture

The most important part of this architecture is where the process starts.
It does not start in React.
It starts with Amazon EventBridge Scheduler.
That means the website does not need to be open for a story to be created.



Building the Autonomous Story Agent

The backend agent is written in TypeScript running on AWS Lambda.
Every scheduled execution first determines the current time in the  Asia/Colombo  timezone.
From that time period, it creates a randomised creative brief containing details such as the genre, setting, characters, conflict, theme, tone, and direction of the plot twist.
For example, the agent might create a brief based on a science-fiction story in the afternoon, while a late-night execution might favour something darker and more mysterious.
Once the creative brief is ready, Lambda sends it to Amazon Bedrock.
I used the Bedrock Runtime Converse API with an Amazon Nova model for the final creative generation.
The model is instructed to return structured JSON containing the story title, genre, theme, setting, summary, full story, plot twist, and tone.



Making AI Output Reliable

One challenge with generated content is that a model does not always return output in exactly the structure an application expects.
Because of that, I did not save Bedrock responses directly into the database.
The agent first parses and validates the response.
It checks that all required fields exist and also handles cases where JSON is returned inside Markdown code fences.
If the output is malformed or incomplete, the generation is treated as a failure rather than being saved as a completed story.
This made the pipeline much safer.



Preventing Duplicate Stories

Scheduled systems also need to handle retries.
A Lambda invocation may be retried after a temporary problem, but I did not want one scheduled execution to accidentally create the same story twice.
To solve this, every scheduled generation receives a  generationKey  based on its generation window.
When the agent writes the story to Amazon DynamoDB, it uses conditional logic to prevent another item with the same generation key from being stored.
This gave the autonomous workflow simple idempotency protection.
The DynamoDB table uses on-demand capacity and also includes an index that allows autonomous stories to be retrieved in generation-time order.



Creating the API

I created a separate Lambda API behind Amazon API Gateway.
The frontend can request:
GET /health
GET /stories
GET /stories/latest
GET /stories/{id}
GET /agent/status

The frontend never receives AWS credentials.
It only communicates with the HTTP API.
During deployment, I also encountered an API routing issue caused by the API Gateway stage prefix. The  /challenge  prefix was reaching the Lambda router and preventing some routes from matching correctly.
I fixed this by normalising the incoming API path before routing it.
CORS configuration was another important part of the deployment because the new Amplify frontend and API Gateway are hosted separately.



The Autopilot Experience

I wanted the autonomous functionality to be obvious when someone opened the app.
Instead of hiding it inside the original story generator, I added a dedicated Autopilot section.
Home Page

The existing Create Story experience remains available.
Selecting Autopilot opens a different dashboard.
Autopilot

This page contains recent autonomous stories and an Agent Overview.
Each autonomous story includes its genre, theme, generated time, summary, time period, and a button to open the complete story.
The page is intentionally designed to feel like an extension of PlotTwist rather than a completely different application.



AWS Services Used

The final challenge architecture uses Amazon EventBridge Scheduler for autonomous execution, AWS Lambda for story generation and the API, Amazon Bedrock with Amazon Nova for creative generation, Amazon DynamoDB for story storage, Amazon API Gateway for the public API, Amazon CloudWatch for execution logs and evidence, and AWS Amplify Hosting for the React and TypeScript frontend.
I used AWS SAM to define the backend infrastructure so the challenge resources can be deployed as their own isolated stack.
All challenge resources use separate names and are independent from the original PlotTwist deployment.



Proving That It Really Runs on Its Own

For me, this was the most important part of the challenge.
Simply adding a "Generate with AI" button would not make PlotTwist an always-on agent.
The actual workflow is:
Nobody is using PlotTwist
↓
EventBridge reaches its scheduled time
↓
Lambda starts automatically
↓
A creative brief is generated
↓
Amazon Bedrock creates the story
↓
The result is validated
↓
DynamoDB stores the story
↓
The user returns later
↓
The story is already waiting

CloudWatch logs provide evidence of each generation with events such as:
AUTONOMOUS_GENERATION_STARTED
CREATIVE_BRIEF_CREATED
BEDROCK_GENERATION_SUCCESS
STORY_VALIDATION_SUCCESS
STORY_SAVED
AUTONOMOUS_GENERATION_COMPLETED

The timestamps in CloudWatch and DynamoDB make it possible to show that the generation happened independently of the frontend.



What I Learned

The biggest lesson from this project was that turning a normal application into an agent is not only about adding an AI model.
The more interesting work happens around the model.
I had to think about scheduling, retries, validation, idempotency, storage, API design, timezones, CORS, deployment isolation, and how the frontend should explain autonomous behaviour to the user.
I also learned that an autonomous application needs to make its state visible.
Features such as Agent Overview, timestamps, autonomous story labels, and While You Were Away are not only UI features. They help users understand that something has been happening in the background without them.
The original PlotTwist was built around this idea:
Every choice creates a different story.
PlotTwist Autopilot adds another idea:
Even when nobody is choosing, the stories can continue.



Try It and Explore the Code

The original PlotTwist remains on  main , while PlotTwist Autopilot runs separately from the challenge branch.
That allowed me to take an existing creative app, set it free, and turn it into something that keeps creating even after I close the browser.
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