An autonomous research agent that plans questions, searches for answers, analyzes findings, and synthesizes a full markdown report — with live progress streaming to the UI.
Built to run locally for free using Groq's OpenAI-compatible API.
- 🧠 4-phase agentic workflow: Planning → Searching → Analyzing → Synthesizing
- 📡 Real-time streaming via Server-Sent Events (SSE)
- 🎯 Three depth modes: Quick (3 questions), Standard (5), Deep (8)
- 💬 Chat with the generated report for follow-ups
- 📥 One-click Markdown export
- 🔌 Provider-agnostic: works with Groq, OpenRouter, Cerebras, or OpenAI
Backend
- Python 3.11 + FastAPI
- OpenAI Python SDK (used with Groq base_url)
- Uvicorn with reload
- python-dotenv
Frontend
- React 18
- Custom CSS (no UI framework)
- Native EventSource for SSE
AI Models (default)
- Fast tasks:
llama-3.1-8b-instant(Groq) - Report synthesis:
llama-3.3-70b-versatile(Groq)
[React UI]
|
| POST /research/stream
↓
[FastAPI + ResearchAgent]
|
| chat.completions.create
↓
[Groq API]
|
| JSON responses
↓
[FastAPI]
|
| SSE stream
↓
[React UI] ← live updates
- Python 3.9+
- Node.js 18+
- Free Groq API key from https://console.groq.com
cd backend
python -m venv venv
venv\Scripts\activate # Windows
# source venv/bin/activate # macOS/Linux
pip install -r requirements.txtCreate .env:
GROQ_API_KEY=gsk_xxxxxxxxxxxxxxxxxxxxxxxx
Start server:
uvicorn main:app --reload --port 8000cd frontend
npm install
npm startCreate backend/.env:
# Choose ONE provider
# Groq (recommended, free)
GROQ_API_KEY=gsk_...
# Optional: OpenAI (requires paid credits)
# OPENAI_API_KEY=sk-proj-...
# Optional: OpenRouter
# OPENROUTER_API_KEY=sk-or-...Edit backend/agent.py:
# Groq
self.client = AsyncOpenAI(
api_key=os.getenv("GROQ_API_KEY"),
base_url="https://api.groq.com/openai/v1"
)
# OpenRouter
# base_url="https://openrouter.ai/api/v1"
# OpenAI
# base_url="https://api.openai.com/v1"Also change model names at top of agent.py:
MODEL_FAST = "llama-3.1-8b-instant"
MODEL_SMART = "llama-3.3-70b-versatile"Starts a research job. Streams events.
Request
{
"topic": "quantum computing in drug discovery",
"depth": "standard",
"focus_areas": ["pharma", "2024 breakthroughs"]
}Response (SSE)
data: {"phase":"planning","status":"active","progress":5}
data: {"phase":"searching","status":"found","progress":35}
...
Ask follow-up questions.
Request
{
"message": "Summarize the key risks",
"session_id": "abc123",
"report_context": "...full markdown..."
}Returns {"status":"healthy"}
- Planning: Generates 3-8 specific research questions using MODEL_FAST
- Searching: Answers each question independently (parallelizable)
- Analyzing: Finds patterns, contradictions, and gaps across answers
- Synthesizing: Builds final report with MODEL_SMART using structured prompt
Depth controls token budget:
- quick: 800 tokens
- standard: 1500 tokens
- deep: 2500 tokens
ai-research-agent/
├── backend/
│ ├── main.py # FastAPI app, SSE endpoint
│ ├── agent.py # ResearchAgent class, 4-phase logic
│ ├── requirements.txt # fastapi, openai, python-dotenv, uvicorn
│ └──.env # your keys (gitignored)
└── frontend/
├── src/
│ ├── components/
│ │ └── ResearchAgent.js
│ ├── App.js
│ └── styles.css
├── public/
└── package.json
401 Incorrect API key
- Check
.envis inbackend/folder, not project root - Ensure
load_dotenv()runs before importing agent - Key must start with
gsk_for Groq
429 insufficient_quota
- You are still using OpenAI. Switch to Groq in agent.py
- Or add $5 credit at platform.openai.com
Model not found
- Groq does not have
gpt-4o-mini. Usellama-3.1-8b-instant - Check available models at console.groq.com/docs/models
Stream stops early
- Look at terminal for Python traceback
- Add try/except around
client.chat.completions.createto surface errors as SSE events
backend/requirements.txt:
fastapi==0.110.0
uvicorn[standard]==0.27.0
openai>=1.30.0
python-dotenv==1.0.1
httpx==0.26.0
MIT — free for personal and commercial use.
- Add source citations with real web search
- Save research history to SQLite
- Add provider fallback (Groq → Cerebras → OpenRouter)
- Docker compose for one-command start