TL;DR
A production content pipeline splits work across a 5-stage swarm: trend scouting (cloud), story + visuals (cloud), local 9B critic that scores 5 axioms and rejects below 75, human gate, then local 12B thread writer. Four real failures—duplicate image URLs from cache leakage, leaked tokens, 1-char key mismatch in JSON scoring, and missing per-language URLs—were closed with explicit state clearing, double sanitizers, deterministic regex pre-filters, and multi-stage URL fallback. The resulting system runs 8-10 k token critiques for electricity cost only and ships daily without “AI smell.”
How It Actually Works
The swarm is deliberately heterogeneous. Heavy, repetitive, high-volume inference stays on local GPUs; lightweight but latency-sensitive or knowledge-heavy tasks go to cloud APIs. The concrete flow is:
- Stage 1 (Trend Scout): Cloud LLM with real-time search pulls current developer complaints, engagement numbers, and platform quirks.
- Stage 2 (Writer & Visuals): Cloud model produces story beats, full Japanese draft (~9 k chars), English translation, and two distinct cover illustrations. Prompting explicitly separates beat design from prose generation so pacing is decided before any sentence is written.
- Stage 3 (Critic-Agent): Local 9 B parameter distilled model receives the entire draft plus the last five published titles. It must output strict JSON with five keys: preachiness_score, consistency_score, physics_grounding, title_collision, overall. Threshold is hard-coded at 75; any axiom violation or parse error forces immediate rejection and retry. The model runs at 4-bit quantization on a consumer RTX card; a full critique costs roughly 0.8–1.1 kWh depending on ambient Bangkok temperature (33 °C raises fan power draw ~12 %).
- Stage 4 (PL Approval Gate): Human partner reviews the critic JSON and can override with an approval flag. This gate also triggers the deterministic checks.
- Stage 5 (Multi-Channel Deploy): Local 12 B model drafts the X thread. A separate deploy agent pushes Japanese main story, English version, technical note, and thread.
flowchart TD A[Trend Scout - Cloud] --> B[Writer + Visuals - Cloud] B --> C[Local 9B Critic 5 axioms + JSON] C -->|score < 75 or parse fail| Retry C --> D[Deterministic Regex Guards # + digit, forbidden tokens] D --> E[Human PL Gate] E --> F[Local 12B Thread Writer] F --> G[Double Sanitizer <image|>, <think>, EOS] G --> H[Multi-URL Fallback RSS + metadata + scrape] Image deduplication is enforced at three layers. After upload, the pipeline stores each image’s CDN URL in a per-run set. Before the second image is requested it asserts the new URL is not already present. After publication the scraper downloads both images again, computes perceptual hashes (dHash), and aborts the run if distance < 3. This caught the Episode 099 cache-leak bug where the first URL was never removed from the in-memory working set.
Control-token leakage is fought with a two-pass sanitizer written in Rust. The first pass runs before any cloud API call and strips every token present in the model’s tokenizer vocabulary that is not in the printable Unicode range. The second pass runs immediately before HTTP POST and uses a regex compiled from the model card’s special token list. In practice the double pass reduces leakage from ~0.8 % of generations to < 0.01 % across 400+ runs.
The critic’s JSON key bug was a classic string mismatch: prompt defined “preachiness_and_coherence” while the validator read “preach”. The fix was to generate the expected key list from the same constant used in the prompt, then use struct tags for deserialization. Any unknown or missing key now forces a hard reject instead of the previous “fallback 75” logic.
Multi-language URL recovery uses four ordered sources: (1) platform metadata response, (2) RSS feed entry, (3) og:url meta tag scrape, (4) sitemap lookup. Each source is tried with its own timeout; the first valid per-language slug wins. This eliminated the top-of-site fallback that previously occurred on ~7 % of English posts.
All four fixes are covered by deterministic unit tests that replay the exact failing payloads from Episode 099. The test suite runs in < 4 s on CI and is required before any deploy.
Failure Modes & Engineering Trade-Offs
Local 9 B critics are fast and cheap but their 4-bit quantization occasionally produces malformed JSON (~3 % of runs). The pipeline therefore treats every parse error as a reject; there is no “best effort” scoring path. This increases retry count but keeps bad content out.
Temperature in Bangkok directly affects sustained token rate. At 33 °C the GPU throttle limit drops effective throughput by ~18 % versus 25 °C lab conditions. The team now schedules heavy critique batches after sunset or under the air-con duct.
Duplicate-image assertions add 400–600 ms of latency and require network calls to the CDN after publish. The trade-off is acceptable because the pipeline runs once per day; the extra safety eliminated the single worst class of reader complaints.
The deterministic regex layer is brittle to new platform rules. When one platform started auto-linking #123 patterns, the regex had to be updated within 24 h. Keeping the regex list in version control and tied to integration tests is mandatory.
Human gate latency is the largest variable. The current median approval time is 11 min; during peak writing streaks this creates queue pressure on the local GPU. Future work plans to add a secondary 7 B “pre-critic” that can surface the three most likely failure modes before the human sees the piece.
What's Your Take?
- What deterministic guard would you add first if you were running a daily local-LLM content swarm—image hash check, token blacklist, or JSON schema enforcement?
- At what point does the cost of extra safety layers (retry loops, double sanitizers, post-publish scrapers) outweigh the benefit of fully autonomous publishing?
This deep-dive unpacks the real-world engineering behind the speculative cyberpunk short story on Substack (https://sofiworks.substack.com/p/local-ai-spawns-100-sf-novels-but) (Japanese original on Note).
Disclaimer: Technical scenarios and architecture notes are presented for engineering education and speculative fiction world-building.