# Repository: assafelovic/gpt-researcher # Stars: 26510 ## .cursorrules # Project Overview This project, named GPT-Researcher, LLM based autonomous agent that conducts local and web research on any topic and generates a comprehensive report with citations, is built using Next.js and TypeScript. It integrates various libraries for their strenghts. Your primary goal is to help with Next.js app router patterns, TypeScript type safety, Tailwind CSS best practices, code quality standards, and Python/FastAPI backend optimizations. # Key URLs - Project Home Page: https://gptr.dev/ - GitHub Repository: https://github.com/assafelovic/gpt-researcher - Documentation: https://docs.gptr.dev/ # Project Structure - Frontend user interface built with Next.js, TypeScript, and Tailwind CSS in `/frontend` - Static FastAPI version for lightweight deployments - Next.js version for production use with enhanced features - Multi-agent research system using LangChain and LangGraph in `/backend/multi_agents` - Browser, Editor, Researcher, Reviewer, Revisor, Writer, and Publisher agents - Task configuration and agent coordination - Document processing using Unstructured and PyMuPDF in `/backend/document_processing` - PDF, DOCX, and web content parsing - Text extraction and preprocessing - Report generation using LangChain and Jinja2 templates in `/backend/report_generation` - Template-based report structuring - Dynamic content formatting - Multiple output formats in `/backend/output_formats` - PDF via md2pdf - Markdown via mistune - DOCX via python-docx - Format conversion utilities - Export functionality - GPT Researcher core functionality in `/gpt_researcher` - Web scraping and content aggregation - Research planning and execution - Source validation and tracking - Query processing and response generation - Testing infrastructure in `/tests` - Unit tests for individual components - Integration tests for agent interactions - End-to-end research workflow tests - Mock data and fixtures for testing # Language Model Configuration - Default model: gpt-4-turbo - Alternative models: gpt-3.5-turbo, claude-3-opus - Temperature settings for different tasks - Context window management - Token limit handling - Cost optimization strategies # Error Handling - Research failure recovery - API rate limiting - Network timeout handling - Invalid input management - Source validation errors - Report generation failures # Performance - Parallel processing strategies - Caching mechanisms - Memory management - Response streaming - Resource allocation - Query optimization # Development Workflow - Branch naming conventions - Commit message format - PR review process - Testing requirements - Documentation updates - Version control guidelines # API Documentation - REST endpoints - WebSocket events - Request/Response formats - Authentication methods - Rate limits - Error codes # Monitoring - Performance metrics - Error tracking - Usage statistics - Cost monitoring - Research quality metrics - User feedback tracking # Frontend Components - Static FastAPI version for lightweight deployments - Next.js version for production use with enhanced features # Backend Components - Multi-agent system architecture - Document processing pipeline - Report generation system - Output format handlers # Core Research Components - Web scraping and aggregation - Research planning and execution - Source validation - Query processing # Testing - Unit tests - Integration tests - End-to-end tests - Performance testing # Rule Violation Monitoring - Alert developer when changes conflict with project structure - Warn about deviations from coding standards - Flag unauthorized framework or library additions - Monitor for security and performance anti-patterns - Track API usage patterns that may violate guidelines - Report TypeScript strict mode violations - Identify accessibility compliance issues # Development Guidelines - Use TypeScript with strict mode enabled - Follow ESLint and Prettier configurations - Ensure components are responsive and accessible - Use Tailwind CSS for styling, following the project's design system - Minimize AI-generated comments, prefer self-documenting code - Follow React best practices and hooks guidelines - Validate all user inputs and API responses - Use existing components as reference implementations # Important Scripts - `npm run dev`: Start development server - `npm run build`: Build for production - `npm run test`: Run test suite - `python -m pytest`: Run Python tests - `docker-compose up`: Start all services - `docker-compose run gpt-researcher-tests`: Run test suite in container - `python -m uvicorn backend.server.server:app --host=0.0.0.0 --port=8000`: Start FastAPI server - `python -m uvicorn backend.server.server:app --reload`: Start FastAPI server with auto-reload for development - `python main.py`: Run the main application directly # AI Integration Guidelines - Prioritize type safety in all AI interactions - Follow LangChain and LangGraph best practices - Implement proper error handling for AI responses - Maintain context window limits - Handle rate limiting and API quotas - Validate AI outputs before processing - Log AI interactions for debugging # Lexicon - **GPT Researcher**: Autonomous research agent system - **Multi-Agent System**: Coordinated AI agents for research tasks - **Research Pipeline**: End-to-end research workflow - **Agent Roles**: Browser, Editor, Researcher, Reviewer, Revisor, Writer, Publisher - **Source Validation**: Verification of research sources - **Report Generation**: Process of creating final research output # Additional Resources - [Next.js Documentation](https://nextjs.org/docs) - [TypeScript Handbook](https://www.typescriptlang.org/docs/) - [Tailwind CSS Documentation](https://tailwindcss.com/docs) - [LangChain Documentation](https://python.langchain.com/docs/) - [FastAPI Documentation](https://fastapi.tiangolo.com/) - [Project Documentation](https://docs.gptr.dev/) End all your comments with a :-) symbol. ## README.md
Logo #### [![Website](https://img.shields.io/badge/Official%20Website-gptr.dev-teal?style=for-the-badge&logo=world&logoColor=white&color=0891b2)](https://gptr.dev) [![Documentation](https://img.shields.io/badge/Documentation-DOCS-f472b6?logo=googledocs&logoColor=white&style=for-the-badge)](https://docs.gptr.dev) [![Discord](https://img.shields.io/discord/1127851779011391548?logo=discord&logoColor=white&label=Discord&color=34b76a&style=for-the-badge)](https://discord.gg/QgZXvJAccX) [![PyPI version](https://img.shields.io/pypi/v/gpt-researcher?logo=pypi&logoColor=white&style=flat)](https://badge.fury.io/py/gpt-researcher) ![GitHub Release](https://img.shields.io/github/v/release/assafelovic/gpt-researcher?style=flat&logo=github) [![Open In Colab](https://img.shields.io/static/v1?message=Open%20in%20Colab&logo=googlecolab&labelColor=grey&color=yellow&label=%20&style=flat&logoSize=40)](https://colab.research.google.com/github/assafelovic/gpt-researcher/blob/master/docs/docs/examples/pip-run.ipynb) [![Docker Image Version](https://img.shields.io/docker/v/elestio/gpt-researcher/latest?arch=amd64&style=flat&logo=docker&logoColor=white&color=1D63ED)](https://hub.docker.com/r/gptresearcher/gpt-researcher) [![Skill](https://img.shields.io/badge/Claude%20Skill-skills.sh-blueviolet?style=flat&logo=anthropic&logoColor=white)](https://skills.sh/assafelovic/gpt-researcher/gpt-researcher) [![Twitter Follow](https://img.shields.io/twitter/follow/assaf_elovic?style=social)](https://twitter.com/assaf_elovic) [English](README.md) | [中文](README-zh_CN.md) | [日本語](README-ja_JP.md) | [한국어](README-ko_KR.md)
# 🔎 GPT Researcher **GPT Researcher the first open deep research agent designed for both web and local research on any given task.** The agent produces detailed, factual, and unbiased research reports with citations. GPT Researcher provides a full suite of customization options to create tailor made and domain specific research agents. Inspired by the recent [Plan-and-Solve](https://arxiv.org/abs/2305.04091) and [RAG](https://arxiv.org/abs/2005.11401) papers, GPT Researcher addresses misinformation, speed, determinism, and reliability by offering stable performance and increased speed through parallelized agent work. **Our mission is to empower individuals and organizations with accurate, unbiased, and factual information through AI.** ## Why GPT Researcher? - Objective conclusions for manual research can take weeks, requiring vast resources and time. - LLMs trained on outdated information can hallucinate, becoming irrelevant for current research tasks. - Current LLMs have token limitations, insufficient for generating long research reports. - Limited web sources in existing services lead to misinformation and shallow results. - Selective web sources can introduce bias into research tasks. ## Demo Demo video ## Install as Claude Skill Extend Claude's deep research capabilities by installing GPT Researcher as a [Claude Skill](https://skills.sh/assafelovic/gpt-researcher/gpt-researcher): ```bash npx skills add assafelovic/gpt-researcher ``` Once installed, Claude can leverage GPT Researcher's deep research capabilities directly within your conversations. ## Architecture The core idea is to utilize 'planner' and 'execution' agents. The planner generates research questions, while the execution agents gather relevant information. The publisher then aggregates all findings into a comprehensive report.
Steps: * Create a task-specific agent based on a research query. * Generate questions that collectively form an objective opinion on the task. * Use a crawler agent for gathering information for each question. * Summarize and source-track each resource. * Filter and aggregate summaries into a final research report. ## Tutorials - [How it Works](https://docs.gptr.dev/blog/building-gpt-researcher) - [How to Install](https://www.loom.com/share/04ebffb6ed2a4520a27c3e3addcdde20?sid=da1848e8-b1f1-42d1-93c3-5b0b9c3b24ea) - [Live Demo](https://www.loom.com/share/6a3385db4e8747a1913dd85a7834846f?sid=a740fd5b-2aa3-457e-8fb7-86976f59f9b8) ## Features - 📝 Generate detailed research reports using web and local documents. - 🖼️ Smart image scraping and filtering for reports. - 🍌 **AI-generated inline images** using Google Gemini (Nano Banana) for visual illustrations. - 📜 Generate detailed reports exceeding 2,000 words. - 🌐 Aggregate over 20 sources for objective conclusions. - 🖥️ Frontend available in lightweight (HTML/CSS/JS) and production-ready (NextJS + Tailwind) versions. - 🔍 JavaScript-enabled web scraping. - 📂 Maintains memory and context throughout research. - 📄 Export reports to PDF, Word, and other formats. ## 📖 Documentation See the [Documentation](https://docs.gptr.dev/docs/gpt-researcher/getting-started) for: - Installation and setup guides - Configuration and customization options - How-To examples - Full API references ## ⚙️ Getting Started ### Installation 1. Install Python 3.11 or later. [Guide](https://www.tutorialsteacher.com/python/install-python). 2. Clone the project and navigate to the directory: ```bash git clone https://github.com/assafelovic/gpt-researcher.git cd gpt-researcher ``` 3. Set up API keys by exporting them or storing them in a `.env` file. ```bash export OPENAI_API_KEY={Your OpenAI API Key here} export TAVILY_API_KEY={Your Tavily API Key here} ``` (Optional) For enhanced tracing and observability, you can also set: ```bash # export LANGCHAIN_TRACING_V2=true # export LANGCHAIN_API_KEY={Your LangChain API Key here} ``` For custom OpenAI-compatible APIs (e.g., local models, other providers), you can also set: ```bash export OPENAI_BASE_URL={Your custom API base URL here} ``` 4. Install dependencies and start the server: ```bash pip install -r requirements.txt python -m uvicorn main:app --reload ``` Visit [http://localhost:8000](http://localhost:8000) to start. For other setups (e.g., Poetry or virtual environments), check the [Getting Started page](https://docs.gptr.dev/docs/gpt-researcher/getting-started). ## Run as PIP package ```bash pip install gpt-researcher ``` ### Example Usage: ```python ... from gpt_researcher import GPTResearcher query = "why is Nvidia stock going up?" researcher = GPTResearcher(query=query) # Conduct research on the given query research_result = await researcher.conduct_research() # Write the report report = await researcher.write_report() ... ``` **For more examples and configurations, please refer to the [PIP documentation](https://docs.gptr.dev/docs/gpt-researcher/gptr/pip-package) page.** ### 🔧 MCP Client GPT Researcher supports MCP integration to connect with specialized data sources like GitHub repositories, databases, and custom APIs. This enables research from data sources alongside web search. ```bash export RETRIEVER=tavily,mcp # Enable hybrid web + MCP research ``` ```python from gpt_researcher import GPTResearcher import asyncio import os async def mcp_research_example(): # Enable MCP with web search os.environ["RETRIEVER"] = "tavily,mcp" researcher = GPTResearcher( query="What are the top open source web research agents?", mcp_configs=[ { "name": "github", "command": "npx", "args": ["-y", "@modelcontextprotocol/server-github"], "env": {"GITHUB_TOKEN": os.getenv("GITHUB_TOKEN")} } ] ) research_result = await researcher.conduct_research() report = await researcher.write_report() return report ``` > For comprehensive MCP documentation and advanced examples, visit the [MCP Integration Guide](https://docs.gptr.dev/docs/gpt-researcher/retrievers/mcp-configs). ## 🍌 Inline Image Generation GPT Researcher can automatically generate and embed AI-created illustrations in your research reports using Google's Gemini models (Nano Banana). ```bash # Enable in your .env file IMAGE_GENERATION_ENABLED=true GOOGLE_API_KEY=your_google_api_key IMAGE_GENERATION_MODEL=models/gemini-2.5-flash-image ``` When enabled, the system will: 1. Analyze your research context to identify visualization opportunities 2. Pre-generate 2-3 relevant images during the research phase 3. Embed them inline as the report is written Images are generated with dark-mode styling that matches the GPT Researcher UI, featuring professional infographic aesthetics with teal accents. [Learn more about Image Generation](https://docs.gptr.dev/docs/gpt-researcher/gptr/image_generation) in our documentation. ## ✨ Deep Research GPT Researcher now includes Deep Research - an advanced recursive research workflow that explores topics with agentic depth and breadth. This feature employs a tree-like exploration pattern, diving deeper into subtopics while maintaining a comprehensive view of the research subject. - 🌳 Tree-like exploration with configurable depth and breadth - ⚡️ Concurrent processing for faster results - 🤝 Smart context management across research branches - ⏱️ Takes ~5 minutes per deep research - 💰 Costs ~$0.4 per research (using `o3-mini` on "high" reasoning effort) [Learn more about Deep Research](https://docs.gptr.dev/docs/gpt-researcher/gptr/deep_research) in our documentation. ## Run with Docker > **Step 1** - [Install Docker](https://docs.gptr.dev/docs/gpt-researcher/getting-started/getting-started-with-docker) > **Step 2** - Clone the '.env.example' file, add your API Keys to the cloned file and save the file as '.env' > **Step 3** - Within the docker-compose file comment out services that you don't want to run with Docker. ```bash docker-compose up --build ``` If that doesn't work, try running it without the dash: ```bash docker compose up --build ``` > **Step 4** - By default, if you haven't uncommented anything in your docker-compose file, this flow will start 2 processes: - the Python server running on localhost:8000
- the React app running on localhost:3000
Visit localhost:3000 on any browser and enjoy researching! ## 📄 Research on Local Documents You can instruct the GPT Researcher to run research tasks based on your local documents. Currently supported file formats are: PDF, plain text, CSV, Excel, Markdown, PowerPoint, and Word documents. Step 1: Add the env variable `DOC_PATH` pointing to the folder where your documents are located. ```bash export DOC_PATH="./my-docs" ``` Step 2: - If you're running the frontend app on localhost:8000, simply select "My Documents" from the "Report Source" Dropdown Options. - If you're running GPT Researcher with the [PIP package](https://docs.tavily.com/guides/gpt-researcher/gpt-researcher#pip-package), pass the `report_source` argument as "local" when you instantiate the `GPTResearcher` class [code sample here](https://docs.gptr.dev/docs/gpt-researcher/context/tailored-research). ## 🤖 MCP Server We've moved our MCP server to a dedicated repository: [gptr-mcp](https://github.com/assafelovic/gptr-mcp). The GPT Researcher MCP Server enables AI applications like Claude to conduct deep research. While LLM apps can access web search tools with MCP, GPT Researcher MCP delivers deeper, more reliable research results. Features: - Deep research capabilities for AI assistants - Higher quality information with optimized context usage - Comprehensive results with better reasoning for LLMs - Claude Desktop integration For detailed installation and usage instructions, please visit the [official repository](https://github.com/assafelovic/gptr-mcp). ## 👪 Multi-Agent Assistant As AI evolves from prompt engineering and RAG to multi-agent systems, we're excited to introduce multi-agent assistants built with [LangGraph](https://python.langchain.com/v0.1/docs/langgraph/) and [AG2](https://github.com/ag2ai/ag2). By using multi-agent frameworks, the research process can be significantly improved in depth and quality by leveraging multiple agents with specialized skills. Inspired by the recent [STORM](https://arxiv.org/abs/2402.14207) paper, this project showcases how a team of AI agents can work together to conduct research on a given topic, from planning to publication. An average run generates a 5-6 page research report in multiple formats such as PDF, Docx and Markdown. Check it out [here](https://github.com/assafelovic/gpt-researcher/tree/master/multi_agents) or head over to our documentation for [LangGraph](https://docs.gptr.dev/docs/gpt-researcher/multi_agents/langgraph) and [AG2](https://docs.gptr.dev/docs/gpt-researcher/multi_agents/ag2) for more information. ## 🔍 Observability GPT Researcher supports **LangSmith** for enhanced tracing and observability, making it easier to debug and optimize complex multi-agent workflows. To enable tracing: 1. Set the following environment variables: ```bash export LANGCHAIN_TRACING_V2=true export LANGCHAIN_API_KEY=your_api_key export LANGCHAIN_PROJECT="gpt-researcher" ``` 2. Run your research tasks as usual. All LangGraph-based agent interactions will be automatically traced and visualized in your LangSmith dashboard. ## 🖥️ Frontend Applications GPT-Researcher now features an enhanced frontend to improve the user experience and streamline the research process. The frontend offers: - An intuitive interface for inputting research queries - Real-time progress tracking of research tasks - Interactive display of research findings - Customizable settings for tailored research experiences Two deployment options are available: 1. A lightweight static frontend served by FastAPI 2. A feature-rich NextJS application for advanced functionality For detailed setup instructions and more information about the frontend features, please visit our [documentation page](https://docs.gptr.dev/docs/gpt-researcher/frontend/introduction). ## 🚀 Contributing We highly welcome contributions! Please check out [contributing](https://github.com/assafelovic/gpt-researcher/blob/master/CONTRIBUTING.md) if you're interested. Please check out our [roadmap](https://trello.com/b/3O7KBePw/gpt-researcher-roadmap) page and reach out to us via our [Discord community](https://discord.gg/QgZXvJAccX) if you're interested in joining our mission. ## ✉️ Support / Contact us - [Community Discord](https://discord.gg/spBgZmm3Xe) - Author Email: assaf.elovic@gmail.com ## 🛡 Disclaimer This project, GPT Researcher, is an experimental application and is provided "as-is" without any warranty, express or implied. We are sharing codes for academic purposes under the Apache 2 license. Nothing herein is academic advice, and NOT a recommendation to use in academic or research papers. Our view on unbiased research claims: 1. The main goal of GPT Researcher is to reduce incorrect and biased facts. How? We assume that the more sites we scrape the less chances of incorrect data. By scraping multiple sites per research, and choosing the most frequent information, the chances that they are all wrong is extremely low. 2. We do not aim to eliminate biases; we aim to reduce it as much as possible. **We are here as a community to figure out the most effective human/llm interactions.** 3. In research, people also tend towards biases as most have already opinions on the topics they research about. This tool scrapes many opinions and will evenly explain diverse views that a biased person would never have read. ---

Star History Chart

⬆️ Back to Top