AI Novel Generator

A six-stage planning-to-prose pipeline that writes coherent novels, one published daily by GitHub Actions.

LLM / RAG2025All work

Fig. 01Storytelling agent: topic, model and creativity controls.
Storytelling agent: topic, model and creativity controls.

What it is

What it does

Long-form generation collapses without structure, so this agent never asks a model to 'write a novel'. It plans a book spec, forces a strict three-act chapter outline, breaks acts into scene specs, then writes scenes sequentially, each one conditioned on the last 400 words of the previous scene. A GitHub Action publishes a fresh novel to the repo every night at midnight IST.

Why it exists

I asked a model for a 30,000-word novel in one go and got a drifting, repetitive outline that forgot the main character's name. So I stopped asking for novels. I ask for specs, then outlines, then scenes, each with a format the code can actually check.

6
Pipeline stages
37k+
Words per novel
Daily
Auto-published

Repo Amit-kr26/Storytelling_agentDemo storytelling-agent.vercel.app/Stack FastAPI · Gemini · OpenAI · Claude · GitHub Actions

Build7decisions

How it is built

Six-stage pipeline

StoryAgent.generate_story() runs init_book_spec (nine fixed fields with a repair loop until none are empty) → enhance_book_spec (with old-field back-fill) → create_plot_chapters → enhance_plot_chapters → split_chapters_into_scenes → write_a_scene.

Parse-or-retry contracts

Outline stages must emit '**ACT I:** / - Chapter N:' blocks that plans.parse_text_plan() validates; failures re-query rather than degrade.

Scene-level continuity

Every scene prompt carries the previous scene cropped via utils.keep_last_n_words(text, 400), and an assistant prefill seeds '\nChapter {ch}, Scene {sc}\n' formatting.

Story-value rhythm

Act enhancement instructs alternating positive/negative story-value charge per chapter, stored as part of each nine-field scene spec.

Three interchangeable backends

openai / gemini / claude share one retry wrapper (3 tries, 5s sleep, 120s timeout, temperature 0.7, max_tokens 4096) with defaults gpt-4, gemini-2.0-flash and claude-3-5-sonnet.

Nightly automation

.github/workflows/daily_novel.yml triggers at 18:30 UTC (00:00 IST): main.py invents a random topic, generates the novel, and commits it to novels/ as '{Title}_{timestamp}.txt'.

Web + CLI

FastAPI/Jinja UI exposes topic, model picker and creativity sliders; the same package runs headless from main.py for CI.

How the pieces connect

Plan Write Topic supplied or random Book spec 9 fields, repaired Spec enhance more detail 3-act outline parse-or-retry Act enhancement value charge ± Scene specs 9 fields each Scene loop 400-word continuity Post-process headers stripped Novel .txt 37k+ words GitHub Actions commits, or the UI three acts, then nine-field scenes the last 400 words carry over