BookGenerator AI is an open-source, production-grade multi-agent engine engineered to solve the hardest challenge in generative AI: autonomously drafting complete, publication-ready 300-page commercial manuscripts (80,000+ words) without context collapse or prose degradation.
Standard LLM wrappers fail catastrophically when tasked with long-form writing:
- Context degradation & Token Exhaustion: Context windows overflow around 2,000–4,000 words, causing models to forget previous character developments, plot arcs, and established world constraints.
- Repetitive Tropes ("AI Slop"): Models default to repetitive filler phrases ("a testament to", "tapestry of", "shivers down her spine", "a palpable tension") and forced moralizing summary conclusions.
- Hallucinatory Drift: Without strict state isolation, characters swap voice patterns, break world rules, or solve major plot points prematurely.
BookGeneratorAI implements an enterprise-grade multi-agent architecture featuring:
- Hierarchical State Isolation: The drafting agent receives only the current scene micro-beat, active character voice fingerprints, and a 1,200-word rolling memory summary—never the full 80,000-word history.
- Beat-by-Beat Iterative Scene Generator: Chapters are decomposed into 6 sub-beats (600–900 words each), guaranteeing rich sensory grounding and avoiding model context ceilings.
- Adversarial Anti-Slop & Continuity Critics: An independent reviewer agent audits every drafted chapter against banned tropes and character voice fingerprints, issuing mandatory revision briefs before state commitment.
Standard LLMs default to generic clichés and preachy summary endings. BookGeneratorAI's AntiSlopEditorAgent actively intercepts and rewrites prose:
- RAW UNCHECKED OLLAMA PROSE:
- "The quiet night was a testament to their unshakeable bond. Shivers ran down Clara's spine as a palpable tension filled the courtyard. Little did they know, their journey had only just begun. In conclusion, they learned that love conquers all."
+ ADVERSARIAL CRITIC REFINED PROSE:
+ "The courtyard fell quiet under the cold starlight. Clara gripped the stone archway, her knuckles pale against the damp granite. Julian didn't step back; he closed the distance between them until his breathing matched her own." ┌─────────────────────────┐
│ User Seed Concept │
└────────────┬────────────┘
│
┌────────────────────┴────────────────────┐
▼ ▼
┌───────────────────────┐ ┌───────────────────────┐
│ World Builder Agent │ │ Character Architect │
│ (Rules & Bible) │ │ (Voice Fingerprints) │
└───────────┬───────────┘ └───────────┬───────────┘
│ │
└────────────────────┬────────────────────┘
▼
┌─────────────────────────┐
│ Master Outliner Agent │
│ (4-Part, 12 Chapters) │
└────────────┬────────────┘
│
▼
┌─────────────────────────────────────────────────────────────────────────┐
│ Iterative Execution Loop │
│ │
│ ┌─────────────────────────┐ ┌───────────────────────────┐ │
│ │ Prose Drafter Agent │────────────>│ Adversarial Critic Loop │ │
│ │ (Beat-by-Beat Scene) │ │ (Continuity & Anti-Slop) │ │
│ └─────────────────────────┘ └─────────────┬─────────────┘ │
│ ▲ │ │
│ │ Revision Directive │ │
│ └────────────────────────────────────────┘ │
│ │ │
│ Approved │ │
│ ▼ │ │
│ ┌───────────────────────────┐ │ │
│ │ State Memory Engine │ │ │
│ │ (Rolling Memory Update) │ │ │
│ └───────────────────────────┘ │ │
└────────────────────────────────────┬────────────────────────────────────┘
│
▼
┌─────────────────────────┐
│ Commercial DOCX Bridge │
│ (Dynamic TOC & Index) │
└─────────────────────────┘
Reasoning models like DeepSeek-R1 output extensive inner-monologue reasoning blocks (<think>...</think>) before generating response content. LlmClient._clean_llm_output() implements a robust multi-pass regex filter (re.DOTALL) that strips reasoning traces, conversational preambles ("Okay, let's write..."), and prompt meta-leakage without corrupting structured JSON schemas or Markdown prose headings.
To protect long-running generations (which can take 30–60 minutes locally), all intermediate states—WorldBible, CharacterRegistry, MasterOutline, chapter drafts, and critic revision briefs—are persisted transactionally to SQLite (memory/book_state.db). Interrupted runs can resume instantly without re-generating prior chapters.
To prevent infinite revision loops when an LLM struggles with a complex constraint, MasterAdversarialReviewer enforces strict revision bounds (max-revisions, default 1–2 passes). If a draft fails audit after max attempts, the system logs the residual warnings, applies non-blocking text cleanup, and safely advances state.
Ensure Python 3.10+ and Ollama are installed.
git clone https://github.com/apravint/BookGeneratorAI.git
cd BookGeneratorAI
pip install -r requirements.txtEnsure your target model is pulled in Ollama (e.g. DeepSeek-R1):
ollama pull deepseek-r1:latestpython3 main.py \
--title "The Love Story" \
--genre fiction \
--author "Pravin Tamilan" \
--provider ollama \
--model "deepseek-r1:latest" \
--reset \
--output "The_Love_Story.docx"python3 main.py \
--title "Building Distributed Stream Engines" \
--genre technical \
--author "Pravin Tamilan" \
--provider ollama \
--model "deepseek-r1:latest" \
--reset \
--output "Distributed_Streams.docx"export OPENAI_API_KEY="your-api-key"
python3 main.py \
--title "The Exponential Leader" \
--genre business \
--author "Pravin Tamilan" \
--provider openai \
--model "gpt-4o" \
--output "Exponential_Leader.docx"| Flag | Short | Default | Description |
|---|---|---|---|
--title |
-t |
Required | Book title |
--concept |
-c |
"" |
Seed concept or story prompt |
--language |
-l |
english |
Primary language (tamil / english) |
--tamil |
False |
Preset flag for Tamil language book generation | |
--genre |
-g |
auto |
Genre (tamil_historical, tamil_thirukkural, tamil_kavithai, tamil_fiction, fiction, business) |
--author |
-a |
Pravin Tamilan |
Author name for title page & headers |
--provider |
-p |
ollama |
Provider (ollama, gemini, openai, anthropic, jev) |
--model |
-m |
deepseek-r1:latest |
Target LLM model |
--ollama-url |
http://localhost:11434 |
Local Ollama REST endpoint | |
--reset |
-r |
False |
Clean database (memory/book_state.db) & previous outputs before running |
--max-revisions |
1 |
Max critic revision loops per chapter | |
--output |
-o |
Generated_Book.docx |
Output path for .docx compilation |
Run a modern, multi-tab Streamlit dashboard:
pip install -r requirements.txt
streamlit run streamlit_app.pyLaunch at
http://localhost:8501to generate books, monitor live pipeline execution, read chapters, and download DOCX files.
Run a zero-dependency local REST API web server:
python3 server.pyAccess at
http://localhost:8080for live 5-node agent pipeline monitoring and multi-book job creation.
We are actively expanding BookGenerator AI into an enterprise-grade manuscript generation platform:
- Phase 1 (Current Engine): Multi-agent beat-by-beat scene drafting, context isolation, adversarial anti-slop critics, and local Ollama REST integration.
- Phase 2 (Semantic Vector Memory & MCP Server): Local vector memory (ChromaDB / FAISS) and a native Model Context Protocol (MCP) server interface for IDE/agent integration.
- Phase 3 (Enterprise UI & Streaming): Web-based authoring dashboard (Angular) powered by real-time event streaming (Apache Kafka / IBM MQ) for multi-user generation jobs.
- Phase 4 (Enterprise Persistence & Multi-Format Exporters): Oracle DB enterprise state persistence alongside native
.epuband publication-ready.pdfcompilers.
This repository follows modern AI contribution standards.
- Human Contributors: Please review
CONTRIBUTING.mdfor local setup, fast single-chapter test flags, and PR guidelines. - Autonomous AI Agents: Please inspect
AGENTS.mdfor operational boundaries, mandatory verification commands, and safety rules.
Distributed under the MIT License. See LICENSE for details.
Pravin Tamilan
Vice President & Lead AI Systems Architect — Chennai, India
Pravin is a technology leader specializing in agentic AI orchestration, Model Context Protocol (MCP) tool design, distributed microservices, and enterprise Spring Boot & Angular architectures.
- GitHub: @apravint
- Specialization: Enterprise AI Architecture, Multi-Agent Systems, Local Inference Engineering, High-Throughput Stream Processing.