Standalone LangGraph agent for article rewriting with browser capabilities. This production-ready agent extracts content from URLs, generates SEO-optimized articles, and humanizes the content using advanced writing style guidelines.
- Web Content Extraction: Automatically scrapes and extracts content from URLs
- SEO-Optimized Article Generation: Creates articles with target keywords, readability levels, and SEO scores
- Content Humanization: Applies advanced writing style guidelines for natural, engaging content
- Structured Output: Saves article content and metadata in separate, organized files
The agent follows a streamlined workflow:
- Extract Content (if URL provided) - Scrapes and extracts content from the given URL
- Generate Article - Creates an SEO-optimized article based on keywords, tone, and target audience
- Humanize Content - Applies writing style guidelines to make content more natural and engaging
Install dependencies from the requirements file:
pip install -r requirements.txtSet your OpenAI API key using one of these methods:
Option 1: Environment Variable
export OPENAI_API_KEY=your_openai_api_key_hereOption 2: .env File
Create a .env file in the same directory as the script:
OPENAI_API_KEY=your_openai_api_key_hereThe script will automatically load the .env file if python-dotenv is installed.
To view detailed LLM logs, traces, and monitor agent performance, add LangSmith environment variables to your .env file:
# LangSmith Configuration (Optional)
LANGCHAIN_TRACING_V2=true
LANGCHAIN_ENDPOINT=https://api.smith.langchain.com
LANGCHAIN_API_KEY=your_langsmith_api_key_here
LANGCHAIN_PROJECT=article-rewriter-agentGetting Your LangSmith API Key:
- Sign up for a free account at https://smith.langchain.com
- Navigate to Settings → API Keys
- Create a new API key
- Copy the key to your
.envfile
Benefits of LangSmith:
- View all LLM requests and responses in real-time
- Monitor token usage and costs
- Debug agent workflow execution
- Track performance metrics
- Analyze prompt effectiveness
If LangSmith is not configured, the agent will work normally but without observability features.
python article_rewriter_agent.pyOr run as a module:
python -m article_rewriter_agentEdit the example_usage() function in the script to customize:
- URL: The source URL to extract content from
- Primary Keywords: Main SEO keywords for the article
- Secondary Keywords: Additional keywords (optional)
- Tone: Writing tone (e.g., "professional", "casual", "friendly")
- Target Word Count: Desired article length
- Readability Level: "easy", "intermediate", or "advanced"
- Target Audience: Description of the intended readers
- SEO Goals: Specific SEO objectives
Example:
result = await agent.process(
url="https://example.com/article",
primary_keywords=["keyword1", "keyword2"],
secondary_keywords=["keyword3"],
tone="professional",
target_word_count=1500,
readability_level="intermediate",
target_audience="Marketing professionals",
seo_goals="Rank for primary keywords",
)Results are automatically saved to the output folder in the same directory as the script:
{article-title}.md- Clean article content in markdown format (title-based filename){article-title}_info.txt- Article metadata, scores, and analysis
- When run as a script:
{script_directory}/output/ - When run as a module:
{current_working_directory}/output/
The output folder is automatically created if it doesn't exist.
Markdown File (.md):
- Contains only the cleaned article content
- No title, meta description, or formatting markers
- Ready for direct use or publishing
Info File (.txt):
- Article title and word count
- Meta description and character count
- Title variations
- Readability score and suggestions
- SEO score and suggestions
- Humanization details (engagement score, changes made, improvements)
The humanization step applies strict writing style guidelines:
SHOULD:
- Use clear, simple language
- Be spartan and informative
- Use short, impactful sentences
- Use active voice
- Focus on practical, actionable insights
- Use "you" and "your" to directly address readers
AVOID:
- Em dashes (—)
- Metaphors and clichés
- Generalizations
- Setup language (in conclusion, etc.)
- Unnecessary adjectives and adverbs
- Hashtags, semicolons, markdown, asterisks
- A comprehensive list of banned words
The agent requires:
langchain- Core LangChain frameworklangchain-openai- OpenAI integrationlanggraph- Graph-based agent orchestrationaiohttp- Async HTTP client for web scrapingbeautifulsoup4- HTML parsingpython-dotenv- Environment variable loading (optional)
All dependencies are listed in requirements.txt.
The agent provides detailed logging during execution:
- Node execution status
- Content extraction progress
- Article generation parameters
- Humanization progress
- Workflow completion status
All logs are printed to the console with clear visual indicators.
The agent includes comprehensive error handling:
- Invalid URL validation
- Content extraction errors
- Article generation failures
- Humanization errors
- File writing errors
Errors are logged and reported clearly, allowing for easy debugging.