Skip to content

Kallappa2005/Researcher_and_AiAgent_For_Blog_Writing

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Blog Writing Agent (Researcher + AI Agent)

This repository contains a production-ready research-driven blog writing agent that turns a user topic into a publishable markdown blog with supporting images.

Overview

The system implements a conservative, token-aware pipeline that reliably produces a blog even when LLM rate limits are reached. High-level flow:

  • Start: user supplies a topic and an as_of date.
  • Router: quickly decides whether external research is needed and picks a mode (closed_book, hybrid, open_book).
  • Research (optional): runs web searches (Tavily) and extracts a small, high-signal evidence pack.
  • Orchestrator: creates a 4–6 task plan (title, audience, tone, tasks).
  • Worker(s): sequentially generate section markdown for each task (serialized to avoid token bursts).
  • Reducer (merge_content -> decide_images -> generate_and_place_images): merge sections, plan images, generate images, and write final markdown.
  • End: final markdown file is written (in working directory) and images are saved to images/.

Key features

  • Conservative token budgets and caps to avoid per-minute and per-day quota spikes.
  • Groq LLM integration via langchain-groq with graceful fallback when daily TPD limits are hit (the app will still produce a blog + fallback visuals).
  • Research via Tavily (optional; requires TAVILY_API_KEY).
  • Free image generation using Pollinations (no API key required) with a local SVG fallback when image generation fails.
  • Streamlit frontend for running the app interactively (bwa_frontend.py).
  • Generates a .md file per blog and writes images to images/.

Tech stack

  • Python 3.10+ (Conda environment: bwa)
  • LangGraph (graph orchestration)
  • LangChain + langchain-core
  • Groq LLM via langchain-groq (primary LLM)
  • Tavily search via langchain-tavily (web search)
  • Pollinations image generation (https://image.pollinations.ai) for cost-free images
  • Streamlit frontend (bwa_frontend.py)
  • Utilities: pydantic, python-dotenv, pandas

Files of interest

  • bwa_backend.py — main graph and node implementations (router, research, orchestrator, worker, reducer).
  • bwa_frontend.py — Streamlit UI for running the agent and previewing output.
  • requirements.txt — recommended Python packages (see langchain-tavily addition).
  • images/ — generated images are written here at runtime.
  • screenshots/ — example visuals used in this README (embedded below).

Environment & usage

  1. Create or activate the bwa conda environment.
conda activate bwa
pip install -r requirements.txt
  1. Add a .env file in the project root with the following (if you use Groq/Tavily):
GROQ_API_KEY=your_groq_api_key_here
TAVILY_API_KEY=your_tavily_api_key_here  # optional, for open_book/hybrid modes
  1. Run the Streamlit frontend:
streamlit run bwa_frontend.py

Outputs

  • A markdown file is written for each generated blog (filename derived from the title) in the repository root.
  • Images are written into the images/ folder. If Pollinations returns non-image content or is unreachable, the agent writes an auto-generated SVG fallback visual for each planned image so the markdown remains complete.

Design notes

  • The router is intentionally lightweight and low-token to decide whether research is necessary.
  • Workers are executed sequentially (worker_loop_node) to avoid parallel LLM calls and reduce tokens-per-minute usage.
  • When the Groq daily token hard cap (TPD) is reached, the system falls back to an internal plan + section renderers so you still get a coherent, actionable blog and images.

Screenshots

Below are the screenshots included in the screenshots/ folder (displayed in serial order):

  1. Image 1

Image 1

  1. Image 2

Image 2

  1. Image 3

Image 3

  1. Image 4

Image 4

  1. Image 5

Image 5

  1. Image 6

Image 6

  1. Image 7

Image 7

Troubleshooting

  • If you see repeated Conda warnings about C:\\Users\\<you>\\.condarc, fix or remove that file — it does not affect the app but produces noise in terminal output.
  • If Groq returns 429/day-limit errors, the agent will fall back and continue producing content; to avoid this, upgrade your Groq plan or reduce usage.

Contributing

If you want to improve planning prompts, image prompts, or add alternative image providers, modify bwa_backend.py and adjust the prompt templates and the _pollinations_generate_image_bytes implementation.

License & contact

This project is provided as-is. For questions or improvements, open an issue or contact the maintainer.

About

Started Agentic Ai

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors