A sophisticated AI-powered blog generation system that leverages LangGraph and Google Gemini AI to automatically generate, optimize, and translate blog content across multiple languages.
This project implements an agentic workflow using LangGraph state graphs to orchestrate a multi-step blog generation pipeline. It features:
- Intelligent Blog Generation: Generates engaging blog titles and content based on user-provided topics
- Multi-Language Support: Automatically translates generated blogs into Hindi and Marathi
- REST API Interface: FastAPI-based HTTP endpoints for easy integration
- LangSmith Integration: Built-in support for debugging and monitoring via LangSmith
- Production-Ready: Comprehensive error handling, validation, and logging
| Component | Technology |
|---|---|
| LLM | Google Gemini 2.5 Flash |
| Orchestration | LangGraph |
| API Framework | FastAPI |
| Server | Uvicorn |
| Language Framework | LangChain |
| Environment Management | Python dotenv |
agentic-ai-blog-generation/
├── app.py # FastAPI application with REST endpoints
├── main.py # Entry point
├── requirements.txt # Project dependencies
├── pyproject.toml # Project configuration
├── langgraph.json # LangGraph configuration
├── .env.example # Environment variables template
└── src/
├── llms/
│ └── gemini_llm.py # Google Gemini LLM wrapper
├── graphs/
│ └── graph_builder.py # LangGraph state graph builder
├── nodes/
│ └── blog_node.py # Blog generation node implementations
└── states/
└── blogstate.py # State definitions using TypedDict
The system uses LangGraph to orchestrate a multi-step blog generation workflow:
Generates blog content in English based on the provided topic:
Generates blog in English, then translates to requested language:
| Node | Function | Description |
|---|---|---|
| title_creation | Generates catchy, SEO-friendly blog titles | Uses Gemini to create compelling titles |
| content_generation | Creates detailed blog content | Generates 250-word markdown-formatted content |
| route | Extracts language for conditional routing | Determines translation path |
| hindi_translation | Translates to Hindi | Uses structured output for accuracy |
| marathi_translation | Translates to Marathi | Preserves formatting and tone |
- Title Generation: Catchy, SEO-optimized blog titles
- Content Creation: Detailed, engaging blog content with markdown formatting
- Smart Prompting: Expert-crafted prompts for high-quality outputs
- Native Languages: Hindi and Marathi translations
- Structured Output: Pydantic models for consistent blog structure
- Cultural Adaptation: Translates with cultural sensitivity
POST /generate_blog/- Generate and optionally translate blogsGET /health/- Health check endpoint
- Comprehensive input validation
- Detailed error messages and logging
- Graceful failure handling
- Python 3.13 or higher
- Google Gemini API Key (Get one here)
- LangChain API Key (optional, for debugging)
git clone <repository-url>
cd agentic-ai-blog-generationpython -m venv .venv# Windows
.venv\Scripts\activate
# macOS/Linux
source .venv/bin/activateuv add -r requirements.txtCreate a .env file in the project root:
cp .env.example .envEdit .env and add your credentials:
# Required
GEMINI_API_KEY=your_gemini_api_key_here
# Optional (for LangSmith debugging)
LANGCHAIN_API_KEY=your_langchain_api_key
LANGCHAIN_PROJECT=your_project_namepython app.pyThe API will be available at http://localhost:8000
- Interactive Swagger UI:
http://localhost:8000/docs - ReDoc documentation:
http://localhost:8000/redoc
curl -X POST "http://localhost:8000/generate_blog/" \
-H "Content-Type: application/json" \
-d '{"topic": "Machine Learning in Healthcare"}'curl -X POST "http://localhost:8000/generate_blog/" \
-H "Content-Type: application/json" \
-d '{
"topic": "Artificial Intelligence",
"language": "Hindi"
}'curl http://localhost:8000/health/import requests
# API endpoint
url = "http://localhost:8000/generate_blog/"
# Generate blog in Hindi
payload = {
"topic": "Blockchain Technology",
"language": "Hindi"
}
response = requests.post(url, json=payload)
result = response.json()
print(f"Title: {result['data']['blog']['title']}")
print(f"Content: {result['data']['blog']['content']}"){
"topic": "Cloud Computing Benefits",
"language": "Marathi"
}{
"status": "success",
"data": {
"topic": "Cloud Computing Benefits",
"language": "Marathi",
"blog": {
"title": "क्लाउड कंप्यूटिंग के लाभ",
"content": "# क्लाउड कंप्यूटिंग के लाभ\n\n..."
}
}
}{
"status": "error",
"error": "Language must be one of ['Hindi', 'Marathi']"
}| Package | Version | Purpose |
|---|---|---|
| fastapi | >=0.128.0 | Web framework |
| langchain | >=1.2.0 | LLM orchestration |
| langchain-google-genai | >=4.1.2 | Gemini integration |
| langgraph | >=1.0.5 | State graph orchestration |
| langchain-core | >=1.2.6 | Core LangChain components |
| python-dotenv | >=1.2.1 | Environment variable management |
| uvicorn | >=0.40.0 | ASGI server |
-
Install in Development Mode
uv sync
-
Enable LangSmith Debugging Set
LANGCHAIN_TRACING_V2=truein.env -
View Execution Traces
- LangSmith Dashboard: https://smith.langchain.com/
-
LangGraph Studio Integration The project is configured for LangGraph Studio via
langgraph.json
Wrapper for Google Gemini LLM initialization
get_llm(): Returns configured ChatGoogleGenerativeAI instance
Implements blog generation nodes
title_creation(): Generates blog titlecontent_generation(): Generates blog contenttranslation(): Translates blog to target languageroute(): Routes based on language selectionroute_decision(): Determines translation path
Orchestrates LangGraph workflows
build_topic_graph(): Simple English-only workflowbuild_language_graph(): Multi-language workflowsetup_graph(): Compiles and returns executable graph
Type-safe state definition using TypedDict
topic: Input blog topicblog: Generated blog objectlanguage: Target language for translation
# Google Gemini API Configuration
GEMINI_API_KEY=your_api_key_here
# Optional: LangSmith debugging
LANGCHAIN_API_KEY=your_api_key_here
LANGCHAIN_PROJECT=your_project_name
LANGCHAIN_TRACING_V2=trueEdit app.py to modify:
- Host: Change
localhostto0.0.0.0for production - Port: Modify from
8000to desired port - Reload: Set to
Falsein production
if __name__ == "__main__":
uvicorn.run("app:app", host="0.0.0.0", port=8000, reload=False)Currently supported for blog translation:
- Hindi (hi)
- Marathi (mr)
To add more languages:
- Add to
SUPPORTED_LANGUAGESinapp.py - Add corresponding node in
GraphBuilder.build_language_graph()
The application includes comprehensive error handling:
| Error Type | Status Code | Scenario |
|---|---|---|
| Validation Error | 400 | Invalid topic or language |
| LLM Error | 500 | Gemini API issues |
| Missing Config | 500 | Missing GEMINI_API_KEY |
| Rate Limit | 429 | API rate exceeded |
| Unexpected Error | 500 | Unforeseen issues |
- Content Marketing: Automatically generate blog posts for websites
- Multi-Language Blogs: Create content in multiple Indian languages
- SEO Optimization: Generate SEO-friendly titles and content
- Content Curation: Quickly prototype blog content ideas
- AI Learning: Understand LangGraph and agentic workflows
Solution:
- Ensure
.envfile exists in project root - Verify API key is correctly set
- Check file is not in
.gitignore
Solution:
uv add -r requirements.txtSolution:
- Verify internet connection
- Check API key validity
- Ensure quota not exceeded in Google Cloud Console
Solution:
# Add to .env
LANGCHAIN_API_KEY=your_api_key
LANGCHAIN_TRACING_V2=true
LANGCHAIN_PROJECT=your_project_nameContributions are welcome! To contribute:
- Fork the repository
- Create a feature branch (
git checkout -b feature/new-feature) - Commit changes (
git commit -m 'Add new feature') - Push to branch (
git push origin feature/new-feature) - Open a Pull Request
This project is open source and available under the MIT License.

