An End-to-End Autonomous & Human-in-the-Loop AI Agent Platform Powered by LangGraph, Google Gemini, Tavily Web Search & Next.js
The Newsletter Agent is a full-stack, monorepo-based autonomous AI agent application engineered to research, curate, summarize, evaluate, and publish weekly tech digests. Built with an 8-Node LangGraph Agent Graph, it transforms raw user topics or prompt goals into polished, publication-ready newsletters with live execution streaming over Server-Sent Events (SSE) and real email delivery via the Resend API.
- π§ Autonomous & Human-in-the-Loop Modes:
- Autonomous: Executes all 8 graph nodes end-to-end automatically.
- Human-in-the-Loop: Intercepts workflow execution at key stages, allowing users to review retrieved articles/summaries before proceeding.
- π‘ Real-Time SSE Execution Log Stream:
- Live event-driven progress updates streamed directly from the backend LangGraph engine using Server-Sent Events (
text/event-stream). - Expandable stage cards displaying retrieved web search results, top ranked stories, summary takeaways, quality critique scores, and raw JSON payload snapshots.
- Live event-driven progress updates streamed directly from the backend LangGraph engine using Server-Sent Events (
- βοΈ Resend API Email Dispatch:
- Direct email sending integrated with Resend API using custom domain
alerts@support.elitedev.space. - Recipient email address automatically prefilled from local user profile.
- Direct email sending integrated with Resend API using custom domain
- π Rich Markdown & Artifact Viewer:
- Full structured Markdown parsing via
react-markdownandremark-gfm. - Multi-tab rendering: Visual, Markdown, and HTML.
- One-click downloads for
.mdand.htmlfiles.
- Full structured Markdown parsing via
- π¨ Minimalist ERP 3-Way Split UI:
- Sleek side navigation (Agent, Newsletters history, Profile, and GitHub/LinkedIn links).
- Modern neutral design palette (
slate/neutral) matchingshadcn/uiaesthetic with dark mode support.
- πΎ Zustand State Persistence:
- Local browser storage for user profile settings, saved newsletters, and active agent execution states.
The backend graph in apps/server/src/agent is orchestrated using LangGraph @langchain/langgraph and persistent MemorySaver checkpointer.
graph TD
A[User Input / Goal] --> B[Intent Router Node]
B -->|Greeting / Chat| C[Chat Response Node]
B -->|Newsletter Intent| D[Planner Node]
D --> E[Research Node - Tavily Web Search]
E --> F[Rank Node - Gemini LLM Selection]
F --> G[Summarizer Node]
G --> H[Writer Node - Draft Generation]
H --> I[Critique Node - Quality Assessment]
I -->|Score < 8| J[Improvement Node]
J --> H
I -->|Score >= 8 / Approved| K[Export Node]
K --> L[Final Newsletter Artifact & Email Dispatch]
- Intent Router Node: Classifies user prompts into conversational queries vs newsletter generation goals.
- Planner Node: Translates newsletter goals into targeted search queries.
- Research Node: Queries the Tavily Web Search API to fetch 8+ live news stories.
- Rank Node: Uses Gemini LLM reasoning to evaluate and select the top 5 most impactful articles.
- Summarizer Node: Formulates concise key takeaways and "Why it matters" context for each story.
- Writer Node: Drafts complete newsletter copy formatted in structured Markdown and clean HTML.
- Critique Node: Performs quality assessment (grammar, tone, completeness) and assigns a score out of 10.
- Improvement Node: Re-drafts content if the quality score is below threshold.
- Export Node: Prepares final download files and email dispatch payloads.
Newsletter Agent/
βββ apps/
β βββ server/ # Node.js Express & LangGraph Agent Backend
β β βββ src/
β β β βββ agent/ # LangGraph 8-Node Agent Graph & Checkpointer
β β β βββ controllers/ # REST & SSE Controllers (getNews, stream, sendEmail, download)
β β β βββ routes/ # Express Route Definitions
β β β βββ index.ts # Server Entry Point (Port 3001)
β β βββ package.json
β β
β βββ web/ # Next.js 16 App Router & React 19 Frontend
β βββ public/ # Static assets & logo.webp
β βββ src/
β β βββ app/ # App Router Pages (/agent, /newsletters, /profile)
β β βββ components/ # Reusable UI & Logo Components
β β βββ hooks/ # Custom Hooks (useAgent, useProfile)
β β βββ pages_modules/ # Page-specific views (ChatBox, LogPanel, NewsletterArtifact)
β β βββ services/ # Axios API & SSE EventSource Clients
β β βββ store/ # Zustand Persist Stores (useAgentStore, useProfileStore)
β βββ package.json
β
βββ MILESTONES.md # Step-by-Step Project Roadmap & Completed Features
βββ LAST_IMPROVEMENTS.md # Architectural Refactoring Documentation
βββ pnpm-workspace.yaml # Monorepo Workspace Configuration
βββ package.json # Root Monorepo Scripts
- Node.js:
v20.0.0+ - Package Manager:
pnpm(v10+)
Create a .env file in apps/server/.env:
# Google Gemini LLM API Key
GEMINI_API_KEY=your_gemini_api_key
# Tavily Web Search API Key
TAVILY_API_KEY=your_tavily_api_key
# Resend Email API Key
RESEND_API=your_resend_api_key
# LangSmith Observability (Optional)
LANGSMITH_TRACING=true
LANGSMITH_ENDPOINT=https://api.smith.langchain.com
LANGSMITH_API_KEY=your_langsmith_api_key
LANGSMITH_PROJECT=NewsletterAgentCreate a .env.local file in apps/web/.env.local:
NEXT_PUBLIC_BACKEND_URL=http://localhost:3001From the root directory:
pnpm installStart both apps/server (Express backend) and apps/web (Next.js frontend) concurrently:
pnpm dev- Frontend: http://localhost:3000 (or current Next dev port)
- Backend API: http://localhost:3001
| Method | Endpoint | Description |
|---|---|---|
POST |
/api/get-news |
Triggers news research agent workflow (goal, mode, threadId). |
GET |
/api/newsletter/stream |
Streams live SSE execution logs & stage snapshots. |
POST |
/api/newsletter/approve |
Approves intermediate stage & resumes Human-in-the-Loop execution. |
POST |
/api/newsletter/send-email |
Dispatches newsletter email via Resend API to target recipient. |
GET |
/api/newsletter/download |
Serves .md or .html file downloads directly. |
- Framework: Next.js 16 (Turbopack), React 19, Express.js
- Agent Architecture: LangChain, LangGraph JS, Tavily Search SDK
- LLM Engine: Google Gemini 2.5 Flash
- Styling: Tailwind CSS v4, Lucide React, Framer Motion
- State & Theme: Zustand (Persist Middleware), Next-Themes
- Email Delivery: Resend API