Skip to content

Repository files navigation

Auto-Graph

Autonomous AI writing orchestration platform that coordinates AI agents to produce complete long-form manuscripts — novels, novellas, short story collections, and non-fiction books — without human intervention.

It has shipped real books. Three complete novels (~255K words total) have come out of this pipeline end-to-end, plus non-fiction experiments. One is public: Every Good Child, a 103,751-word psychological thriller in 80 chapters — zero human-written prose, with the writer/editor/reviser loop visible in that repo's pull-request history. Two others are commercially published.

All people and companies named in the prompt files' few-shot examples are fictional.

Auto-Graph manages the full pipeline from premise to finished manuscript: outlining, chapter planning, prose writing, editorial review, revision, continuity checking, and final assembly. All prose lives in a GitHub repository as markdown files, with the platform managing the entire lifecycle through issues, branches, and pull requests.

How It Works

A user creates a "kickoff" issue on a (private) orchestration repo with a kickoff label and a YAML body containing the project configuration (premise, genre, style, word count targets, etc.). From there, the pipeline runs autonomously:

Kickoff Issue → Bootstrap Project → Create Repo → Generate Outline → Plan Chapters
    → Create Issues → Write Chapters (parallel batches) → Editorial Review
    → Revise (if needed) → Merge → Continuity Check → Next Chapters
    → Continuity Audit → Final Review

Each chapter goes through a writing loop:

  1. Writer agent drafts the chapter as a PR
  2. Word count gate validates compliance
  3. Editor agent reviews against editorial criteria
  4. If rejected: Reviser agent incorporates feedback (up to 5 rounds)
  5. If approved: PR is merged
  6. Continuity checker audits cross-chapter consistency
  7. Next chapter batch is triggered (respecting narrative dependencies)

Continuity state (character positions, timeline, plot threads, established facts) propagates forward across chapters to maintain narrative coherence at scale. Chapters can run in parallel where the planner's dependency DAG allows.

Architecture

AWS-native serverless architecture:

  • 15 Lambda handlers — one per pipeline stage, event-driven via SQS FIFO
  • 7 ECS Fargate workers — long-running Claude Code CLI tasks (outliner, planner, writer, editor, reviser, continuity-checker, auditor)
  • Step Functions — orchestrates async ECS polling without busy-wait
  • DynamoDB — 5 tables (projects, task-graphs, agent-runs, task-outputs, repo-locks)
  • SQS FIFO — work-item queue with per-project message grouping
  • API Gateway — GitHub webhook ingress
  • EventBridge — scheduled heartbeat sweep for stalled agent runs
packages/
  core/       # Shared library: config, DynamoDB services, GitHub client, prompts, queue, writing utilities
  lambdas/    # 15 Lambda handlers + integration tests
  worker/     # ECS worker entrypoint + 7 worker types (Docker)
  cdk/        # AWS CDK infrastructure stack (10 constructs)

Lambda Handlers

Handler Purpose
webhook API Gateway entry point — validates GitHub webhook signatures, parses kickoff YAML, routes events
bootstrap-project Creates project record in DynamoDB, comments on kickoff issue
bootstrap-repo Creates target GitHub repo with scaffolding (outline/, manuscript/ dirs)
generate-outline Launches outliner ECS task to produce master outline, character bible, world bible
plan-chapters Launches planner ECS task to build chapter dependency DAG
create-issues Creates GitHub issues per chapter from task graph, triggers first batch
trigger-chapter Acquires repo lock, loads continuity state, launches writer ECS task
reconcile Central state machine — polls ECS tasks, routes results to downstream handlers
review-chapter Launches editor ECS task with chapter content + continuity state
revise-chapter Launches reviser ECS task with editorial feedback
merge-chapter Validates merge readiness, squash-merges PR, closes issue, releases repo lock
continuity-check Launches continuity-checker ECS task, loads existing state from repo
trigger-next-chapter Finds ready nodes in dependency DAG, respects concurrency limit
continuity-audit Launches auditor ECS task for holistic full-book continuity audit after all chapters merge
final-review Tallies word counts, marks project complete

A reconcile-enqueuer (EventBridge schedule) runs every 5 minutes to detect stalled agent runs and re-enqueue them.

ECS Workers

Worker Purpose
outliner Generates master outline, character bible, world bible, and research notes from premise
planner Breaks outline into ordered chapter DAG with narrative dependencies
writer Drafts chapter prose as markdown, creates PR against main branch
editor Reviews chapter for voice, tone, continuity — posts APPROVED or CHANGES_REQUESTED review
reviser Incorporates editorial feedback, pushes revisions to same branch
continuity-checker Audits cross-chapter consistency, produces state delta and report
auditor Performs holistic full-book continuity audit across all chapters (120-min timeout)

Workers fetch system prompts from DynamoDB via RUN_ID and execute the Claude Code CLI. All workers run on 2 vCPU / 8 GB Fargate tasks.

Data Model

