LekhAI (derived from the Sanskrit word Lekh meaning "writing") is an advanced multi-agent system that orchestrates a team of AI personas to create high-quality, technically accurate blog posts.
Unlike standard "text generators," LekhAI doesn't just guess. It researches the live web, plans a strategic outline, drafts with context, and polishes the final output—mimicking a real-world editorial newsroom.
- 🤖 Multi-Agent Architecture: Four specialized agents (Researcher, Strategist, Writer, Editor) working in a coordinated sequence.
- 🌐 Live Web Access: The Research Agent uses DuckDuckGo Search to fetch real-time data, sources, and recent developments (no API key required).
- ⚡ Real-Time Streaming: Uses Server-Sent Events (SSE) to stream progress and content to the UI instantly.
- 🧠 Gemini Powered: Built on Google's Gemini 2.5 Flash (or 1.5 Flash) for high speed and low cost.
- 🎨 Modern UI: A clean, responsive interface built with Tailwind CSS and Glassmorphism design.
- 💾 Session History: Tracks and saves your past generations for easy retrieval.
- 📝 Markdown Support: Full rendering of headings, lists, and code blocks.
LekhAI uses a Sequential Coordinator pattern. The main application acts as the orchestrator, passing the state between agents.
graph LR
A[User Input] --> B(Coordinator)
B --> C{Research Agent}
C -- Tools: Web Search --> D[Live Internet]
D --> C
C -- Key Points --> E{Outline Agent}
E -- Structure --> F{Writing Agent}
F -- Draft --> G{Editing Agent}
G -- Final Blog --> H[User UI]
- 🔍 Researcher: Scours the web for 5-10 key facts and sources.
- 📋 Strategist: Converts raw facts into a logical, SEO-friendly outline.
- ✍️ Writer: Expands the outline into a full draft with code snippets and examples.
- ✨ Editor: Fixes grammar, adjusts tone, and ensures professional formatting.
Prerequisites
- Python 3.10 or higher
- Google Gemini API Key
- Clone the Repository
git clone https://github.com/Vrajesh-Sharma/Blog-Agent.git
cd LekhAI- Create a Virtual Environment
python -m venv venv
# Windows
venv\Scripts\activate
# Mac/Linux
source venv/bin/activate- Install Dependencies
pip install -r requirements.txt- Configure Environment Create a .env file in the root directory:
# Code snippet
GOOGLE_API_KEY=your_gemini_api_key_here
GEMINI_MODEL=gemini-2.5-flash # Recommended for speed- Run the Application
python app.py
Access the application at: http://127.0.0.1:5000LekhAI/
├── agents/ # The brains of the operation
│ ├── agent_base.py # Base class handling Gemini connections
│ ├── research_agent.py # Web searching logic
│ ├── outline_agent.py # Structuring logic
│ ├── writing_agent.py # Drafting logic
│ └── editing_agent.py # Polishing logic
├── tools/ # Capabilities given to agents
│ ├── google_search_tool.py # DuckDuckGo integration
│ └── create_outline_tool.py
├── templates/ # Frontend UI
│ ├── base.html # Layout and Tailwind setup
│ ├── index.html # Landing page
│ ├── generate.html # Streaming generation interface
│ └── history.html # Past blogs view
├── services/ # State management
│ ├── session_service.py
│ └── memory_service.py
├── app.py # Main Flask application & Coordinator
├── requirements.txt # Python dependencies
└── .env # API Keys (Hidden)You can switch between Gemini versions in your .env file.
-
Speed/Free Tier: gemini-2.5-flash or gemini-1.5-flash
-
High Quality: gemini-1.5-pro (Note: Lower rate limits may apply)
To change how an agent behaves (e.g., making the Writer more humorous), edit the system_instruction in the respective file under agents/.
Example (agents/writing_agent.py):
system_instruction=(
"You are a witty technical writer. Use analogies and humor..."
)- Cause: You are hitting the Gemini Free Tier rate limits (approx 15 requests/min).
- Fix: The system has built-in time.sleep(5) delays in app.py. If you still see this, increase the sleep time to 10 seconds.
- Cause: The model tried to use a tool but the code didn't handle the callback.
- Fix: Ensure agents/agent_base.py has enable_automatic_function_calling=True inside the chat session initiation.
- Cause: DuckDuckGo rate limiting.
- Fix: The tool catches this error gracefully. Try again in a few minutes or ensure your IP isn't blocked.
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the project
- Create your Feature Branch (git checkout -b feature/AmazingFeature)
- Commit your changes (git commit -m 'Add some AmazingFeature')
- Push to the Branch (git push origin feature/AmazingFeature)
- Open a Pull Request