My AI-Powered Novel-Writing Pipeline: Book-Agent – Generating Epistemically Controlled Long-Form Fiction

Hello everyone on Level1Techs. Lets try this again since my first post violated AI rule. My project is Book-Agent which is fully automated AI-agent pipeline for generating complete books using LLMs. This is not just straightforward text generation but I have built sophisticated, multi-phase system that’s designed to produce structurally sound high-quality books. It has a strict epistemology control with planned revelation schedule for facts and clues. It aims to have a good narrative consistency, rhetorical quality, and stylistic integrity.

Basic idea is to turn user prompt (e.g. “a cyberpunk novel about a hacker in 2077”) into a full book. It’s genre-agnostic and should be able to adapt different genres. It has all kinds of mechanisms to prevent repetition or narrative collapse.

What I’ve Built So Far

I have built this for about a month now and it’s capable of generating entire books reliably but it still has room to improve. The pipeline is modular with different phases that handle decomposition, classification, world modeling, character creation, knowledge inventory, secrecy stratification, clue generation, revelation scheduling, structural mapping, plot thread management, prose generation, and epistemic QA. Here’s a high-level breakdown:

Key Technical Components

  • book_state.json: is the structure that is the source of truth and holds the whole project data. This allows recovery from interrupts and adding manual tweaks.
  • Phased Architecture (each step in phases/ directory):
    • Prompt Decomposition (Phase 1): Breaks down user prompt and categorizes genre signals, constraints, world facts, characters, and themes.
    • Narrative Classification (Phase 2): Determines primary genre, modifiers, and revelation mode (t.g. “slow-burn mystery” vs. “immediate action”).
    • Book Title Generation (Phase 2.5): Generates unique title that respects our epistemic guidelines and doesn’t reveal our secrets but might hint something.
    • World Model (Phase 3): Builds rules, entities, and causal constraints to maintain consistency.
    • Character Initialization (Phase 4): Creates characters with epistemic states (what they know, don’t know, or falsely believe).
    • Knowledge Inventory (Phase 5): Catalogs all plot-critical info as items.
    • Secrecy Classification & Clues (Phases 6-6.5): Batches knowledge into secrecy levels (public, hidden, delayed, never_explicit) and generates ambiguous clues.
    • Revelation Scheduling (Phase 7): Plans multi-step reveals across chapters to build tension without spoilers.
    • Structural Mapping & Plot Threads (Phases 8-8.5): Defines narrative skeleton (acts, beats), assigns POVs, and manages multiple plot threads with advancement guidelines.
    • Prose Generation (Phase 9): Multi-pass drafting with style memory (Prose Consistency Layer – PCL) using vector embeddings and syntactic checks to enforce consistency and avoid repetition.
    • Epistemic QA (Phase 10): Rhetorical QA Engine (RQE) flags issues like repetition, ensures sensory details, parallelism, and more. This step also guards against leaked secrets and logical inconsistencies.
  • Style and Anti-Repetition Safeguards:
    • Prose Consistency Layer (PCL): Vector-based style memory + syntactic analysis to detect repetition. Each written chapter is stored to vector database and all newly written chapters are compared against previous content.
    • Rotating Opener Templates: Breaks LLM tendency to start chapters similar way. We inject rotating instructions in prompt to guide LLM to start chapters in varying ways.
    • Entropy Injection: Analyzes previous chapter and provides 2-3 lines of instructions to prevent repetition and stagination.
    • Motif Collection with Cooldown: Tracks recurring motifs (e.g., “rain as metaphor”) and enforces cooldown periods to avoid overuse.
    • Ban Filter: Filters overused words.
  • Services Layer:
    • LLMService: provides unified interface for different LLM APIs. It can use LM Studio’s REST API or any of the big providers like: Gemini, Clause, ChatGPT, Grok.
    • LoggingService: Logs the whole process and provides statistics from token usage and request times.
    • WriterService: Handles draft generation with triple-layer context where information is limited to different scopes: global, reader, character to prevent epistemic leaks.

Process entry point is main.py and the whole operation is orchestrated by BookProject-class in book_project.py.

Example Book: “Silence Within the Grid” (Sci-Fi Thriller):

Get the whole book in: PDF, EPUB, MD, TXT


What I Want to Do Next with the R9700

I currently run this mostly locally on LM Studio’s REST API with my 2080TI (11GB VRAM) but I have experimented with “big boy models”, like Gemini API is not too expensive to use sometimes. I have tried to minimize token usage on paid APIs by running some of the steps locally, like QA for example.

My current model of choice is gpt-oss-20b-MXFP4.gguf which can follow instructions, produce structured JSON output while still produce decent prose. Qwen3-30B-A3B-Instruct-2507-Q4_K_M.gguf is good model that can (barely) run on my machine but it is a terrible writer and repeats certain structures a lot, like “Not X, But Y”, for example. This model allowed me to develop my Rhetorical QA Engine to mitigate against that type of problem. With my current setup one book can take up to 21-48 hours to generate depending of its length.

R9700 and its 128GB VRAM would be a game-changer for me and my project. It would allow me to improve my character, item and relationship tracking for one which is next problem to tackle but my prompts are getting pretty stuffed already.

I would love to use larger models and with better quantization. That would allow me to increase complexity and produce better books. Speedup would also be very welcome too but memory and model restrictions are the biggest bottle neck for quality. It would also allow me to dive deep into fine-tuning and LoRA training to improve quality.

Thanks for considering my project, and happy holidays to the Level1 crew! If I win, I’ll document the integration here. Thanks for reading – excited to hear thoughts from the community!

So the project’s to finish automating systematically going against the spirit of rule 13 at novel length. Interesting approach to developing a winning proposal.

ERR_SSL_PROTOCOL_ERROR

1 Like

Oh, I was not aware of that rule. I probably should have. I definitely used LLM to construct that post and build that presentation from my PROJECT_CONTEXT.md. Perhaps I need to rewrite the whole thing. Thanks for letting me know.

ERR_SSL_PROTOCOL_ERROR

As far as I understand, the server should work just fine but it has somewhat limited TLS support (TLS 1.3 and TLS 1.2 with No-SNI fallback) and that error is probably because of "Experimental: Server negotiated using No-SNI”.

TLS 1.3     Yes
TLS 1.2     Yes*
TLS 1.1     No
TLS 1.0     No
SSL 3   No
SSL 2   No
(*) Experimental: Server negotiated using No-SNI