This repository demonstrates the use of LangGraph to build modular, graph-based AI agent systems in Python. It includes agent implementations, utilities, tutorials, and exercises for learning and extending agentic workflows.
- Project Structure
- Installation
- Configuration
- Agents Overview
- Utilities
- Tutorials
- Exercises
- How to Run
- License
langgraph/
│
├── agents/
│ ├── 1_simple_bot.ipynb # Basic conversational agent (notebook)
│ ├── 2_chatbot_with_memory.py # Chatbot with memory (Python script)
│ ├── 3_react_agent.py # React agent with tool use
│ ├── 4_drafter_agent.py # Human-in-the-loop document drafter
│ ├── 5_rag_agent.py # Retrieval-Augmented Generation agent
│ ├── utils/
│ │ ├── __init__.py
│ │ └── settings.py # Centralized settings/configuration
│ ├── chroma.sqlite3 # Chroma vector DB for RAG agent
│ └── market-infographic-recap-2024.pdf # Example PDF for RAG agent
│
├── tutorials/ # Step-by-step LangGraph tutorials
│ ├── 1_ hello_world.ipynb
│ ├── 2_multiple_inputs.ipynb
│ ├── 3_sequential_graph.ipynb
│ ├── 4_conditional_graph.ipynb
│ └── 5_looping_graph.ipynb
│
├── exercises/ # Practice exercises for LangGraph
│ ├── exercise_graph1.ipynb
│ ├── exercise_graph2.ipynb
│ ├── exercise_graph3.ipynb
│ ├── exercise_graph4.ipynb
│ └── exercise_graph5.ipynb
│
├── requirements.txt # Python dependencies
└── README.md # Project documentation
-
Clone the repository:
git clone https://github.com/ankitprasad81/langgraph.git cd langgraph
-
Create and activate a virtual environment:
python -m venv .venv .\.venv\Scripts\Activate -
Install dependencies:
pip install -r requirements.txt
- Copy
.env.exampleto.envand fill in your API keys (e.g., for Groq, HuggingFace, etc.). - The main configuration is in
agents/utils/settings.pyand uses pydantic-settings.
Example .env:
GROQ_API_KEY=your_groq_api_key
- A basic conversational agent using LangGraph and ChatGroq.
- Demonstrates message handling and graph compilation.
- Maintains full conversation history using both
HumanMessageandAIMessage. - Saves conversation logs to
logging.txt. - Run with:
python agents\2_chatbot_with_memory.py
- Demonstrates tool use (add, subtract, multiply) within a graph.
- Uses conditional edges to decide when to call tools or finish.
- Run with:
python agents\3_react_agent.py
- Human-in-the-loop document drafting agent.
- Supports updating and saving documents via tool calls.
- Run with:
python agents\4_drafter_agent.py
- Retrieval-Augmented Generation agent.
- Loads a PDF, chunks it, creates a Chroma vector store, and answers questions using retrieval.
- Requires
market-infographic-recap-2024.pdfin theagents/directory. - Run with:
python agents\5_rag_agent.py
agents/utils/settings.py: Centralized settings using Pydantic. Reads from.env.agents/chroma.sqlite3: Vector database for document retrieval (used by RAG agent).
The tutorials/ folder contains step-by-step Jupyter notebooks covering:
- Hello World: Basic graph and node setup.
- Multiple Inputs: Handling multiple state fields.
- Sequential Graph: Chaining nodes in sequence.
- Conditional Graph: Routing based on state.
- Looping Graph: Implementing loops in the graph.
Open and run these notebooks in Jupyter or VS Code to learn LangGraph concepts.
The exercises/ folder provides hands-on practice with:
- State management
- Node creation
- Conditional logic
- Looping
- Multi-step workflows
Each exercise is a Jupyter notebook with a task description and starter code.
- For Python scripts:
python agents\<script_name>.py
- For Jupyter notebooks:
Open in VS Code or JupyterLab and run cells interactively.
This project is for educational and research purposes.
Note:
- Make sure you have the required API keys and dependencies.
- For Windows, all commands are provided in PowerShell syntax.