Skip to content

heefan/agent_design_patterns

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

1 Commit
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Tech Blog Writer Agent

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.

🎯 Features

  • 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

πŸ—οΈ Architecture

Chain Steps

  1. Topic Research & Analysis πŸ“Š

    • Analyzes topic relevance and trending status
    • Identifies target audience and pain points
    • Researches competitive landscape
    • Discovers search intent and keywords
  2. Content Outline Generation πŸ“

    • Creates structured blog outline
    • Develops compelling titles and meta descriptions
    • Plans content strategy and engagement elements
    • Maps internal linking opportunities
  3. Content Writing ✍️

    • Writes engaging, well-structured content
    • Includes practical examples and case studies
    • Maintains consistent tone and style
    • Incorporates markdown formatting
  4. SEO Optimization πŸ”

    • Optimizes keyword placement and density
    • Enhances readability and structure
    • Adds meta tags and schema recommendations
    • Improves heading hierarchy
  5. Final Review & Polish ✨

    • Grammar and spell checking
    • Quality assessment and scoring
    • Final formatting and consistency
    • Publication readiness verification

Quality Gates

Each step includes automated validation:

  • Content completeness checks
  • Word count validation
  • Structure verification
  • SEO requirement validation

πŸš€ Installation

Prerequisites

  • Python 3.11+
  • UV package manager
  • Either: Gemini API key (local) OR Google Cloud Project (production)

Quick Setup

  1. Clone and setup project:
git clone <repository>
cd tech_blog_agent
  1. Install dependencies:
uv sync
  1. Choose your deployment mode:

🟒 Option A: Local Testing (Recommended for getting started)

# 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

πŸ”΅ Option B: Production Deployment (Google Cloud)

# 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-id

πŸ“– Usage

Interactive Mode

uv run python main.py

The 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)

Demo Mode

uv run python main.py

Select option 2 to run predefined examples.

Programmatic Usage

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())

πŸ—οΈ Project Structure

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

πŸ”§ Configuration

Environment Variables

For Local Testing:

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)

Chain Configuration

You can customize the chain by:

  1. Modifying agent prompts in individual agent files
  2. Adjusting quality gates in validators/quality_gates.py
  3. Changing model parameters in agent constructors
  4. Adding new steps by extending BaseAgent class

Model Configuration

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)

πŸ§ͺ Quality Gates

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

🚨 Troubleshooting

Local Testing Issues

  1. 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
  2. Import Error

    uv sync  # Reinstall dependencies

Production Issues

  1. Authentication Error

    gcloud auth application-default login
  2. Project ID Not Set

    export GOOGLE_CLOUD_PROJECT=your-project-id
    export USE_GEMINI_API=false
  3. Vertex AI API Not Enabled

    gcloud services enable aiplatform.googleapis.com

Switching Between Modes

# 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
  1. Quota Exceeded
    • Check your Vertex AI quotas in Google Cloud Console
    • Consider using different regions

Debug Mode

Set environment variable for detailed logging:

export DEBUG=1
uv run python main.py

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Add your changes
  4. Ensure quality gates pass
  5. Submit a pull request

πŸ“„ License

MIT License - see LICENSE file for details.

🎯 Next Steps

  • 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

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages