Skip to content

BrijeshRakhasiya/Agentic-Blog-Generator

Repository files navigation

🤖 Agentic Blog Generator

An End-to-End Agentic AI Application for Intelligent Blog Generation with Multi-Language Support

Python LangGraph FastAPI Groq License: MIT


📋 Table of Contents


🎯 Problem Statement

The Challenge

In today's digital landscape, content creation faces several critical challenges:

Problem Impact
Time-Consuming Content Creation Writers spend 3-4 hours on average to create a single comprehensive blog post
Language Barriers Businesses struggle to reach global audiences due to lack of multilingual content
Inconsistent Quality Manual content creation leads to varying quality and tone across articles
Scalability Issues Traditional content workflows can't scale to meet growing content demands
SEO Optimization Creating SEO-friendly titles and content requires specialized expertise

Real-World Scenario

"A tech company wants to publish blog content about emerging technologies in multiple languages to reach their global audience. They need consistent, high-quality, SEO-optimized content that maintains cultural relevance across translations."

Key Questions This Project Addresses

  1. How can we automate blog generation while maintaining quality?
  2. How do we handle multi-language content generation with cultural adaptation?
  3. How can we create a modular, scalable content generation pipeline?
  4. How do we orchestrate multiple AI agents to work together seamlessly?

💡 Solution Approach

Agentic AI Architecture

I implemented an Agentic AI System using LangGraph that breaks down the complex task of blog generation into specialized, autonomous agents that collaborate to produce high-quality content.

┌─────────────────────────────────────────────────────────────────────────┐
│                        AGENTIC AI PARADIGM                              │
├─────────────────────────────────────────────────────────────────────────┤
│  Traditional AI          vs.          Agentic AI (This Project)        │
│  ─────────────────                    ─────────────────────────         │
│  • Single monolithic model            • Multiple specialized agents     │
│  • One-shot generation                • Multi-step orchestrated flow    │
│  • No state management                • Stateful conversation           │
│  • Limited control flow               • Conditional routing & branching │
│  • Hard to debug/trace                • Full observability (LangSmith)  │
└─────────────────────────────────────────────────────────────────────────┘

Why LangGraph?

Feature Benefit
State Management Maintains context across all nodes, ensuring coherent content
Conditional Routing Dynamically routes to appropriate translation agent based on input
Graph Visualization Clear understanding of workflow with visual representation
Fault Tolerance Each node can handle errors independently
Observability Full tracing with LangSmith for debugging and optimization

Solution Components

graph TD
    A[User Input] -->|topic + language| B[FastAPI Server]
    B --> C{GraphBuilder}
    C -->|topic only| D[Topic Graph]
    C -->|topic + language| E[Language Graph]
    
    D --> F[Title Agent]
    F --> G[Content Agent]
    G --> H[Return Blog]
    
    E --> I[Title Agent]
    I --> J[Content Agent]
    J --> K[Router Agent]
    K -->|hindi| L[Hindi Translator]
    K -->|french| M[French Translator]
    L --> N[Return Translated Blog]
    M --> N
Loading

🏗️ System Architecture

High-Level Architecture

┌──────────────────────────────────────────────────────────────────────────┐
│                              CLIENT LAYER                                 │
│                    (REST API / LangGraph Studio)                          │
└────────────────────────────────┬─────────────────────────────────────────┘
                                 │ HTTP POST /blogs
                                 ▼
┌──────────────────────────────────────────────────────────────────────────┐
│                           APPLICATION LAYER                               │
│  ┌─────────────────┐    ┌─────────────────┐    ┌─────────────────┐       │
│  │   FastAPI App   │───▶│  GraphBuilder   │───▶│   StateGraph    │       │
│  │    (app.py)     │    │ (graph_builder) │    │   (LangGraph)   │       │
│  └─────────────────┘    └─────────────────┘    └─────────────────┘       │
└────────────────────────────────┬─────────────────────────────────────────┘
                                 │
                                 ▼
┌──────────────────────────────────────────────────────────────────────────┐
│                            AGENT LAYER                                    │
│  ┌───────────────┐  ┌───────────────┐  ┌───────────────┐                 │
│  │  Title Agent  │  │ Content Agent │  │  Route Agent  │                 │
│  │               │  │               │  │               │                 │
│  │ • SEO Title   │  │ • Detailed    │  │ • Language    │                 │
│  │ • Creative    │  │   Content     │  │   Detection   │                 │
│  │ • Markdown    │  │ • Markdown    │  │ • Routing     │                 │
│  └───────────────┘  └───────────────┘  └───────────────┘                 │
│                                              │                            │
│                          ┌───────────────────┼───────────────────┐       │
│                          ▼                   ▼                   ▼       │
│                  ┌──────────────┐    ┌──────────────┐    ┌───────────┐  │
│                  │Hindi Translator│  │French Translator│ │ More...   │  │
│                  │              │    │              │    │           │  │
│                  │• Cultural    │    │• Cultural    │    │           │  │
│                  │  Adaptation  │    │  Adaptation  │    │           │  │
│                  └──────────────┘    └──────────────┘    └───────────┘  │
└────────────────────────────────────────────────────────────────────────┘
                                 │
                                 ▼
┌──────────────────────────────────────────────────────────────────────────┐
│                              LLM LAYER                                    │
│  ┌─────────────────────────────────────────────────────────────────┐     │
│  │                      Groq LLM (GPT-OSS-120B)                    │     │
│  │                                                                  │     │
│  │  • Ultra-fast inference (~10x faster than traditional APIs)     │     │
│  │  • High-quality text generation                                  │     │
│  │  • Cost-effective for production workloads                       │     │
│  └─────────────────────────────────────────────────────────────────┘     │
└────────────────────────────────────────────────────────────────────────┘
                                 │
                                 ▼
┌──────────────────────────────────────────────────────────────────────────┐
│                          OBSERVABILITY LAYER                              │
│  ┌─────────────────────────────────────────────────────────────────┐     │
│  │                         LangSmith                                │     │
│  │                                                                  │     │
│  │  • Full trace of agent execution                                 │     │
│  │  • Token usage monitoring                                        │     │
│  │  • Latency tracking                                              │     │
│  │  • Debug failed runs                                             │     │
│  └─────────────────────────────────────────────────────────────────┘     │
└──────────────────────────────────────────────────────────────────────────┘

State Flow Diagram

┌─────────────────────────────────────────────────────────────────┐
│                        BlogState                                 │
├─────────────────────────────────────────────────────────────────┤
│  {                                                               │
│    "topic": "Agentic AI in Healthcare",                         │
│    "current_language": "hindi",                                 │
│    "blog": {                                                     │
│      "title": "Generated SEO Title...",                         │
│      "content": "Detailed blog content..."                      │
│    }                                                             │
│  }                                                               │
└─────────────────────────────────────────────────────────────────┘
                              │
        ┌─────────────────────┼─────────────────────┐
        ▼                     ▼                     ▼
   [Title Node]         [Content Node]      [Translation Node]
   Updates: title       Updates: content    Updates: content
                                            (translated)

🔄 Workflow Visualization

LangGraph Flow Diagram

Blog Generation Flow

The above diagram shows the complete LangGraph workflow:

  1. START → Entry point of the graph
  2. title_creation → Generates SEO-optimized blog title
  3. content_generation → Creates detailed blog content
  4. route → Determines the target language
  5. Conditional Edge → Routes to appropriate translator
  6. hindi_translation / french_translation → Translates content
  7. END → Returns final state

🛠️ Tech Stack

Category Technology Purpose
Framework LangGraph Agentic workflow orchestration
LLM Groq (GPT-OSS-120B) Fast, high-quality text generation
API FastAPI RESTful API server
State Management TypedDict + Pydantic Type-safe state handling
Tracing LangSmith Observability & debugging
Language Python 3.13+ Modern Python features

Why These Choices?

Technology Rationale
LangGraph over LangChain Agents Better control flow, explicit state management, and visual debugging
Groq over OpenAI 10x faster inference, cost-effective, comparable quality
FastAPI over Flask Async support, automatic OpenAPI docs, type hints
Pydantic Runtime type validation, automatic serialization

📁 Project Structure

Agentic-Blog-Generator/
│
├── 📄 app.py                    # FastAPI application entry point
├── 📄 main.py                   # Alternative entry point
├── 📄 langgraph.json            # LangGraph Studio configuration
├── 📄 requirements.txt          # Project dependencies
├── 📄 pyproject.toml            # Python project metadata
├── 📄 README.md                 # Project documentation (you're here!)
│
├── 📁 src/                      # Source code package
│   ├── 📄 __init__.py
│   │
│   ├── 📁 graphs/               # LangGraph workflow definitions
│   │   ├── 📄 __init__.py
│   │   └── 📄 graph_builder.py  # Graph construction logic
│   │
│   ├── 📁 llms/                 # LLM configurations
│   │   ├── 📄 __init__.py
│   │   └── 📄 groqllm.py        # Groq LLM wrapper
│   │
│   ├── 📁 nodes/                # Agent node implementations
│   │   ├── 📄 __init__.py
│   │   └── 📄 blog_node.py      # Blog generation nodes
│   │
│   └── 📁 states/               # State definitions
│       ├── 📄 __init__.py
│       └── 📄 blogstate.py      # BlogState TypedDict
│
├── 📁 assets/                   # Images and media
│   ├── 🖼️ blog_generation_flow.png
│   ├── 🖼️ output_1.png          # Hindi output screenshot
│   ├── 🖼️ output_2.png          # French output screenshot
│   └── 🖼️ sample_input.png      # LangSmith input screenshot
│
└── 📁 outputs/                  # Generated content samples
    ├── 📄 output_results.txt         # English blog output
    ├── 📄 output_results_hindi.txt   # Hindi translated blog
    └── 📄 output_results_french.txt  # French translated blog

⚙️ Installation & Setup

Prerequisites

  • Python 3.13 or higher
  • Groq API Key (Get it here)
  • LangSmith API Key (Optional, for tracing)

Step 1: Clone the Repository

git clone https://github.com/BrijeshRakhasiya/Agentic-Blog-Generator.git
cd Agentic-Blog-Generator

Step 2: Create Virtual Environment

# Using venv
python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate

# Or using uv (recommended)
uv venv
source .venv/bin/activate

Step 3: Install Dependencies

# Using pip
pip install -r requirements.txt

# Or using uv
uv pip install -r requirements.txt

Step 4: Configure Environment Variables

Create a .env file in the root directory:

# Required
GROQ_API_KEY=your_groq_api_key_here

# Optional (for LangSmith tracing)
LANGCHAIN_API_KEY=your_langsmith_api_key_here
LANGCHAIN_TRACING_V2=true
LANGCHAIN_PROJECT=agentic-blog-generator

Step 5: Run the Application

# Start the FastAPI server
python app.py

# Or using uvicorn directly
uvicorn app:app --host 0.0.0.0 --port 8000 --reload

The API will be available at http://localhost:8000


🚀 Usage

API Endpoint

POST /blogs

Request Body

{
  "topic": "Agentic AI in Healthcare",
  "language": "hindi"  // Optional: "hindi", "french", or omit for English
}

Example Requests

Generate English Blog (Topic Only)

curl -X POST "http://localhost:8000/blogs" \
  -H "Content-Type: application/json" \
  -d '{"topic": "Future of Artificial Intelligence"}'

Generate Hindi Blog

curl -X POST "http://localhost:8000/blogs" \
  -H "Content-Type: application/json" \
  -d '{"topic": "Agentic AI in Healthcare", "language": "hindi"}'

Generate French Blog

curl -X POST "http://localhost:8000/blogs" \
  -H "Content-Type: application/json" \
  -d '{"topic": "AI in Automotive Industry", "language": "french"}'

Response Format

{
  "data": {
    "topic": "Agentic AI in Healthcare",
    "current_language": "hindi",
    "blog": {
      "title": "एजेंटिक एआई इन हेल्थकेयर: इंटेलिजेंट मेडिसिन के भविष्य में एक गहन विश्लेषण",
      "content": "... detailed translated content ..."
    }
  }
}

Using LangGraph Studio

You can also visualize and test the graph using LangGraph Studio:

langgraph dev

📊 Sample Outputs

Input Configuration (LangSmith Tracing)

Sample Input in LangSmith

The above screenshot shows the input configuration in LangSmith tracing interface.


Output 1: Hindi Translation

Hindi Output

📖 Click to see Hindi Output Content
एजेंटिक एआई इन हेल्थकेयर: इंटेलिजेंट मेडिसिन के भविष्य में एक गहन विश्लेषण

द्वारा [Your Name], एआई & हेल्थकेयर थॉट लीडर

प्रकाशित: दिसंबर 2025

सामग्री-सूची

#	सेक्शन
1	एजेंटिक एआई क्या है?
2	हेल्थकेयर क्यों है एजेंटिक सिस्टम्स का परफेक्ट प्लेग्राउंड?
3	मुख्य आर्किटेक्चरल स्तम्भ
4	प्रमुख उपयोग‑केस और वास्तविक‑विश्व कार्यान्वयन
5	टेक्निकल ब्लूप्रिंट: एजेंटिक हेल्थकेयर प्लेटफ़ॉर्म बनाना
...

Output 2: French Translation

French Output

📖 Click to see French Output Content
AI dans l'automobile : Plongée approfondie dans le futur de la mobilité

Par un·e rédacteur·rice expert·e en technologies automobiles

Table des matières

#	Section	Idée clé
1	Introduction	Pourquoi l'IA est le moteur qui propulse la prochaine révolution automobile
2	Bref historique de l'IA dans les voitures	Du régulateur de vitesse au niveau 5 d'autonomie
3	Technologies IA de base	Capteurs, perception, prise de décision et actionnement
4	Applications concrètes aujourd'hui	ADAS, conduite autonome, maintenance prédictive...
...

Output Comparison

Aspect English Hindi French
Topic Agentic AI in Healthcare Agentic AI in Healthcare AI in Automotive
Title Style SEO-optimized Culturally adapted Professionally localized
Content Format Markdown tables, headers Same structure, Hindi text Same structure, French text
Cultural Adaptation ✓ Idioms adapted ✓ Idioms adapted

🔍 LangSmith Tracing

This project integrates with LangSmith for complete observability:

Features

  • Full Trace Visualization: See every step of the agent workflow
  • Token Usage: Monitor LLM token consumption
  • Latency Tracking: Identify performance bottlenecks
  • Error Debugging: Debug failed runs with full context
  • Run Comparison: Compare different runs side by side

Sample Trace

The LangSmith trace shows:

  1. Input processing (topic + language)
  2. Title generation step
  3. Content generation step
  4. Routing decision
  5. Translation execution
  6. Final output

🧠 Key Learnings

Technical Insights

Learning Description
State Graph Design Designing state schemas that flow cleanly through nodes is crucial
Conditional Routing LangGraph's conditional edges enable dynamic workflow branching
Agent Specialization Breaking tasks into specialized agents improves output quality
Error Handling Each node should handle errors gracefully to prevent cascade failures

Architecture Patterns

  1. Single Responsibility: Each node does one thing well
  2. State Immutability: Nodes return new state updates, not mutations
  3. Composability: Graphs can be composed into larger workflows
  4. Observability First: Built-in tracing from day one

Challenges Overcome

Challenge Solution
State persistence across nodes Used TypedDict with proper field definitions
Dynamic language routing Implemented conditional edges with route_decision function
LLM response consistency Added structured prompts with clear formatting instructions
Translation quality Included cultural adaptation instructions in prompts

🔮 Future Enhancements

Priority Enhancement Description
🔴 High More Languages Add Spanish, German, Japanese, Chinese support
🔴 High Image Generation Integrate DALL-E/Stable Diffusion for blog images
🟡 Medium SEO Analysis Add keyword density, readability score analysis
🟡 Medium Content Caching Redis-based caching for repeated topics
🟢 Low Voice Generation Text-to-speech for audio blog versions
🟢 Low Scheduling Automated blog generation on schedule

Roadmap

Q1 2025: Multi-language support (10+ languages)
Q2 2025: Image generation integration
Q3 2025: SEO optimization agent
Q4 2025: Full CMS integration

🤝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

📄 License

This project is licensed under the MIT License - see the LICENSE file for details.

MIT License

Copyright (c) 2025 Brijesh Rakhasiya

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

👨‍💻 Author

Built with ❤️ by Brijesh Rakhasiya

GitHub


⭐ Star this repository if you found it helpful!

Releases

No releases published

Packages

 
 
 

Contributors

Languages