From a single sentence to a fully branded newsletter in my inbox. Here is the breakdown of the AI newsletter system I built, how it works under the hood, and the technical hurdles solved along the way. The Architecture: Workflows, Agent, Tools The system separates logic, orchestration, and execution into three distinct layers: 1. Workflows: Markdown SOPs outlining explicit execution instructions, guardrails, and known pitfalls for the agent. 2. Agent: Claude Code acts as the orchestrator, deciding which tools to call and evaluating output quality. 3. Tools: Three focused Python scripts handling image generation, HTML compilation, and email delivery. When an edge case or error occurs, the fix is documented directly back into the workflow instructions, preventing repeat failures. Step-by-Step Pipeline 1. Primary-Source Research 2. The agent queries the web and filters strictly for primary research data (e.g., AMA, JAMA Network Open, Menlo Ventures, Oliver Wyman), automatically discarding secondary vendor-blog claims. 3. Structured Content Generation 4. The draft is emitted as structured JSON containing the subject line, preheader, hook, three verified metrics, three core sections, an Effort vs. Impact matrix, key takeaways, and source citations. 5. Parallel Infographic Generation 6. Using the Gemini API (Nano Banana 2), four visuals are generated concurrently (one hero banner and three infographics) aligned with custom brand colors. 7. Email-Safe HTML Assembly 8. A Python build script converts the JSON and assets into inline-CSS, table-based HTML optimized for Gmail rendering, including custom stat cards and styled matrix blocks. 9. Human-in-the-Loop Gate 10. A local preview file is generated for manual review. No email is dispatched without explicit approval. 11. Multipart SMTP Delivery 12. The approved email is transmitted via Gmail SMTP with embedded CID images so assets display reliably without being blocked or clipped. Key Engineering Challenges and Fixes