DynamoDB Table Purpose
projects Project config, status, word counts, repo reference
task-graphs Chapter dependency DAG with node statuses
agent-runs ECS task tracking (ARN, worker type, status, timing)
task-outputs System prompts and task artifacts
repo-locks Pessimistic locking for concurrent repo writes (with TTL)

Continuity State

The continuity system tracks four dimensions across chapters, stored in notes/continuity-state.json in the target repo:

  • Characters — name, aliases, location, status (alive/dead/unknown), last appearance, relationships
  • Timeline — events per chapter with time-of-day and day-number
  • Plot threads — named arcs (open/resolved/abandoned) with key events
  • World state — key-value map of locations, objects, and conditions

After each chapter merge, the continuity checker audits the chapter and produces a delta that is deterministically merged into the full state. The state is pruned (last 5 chapters of timeline/events) for the checker's prompt to manage token limits, but writers and editors receive the full state as context.

Continuity checking is non-blocking — issues are documented in notes/continuity-report-chapter-NN.md but don't gate pipeline progress.

After all chapters merge, a full-book continuity audit runs before final review. The auditor processes every chapter sequentially, building a cumulative world state and flagging long-range contradictions, unresolved plot threads, and accumulated drift that per-chapter checks can't catch. Results are compiled into notes/continuity-audit-report.md.

CDK Constructs

The infrastructure is composed of 10 CDK constructs:

Construct Resources
network VPC with public/private subnets, NAT Gateway
database 5 DynamoDB tables (on-demand, optimistic locking)
queue SQS FIFO queue with per-project message grouping
registry ECR repository for worker Docker images
secrets Secrets Manager (GitHub App key, Claude OAuth token, webhook secret)
compute ECS Fargate cluster with 6 task definitions
functions 14 Lambda functions with least-privilege IAM roles
api API Gateway HTTP API (POST /webhooks/github)
orchestration Step Functions state machine for ECS task polling
monitoring CloudWatch alarms, dashboards, log groups

Kickoff Configuration

Projects are configured via YAML in the kickoff issue body:

title: "The Last Algorithm"
premise: "An AI researcher discovers..."
genre: "science fiction"
projectType: novel              # novel | novella | short-story-collection | non-fiction
targetWordCount: 80000
chapterCount: 24
pov: third-limited              # first-person | third-limited | third-omniscient | multiple
style: "literary fiction with a focus on interiority"
styleReference: "Kazuo Ishiguro"
specialInstructions: "..."
config:
  chapterWordCountMin: 2500
  chapterWordCountMax: 4000
  chapterBatchSize: 3
  maxRevisionRounds: 5
  continuityCheckEnabled: true
  wordCountStrict: true

Tech Stack

  • Runtime: Node.js 22, TypeScript 5.x (strict mode, ESM)
  • Monorepo: pnpm workspaces
  • Cloud: AWS Lambda, ECS Fargate, DynamoDB, SQS FIFO, Step Functions, API Gateway, EventBridge, ECR
  • IaC: AWS CDK v2
  • AI Agent: Claude Code CLI
  • Testing: Vitest
  • Validation: Zod
  • GitHub: Octokit

Prerequisites

  • Node.js 22+
  • pnpm 9+
  • Docker (for worker image builds)
  • AWS CDK CLI (for deployment)
  • AWS credentials configured

Getting Started

# Install dependencies, build, typecheck, lint, and test
./bootstrap.sh

# Or manually:
pnpm install --frozen-lockfile
pnpm -r run build

Development

pnpm test                          # Run all tests
pnpm exec vitest --watch           # Watch mode
pnpm lint                          # Lint all packages
cd packages/cdk && cdk diff        # Preview infrastructure changes
cd packages/cdk && cdk deploy      # Deploy to AWS

CI/CD

GitHub Actions on push to main:

  1. Typechecktsc --noEmit across all packages
  2. Lint — ESLint across all packages
  3. Test — Vitest run
  4. Build — TypeScript compilation + Docker image build/push to ECR (tagged with git SHA)
  5. Deploycdk deploy to AWS

A weekly scheduled workflow rebuilds the worker Docker image every Monday to pick up the latest Claude Code CLI.

Documentation

Provenance

Auto-graph is a personal project (Feb–Jun 2026), and part of a flywheel: 31 of this repository's 158 commits were authored by dev-agents from my autonomous-SDLC platform (telos is its public successor) — one agent platform helping build another. The interesting parts are operational: consolidating 14 FIFO queues into a single dispatcher after back-pressure problems, phantom in-flight stall recovery, ordering enforcement so the writer can't outrun the planner, and a heartbeat sweep that reaps stalled agent runs.

License

MIT — see LICENSE. (Manuscripts produced by the pipeline are separate works and carry their own rights.)

About

Autonomous AI writing platform: a six-role agent pipeline (outline → plan → write → edit → revise → continuity-check) that ships complete novels as merged PRs. TypeScript + AWS CDK, ECS Fargate Claude Code workers. Wrote a 103K-word novel end-to-end.

Topics

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages