A sophisticated AI-powered blog writing system using Google's Gemini models and the chain design pattern. This agent breaks down blog creation into sequential, focused steps for higher quality output.
- Chain Design Pattern: Sequential 5-step workflow with quality gates
- Dual Deployment Options: Local testing with Gemini API or production with Vertex AI
- Easy Local Testing: No cloud setup required - just an API key
- Quality Validation: Automated checks between each step
- SEO Optimization: Built-in search engine optimization
- Flexible Configuration: Customizable audience, style, and length
- Error Recovery: Retry failed steps with feedback
-
Topic Research & Analysis π
- Analyzes topic relevance and trending status
- Identifies target audience and pain points
- Researches competitive landscape
- Discovers search intent and keywords
-
Content Outline Generation π
- Creates structured blog outline
- Develops compelling titles and meta descriptions
- Plans content strategy and engagement elements
- Maps internal linking opportunities
-
Content Writing βοΈ
- Writes engaging, well-structured content
- Includes practical examples and case studies
- Maintains consistent tone and style
- Incorporates markdown formatting
-
SEO Optimization π
- Optimizes keyword placement and density
- Enhances readability and structure
- Adds meta tags and schema recommendations
- Improves heading hierarchy
-
Final Review & Polish β¨
- Grammar and spell checking
- Quality assessment and scoring
- Final formatting and consistency
- Publication readiness verification
Each step includes automated validation:
- Content completeness checks
- Word count validation
- Structure verification
- SEO requirement validation
- Python 3.11+
- UV package manager
- Either: Gemini API key (local) OR Google Cloud Project (production)
- Clone and setup project:
git clone <repository>
cd tech_blog_agent- Install dependencies:
uv sync- Choose your deployment mode:
# 1. Get API key from: https://makersuite.google.com/app/apikey
# 2. Configure environment:
cp .env.example .env
# Edit .env and set:
USE_GEMINI_API=true
GEMINI_API_KEY=your_api_key_here# 1. Set up Google Cloud:
export GOOGLE_CLOUD_PROJECT=your-project-id
gcloud auth application-default login
gcloud services enable aiplatform.googleapis.com
# 2. Configure environment:
cp .env.example .env
# Edit .env and set:
USE_GEMINI_API=false
GOOGLE_CLOUD_PROJECT=your-project-iduv run python main.pyThe system will automatically detect your configuration and use the appropriate API. Then provide:
- Blog topic
- Target audience (optional)
- Writing style (optional)
- Target word count (default: 1500)
- SEO keywords (optional)
uv run python main.pySelect option 2 to run predefined examples.
import asyncio
from agents.client_factory import ClientFactory
from chains.blog_writer_chain import BlogWriterChain
async def generate_blog():
# Automatically uses correct client based on environment
client = ClientFactory.create_client()
chain = BlogWriterChain(client)
result = await chain.generate_blog_post(
topic="Introduction to Docker Containers",
target_audience="beginner developers",
style_guide="friendly and practical",
word_count_target=1800,
seo_keywords=["docker", "containers", "containerization"]
)
if result["success"]:
print("Blog generated successfully!")
print(f"Word count: {result['metadata']['word_count']}")
# Save to file
with open("blog_post.md", "w") as f:
f.write(result["blog_post"])
else:
print(f"Generation failed: {result['error']}")
asyncio.run(generate_blog())tech_blog_agent/
βββ agents/ # Individual AI agents
β βββ client_factory.py # Client factory for API switching
β βββ vertex_ai_client.py # Google Vertex AI client
β βββ gemini_api_client.py # Direct Gemini API client
β βββ researcher.py # Topic research agent
β βββ outliner.py # Content outline agent
β βββ writer.py # Content writing agent
β βββ seo_optimizer.py # SEO optimization agent
β βββ reviewer.py # Final review agent
βββ chains/ # Chain orchestration
β βββ base.py # Base classes and models
β βββ blog_writer_chain.py # Main blog writer chain
βββ validators/ # Quality validation
β βββ quality_gates.py # Quality gate implementations
βββ main.py # Main application entry point
βββ pyproject.toml # UV project configuration
βββ README.md # This file
For Local Testing:
USE_GEMINI_API=true(enables Gemini API mode)GEMINI_API_KEY=your_api_key(get from https://makersuite.google.com/app/apikey)
For Production:
USE_GEMINI_API=false(or omit - enables Vertex AI mode)GOOGLE_CLOUD_PROJECT=your-project-id(your Google Cloud project)VERTEX_AI_LOCATION=us-central1(optional, default location)
You can customize the chain by:
- Modifying agent prompts in individual agent files
- Adjusting quality gates in
validators/quality_gates.py - Changing model parameters in agent constructors
- Adding new steps by extending
BaseAgentclass
Default models and parameters:
- Model:
gemini-1.5-pro(works with both APIs) - Temperature: 0.3-0.7 (varies by step)
- Max tokens: 1500-5000 (varies by step)
Each step has validation criteria:
- Research: Completeness, word count, required sections
- Outline: Structure, headings, required elements
- Content: Word count targets, paragraph structure, headings
- SEO: Keyword usage, meta elements, topic mentions
- Final: Publication readiness, quality score
-
API Key Error
# Get API key from: https://makersuite.google.com/app/apikey export GEMINI_API_KEY=your_api_key_here export USE_GEMINI_API=true
-
Import Error
uv sync # Reinstall dependencies
-
Authentication Error
gcloud auth application-default login
-
Project ID Not Set
export GOOGLE_CLOUD_PROJECT=your-project-id export USE_GEMINI_API=false
-
Vertex AI API Not Enabled
gcloud services enable aiplatform.googleapis.com
# Switch to local testing
export USE_GEMINI_API=true
export GEMINI_API_KEY=your_api_key
# Switch to production
export USE_GEMINI_API=false
export GOOGLE_CLOUD_PROJECT=your_project_id- Quota Exceeded
- Check your Vertex AI quotas in Google Cloud Console
- Consider using different regions
Set environment variable for detailed logging:
export DEBUG=1
uv run python main.py- Fork the repository
- Create a feature branch
- Add your changes
- Ensure quality gates pass
- Submit a pull request
MIT License - see LICENSE file for details.
- Add support for multiple output formats (HTML, PDF)
- Integrate with CMS platforms (WordPress, Medium)
- Add image generation capabilities
- Implement A/B testing for different approaches
- Add analytics and performance tracking