A Perplexity-like research agent built with Gemini 2.0 and LangGraph. This application acts like perplexity.ai by breaking down a query into subtasks, researching each one using web search, and then synthesizing a comprehensive answer.
This project is organized into three implementations:
-
perplexity-agent/: The Streamlit implementation (easy to run and visualize the process)app.py: The Streamlit UI for the agentagent.py: Core agent logic using LangGraph
-
fastapi-react/: The FastAPI + React implementation (production-like setup)fastapi_backend/: Backend implementation with FastAPIfastapi_app.py: API server that handles query processing
react_frontend/: Frontend implementation with Reactsrc/: React source codepublic/: Public assets
-
langgraph_examples/: Example implementations of LangGraph concepts
- Task Decomposition: Breaks down complex queries into simpler subtasks
- Web Research: Researches each subtask using Gemini 2.0's web search capabilities
- Answer Synthesis: Synthesizes a final answer based on all research findings
- Real-time Feedback: Shows the process of research as it happens (in Streamlit version)
- Clean UI: Provides a clean, user-friendly interface in both implementations
- Python 3.7+
- Node.js and npm (for the React implementation)
- Google API key with access to Gemini 2.0
- Clone the repository:
git clone <repository-url>
cd build-with-ai- Create and activate a virtual environment:
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate- Install Python dependencies:
pip install -r requirements.txt- Create a
.envfile in the root directory with your Google API key:
GOOGLE_API_KEY=your_api_key_here
The Streamlit implementation provides a simple, interactive UI that shows the research process in real-time:
cd perplexity-agent
streamlit run app.pyThis will start the Streamlit app, which you can access at http://localhost:8501.
- Enter your query in the input field
- Click "Send Query"
- Watch as the agent:
- Breaks down your query into subtasks
- Researches each subtask one by one
- Synthesizes a final answer
- Review the results in the expandable sections
- Start a new search by clicking "New Search" or entering a new query
The FastAPI + React implementation provides a more production-like setup:
- Start the FastAPI backend:
cd fastapi-react/fastapi_backend
uvicorn fastapi_app:app --reload- In a new terminal, install the React frontend dependencies and start the server:
cd fastapi-react/react_frontend
npm install
npm startThis will start the React app, which you can access at http://localhost:3000.
The agent follows a four-step process powered by LangGraph:
- Decompose: Breaks down the user query into smaller, focused subtasks
- Route: Determines which subtask to process next
- Research: Uses Gemini 2.0 with web search capability to research the current subtask
- Synthesize: Combines all research results to generate a comprehensive final answer
The LangGraph-powered agent architecture provides:
- Structured Workflow: Clear steps for processing complex queries
- Modular Design: Separation of concerns between different stages of processing
- Callback-Based UI Updates: Real-time feedback as processing happens
- State Management: Tracking of subtasks, results, and progress
This project was created for the "Build with AI: Building a Perplexity Agent using Gemini 2.0 and LangGraph" workshop at EMSI Casablanca GDGOnCampus.
Created by Mohamed Wahib ABKARI & Anass Amazzar | GDGOnCampus EMSI Casablanca