This is an autonomous AI Research Agent built using LangGraph, LangChain, and Tavily. The agent starts with a broad topic, devises specific sub-questions, autonomously searches the web for answers, evaluates if its findings are sufficient (looping for more context if not), and finally compiles a comprehensive Markdown report.
The cyclical agent logic is powered by LangGraph. Below is a high-level representation of the state machine:
graph TD
Start((Start)) --> generate_questions[Generate Questions]
generate_questions --> conduct_research[Conduct Research]
conduct_research --> evaluate_research{Evaluate Findings}
evaluate_research -- "NEEDS_MORE_RESEARCH" --> conduct_research
evaluate_research -- "SUFFICIENT" --> compile_report[Compile Report]
compile_report --> End((End))
classDef default fill:#e3f2fd,stroke:#1565c0,stroke-width:2px,color:#000;
classDef decision fill:#fff3e0,stroke:#ef6c00,stroke-width:2px,color:#000;
class generate_questions,conduct_research,compile_report default;
class evaluate_research decision;
Follow these steps to set up and run the Research Agent on a new machine.
Ensure you have Python 3.10+ installed on your system.
Open a terminal, navigate into the research_agent/ directory, and initialize a virtual environment:
python3 -m venv venvActivate the virtual environment:
# On macOS / Linux:
source venv/bin/activate
# On Windows:
venv\Scripts\activateInstall all required modules such as LangGraph and Tavily via pip:
pip install -r requirements.txtThe application requires credentials to work properly. Create a new .env file in the root of the research_agent/ folder:
touch .envOpen the .env file and insert the following keys using your own credentials:
TAVILY_API_KEY="your_tavily_api_key_here"
OPENAI_API_KEY="your_openai_api_key_here"(You can get a Tavily key from tavily.com and an OpenAI key from platform.openai.com)
Run the main script to orchestrate the nodes and begin researching! You can edit the initial_state target topic found in main.py to change the research question.
python3 main.pyThe resulting findings will be autonomously compiled and saved to research_report.md.