The Problem: Death by 1,000 Tabs
Like many developers, my morning routine used to be a productivity killer. It involved opening about 25 tabs-Hacker News, TechCrunch, Bloomberg, various Substacks, Twitter-trying to find the actual "signal" amidst the noise.
The reality? 90% of it was repetitive clickbait or shallow press releases.
I realized I was spending an hour just trying to find something to read, rather than actually reading. I decided to engineer my way out of this loop.
I didn't just want a GPT wrapper that summarizes text. I wanted an autonomous system that could research, cross-reference multiple sources, write a draft, and then-crucially-critique its own work before showing it to me.
Here is how I built TrendFlow, an agentic news workflow using Python, LangGraph, and Google Gemini.
The Tech Stack
I needed a stack that handled logic, not just text generation.
-
The Brains:
Google Gemini 2.5 Pro(Creative work) &2.5 Flash(Fast logic/JSON) - The Orchestrator: LangGraph (State management and cyclical flows)
- The Eyes (APIs): A robust aggregator hitting GNews, MarketAux (for financial sentiment), The Guardian, NYT, Newsdata and Google News.
- The Plumbing: Python & Pydantic for strict data validation.
The Architecture: It's Not a Straight Line
The key difference between a simple script and an "agent" is the ability to loop back and self-correct.
I designed a state graph with five distinct "personas" (nodes):
1. The Researcher
It doesn't just search the topic. It uses an LLM to generate optimized Boolean queries to find fresh, specific data.2. The Aggregator
A custom tool that hits 6+ premium sources with failovers. If the NYT API times out, it automatically switches to The Guardian.3. The Writer
A persona prompted to write like a senior tech columnist—data-driven, skeptical of hype, and punchy.4. The Ruthless Editor (The Secret Sauce)
This is where most AI content fails. I built a node that specifically hunts for "AI Slop." If it sees words like "delve," it slaps a big red REJECT stamp on the draft.5. SEO & Packaging
Once approved, this node generates viral titles, meta tags, and LinkedIn hooks.
The Code: The Quality Control Loop
The most critical part of this application is the conditional edge that decides if a draft is good enough.
If the Editor rejects a draft, it doesn't just end. The state is passed to a "Refiner" node along with specific critiques. The Refiner fixes only what was asked, and sends it back to the Editor for another review.
Here is the Python logic that manages that state transition in LangGraph:
# Define the state of our article travelling through the graph
class AgentState(TypedDict):
topic: str
draft: str
critique: str
revision_count: int
is_approved: bool
# ... other metadata
# The Conditional Logic
def check_approval(state: AgentState):
"""
Determines the next step based on the Editor's verdict.
"""
# 1. If approved by Editor with a high score, proceed to packaging
if state["is_approved"]:
print("--- Draft Approved. Moving to SEO. ---")
return "approved"
# 2. Safety Valve: Prevent infinite loops.
# If we've already revised twice, force approval or bail out.
if state["revision_count"] >= 2:
print("--- Max revisions reached. Proceeding anyway. ---")
return "approved"
# 3. Otherwise, send it back to the Refiner node to fix the critique
print(f"--- Draft Rejected. Sending back for revision {state['revision_count'] + 1} ---")
return "rejected"
# Adding the conditional edge to the graph workflow
workflow.add_conditional_edges(
"editor", # The node where the decision happens
check_approval, # The function above
{
"approved": "seo", # Map return value to next node
"rejected": "refiner" # Map return value to next node
}
)
This loop ensures the final output is rarely the first, generic draft the LLM spits out. It forces iteration.
The Results
Instead of 25 tabs, I now run one script:
python backend/main.py --topic "Artificial Intelligence"
Five minutes later, I get a fully sourced, concise briefing that has already been fact-checked and stripped of marketing fluff. It's not perfect, but it's better than 90% of the SEO content out there, and it took zero of my time to produce.
What's Next?
I'm currently working on adding a "Memory" layer using vector storage (Supabase pgvector) so the agent remembers what it wrote yesterday and doesn't repeat itself.
I'm planning to open-source the repo once I clean up the API key handling.
Let me know in the comments: What's your biggest pain point with current AI-generated content, and how would you program an "Editor" node to fix it?
Top comments (0)