|
1 | | -# LangGraph 101 |
| 1 | +# Deep Agents Travel Planner Workshop |
2 | 2 |
|
3 | | -Welcome to LangGraph 101! |
| 3 | +A hands-on, single-notebook walkthrough that builds a production-style travel planner agent from scratch using [Deep Agents](https://docs.langchain.com/oss/python/deepagents/overview) on top of LangChain and LangGraph. |
4 | 4 |
|
5 | | -## Introduction |
6 | | -This repository contains hands-on tutorials for learning LangChain, LangGraph, and Deep Agents, organized into two learning tracks: |
| 5 | +The notebook lives at `notebooks/deepagents-travel-planner.ipynb` and is designed to be worked through top-to-bottom in a guided session with a LangChain engineer. |
7 | 6 |
|
8 | | -- **101**: Fundamentals of building agents with LangChain and LangGraph |
9 | | -- **201**: Advanced patterns including multi-agent systems, deep agents, and production workflows |
| 7 | +## What You'll Build |
10 | 8 |
|
11 | | -To understand how these frameworks relate to each other, see [LangChain vs LangGraph vs Deep Agents](https://docs.langchain.com/oss/python/concepts/products). |
| 9 | +By the end of the notebook you'll have a travel planning agent that can: |
12 | 10 |
|
13 | | -This is a condensed version of LangChain Academy, intended to be run in a session with a LangChain engineer. If you're interested in going into more depth, or working through tutorials on your own, check out [LangChain Academy](https://academy.langchain.com/courses/intro-to-langgraph)! LangChain Academy has helpful pre-recorded videos from our LangChain engineers. |
| 11 | +- Plan a multi-day trip from a single user request |
| 12 | +- Delegate research to specialized subagents (`hotel-search`, `flight-search`, `activity-search`) running in parallel |
| 13 | +- Read and write files on a virtual filesystem (or on real disk) via `read_file` / `write_file` / `edit_file` |
| 14 | +- Pause for human approval before "booking" anything |
| 15 | +- Remember a traveler's preferences across conversations (per-user, with a shared global namespace) |
| 16 | +- Follow a team-authored `AGENTS.md` and load on-demand `SKILL.md` files for each deliverable (itinerary, budget, packing list, travel brief) |
| 17 | +- Emit a final itinerary and budget in your team's exact format |
14 | 18 |
|
15 | | -## What's Inside |
| 19 | +## Notebook Outline |
16 | 20 |
|
17 | | -### 101 - Fundamentals (`notebooks/101/`) |
18 | | -- **101_langchain_langgraph.ipynb**: Build your first agent with models, tools, memory, and streaming |
19 | | -- **102_middleware.ipynb**: Middleware, human-in-the-loop patterns, and guardrails |
| 21 | +The notebook is split into ten parts. Each part introduces one Deep Agents concept and adds one capability to the agent: |
20 | 22 |
|
21 | | -### 201 - Production Patterns (`notebooks/201/`) |
22 | | -- **email_agent.ipynb**: Build a stateful email triage and response agent |
23 | | -- **multi_agent.ipynb**: Multi-agent systems with supervisors and specialized sub-agents |
24 | | -- **research_agent.ipynb**: Deep research agent with parallel sub-researchers |
25 | | -- **deepagents.ipynb**: Build a research agent from scratch with DeepAgents -- covers AGENTS.md, skills, backends, long-term memory, HITL, and more |
| 23 | +| Part | Topic | What's introduced | |
| 24 | +| --- | --- | --- | |
| 25 | +| 0 | Setup & Installation | `uv sync`, `.env`, model config | |
| 26 | +| 1 | Your First Deep Agent | `create_deep_agent`, the harness, planner + virtual filesystem out of the box | |
| 27 | +| 2 | Adding Custom Tools | Domain tools for discovery, pricing, and availability | |
| 28 | +| 3 | Understanding Backends | `StateBackend`, `FilesystemBackend`, `CompositeBackend`, `StoreBackend` | |
| 29 | +| 4 | Adding Subagents | `hotel-search`, `flight-search`, `activity-search` + an orchestrator that fans out via `task()` | |
| 30 | +| 5 | Middleware Deep Dive | Inspecting `write_todos`, writing a `@wrap_tool_call` logger | |
| 31 | +| 6 | Human-in-the-Loop | `HumanInTheLoopMiddleware`, interrupts, `Command(resume=...)` | |
| 32 | +| 7 | Long-Term Memory | `StoreBackend` routed via `CompositeBackend`, per-user vs shared namespaces | |
| 33 | +| 8 | `AGENTS.md` & Skills | Identity file + on-demand `SKILL.md` files for each deliverable | |
| 34 | +| 9 | The Complete Travel Planner | All layers composed end-to-end | |
26 | 35 |
|
27 | | -### Agents (`agents/`) |
28 | | -Standalone agent implementations that run in LangGraph Studio via `langgraph dev`: |
29 | | -- **`agents/101/`** - Simple weather agent from the 101 notebook |
30 | | -- **`agents/email_agent/`** - Email triage agent |
31 | | -- **`agents/music_store/`** - Multi-agent music store (supervisor + subagents) |
32 | | -- **`agents/researcher/`** - Deep research agent with parallel sub-researchers |
33 | | -- **`agents/deep_agent/`** - DeepAgents research agent with AGENTS.md, skills (LinkedIn post, Twitter/X post), long-term memory, and HITL |
34 | | - |
35 | | -All notebooks use the latest **LangChain**, **LangGraph**, and **DeepAgents** primitives, including `create_agent()`, `create_deep_agent()`, middleware, and interrupt patterns. |
36 | | - |
37 | | -## Project Structure |
38 | | - |
39 | | -``` |
40 | | -langgraph-101/ |
41 | | -├── notebooks/ |
42 | | -│ ├── 101/ # Fundamentals |
43 | | -│ │ ├── 101_langchain_langgraph.ipynb |
44 | | -│ │ └── 102_middleware.ipynb |
45 | | -│ └── 201/ # Production Patterns |
46 | | -│ └── deep_agents.ipynb |
47 | | -│ ├── email_agent.ipynb |
48 | | -│ ├── multi_agent.ipynb |
49 | | -│ ├── research_agent.ipynb |
50 | | -
|
51 | | -├── agents/ # Standalone agents for LangGraph Studio |
52 | | -│ ├── 101/agent.py |
53 | | -│ ├── email_agent/graph.py |
54 | | -│ ├── music_store/ # Multi-agent supervisor + subagents |
55 | | -│ ├── researcher/ # Deep research agent |
56 | | -│ └── deep_agent/ # DeepAgents research agent |
57 | | -│ ├── agent.py # Agent definition |
58 | | -│ ├── AGENTS.md # Agent identity & instructions |
59 | | -│ └── skills/ # On-demand capabilities |
60 | | -│ ├── linkedin-post/SKILL.md |
61 | | -│ └── twitter-post/SKILL.md |
62 | | -├── utils/ |
63 | | -│ ├── models.py # Centralized model configuration |
64 | | -│ └── utils.py # Shared utilities |
65 | | -├── langgraph.json # Agent registry for langgraph dev |
66 | | -└── .env # API keys (not committed) |
67 | | -``` |
68 | | - |
69 | | -## Context |
70 | | - |
71 | | -At LangChain, we aim to make it easy to build LLM applications. One type of LLM application you can build is an agent. There's a lot of excitement around building agents because they can automate a wide range of tasks that were previously impossible. |
72 | | - |
73 | | -In practice though, it is incredibly difficult to build systems that reliably execute on these tasks. As we've worked with our users to put agents into production, we've learned that more control is often necessary. You might need an agent to always call a specific tool first or use different prompts based on its state. |
74 | | - |
75 | | -To tackle this problem, we've built [LangGraph](https://docs.langchain.com/oss/python/langgraph/overview) — a framework for building agent and multi-agent applications. Separate from the LangChain package, LangGraph's core design philosophy is to help developers add better precision and control into agent workflows, suitable for the complexity of real-world systems. |
76 | | - |
77 | | -For complex, multi-step tasks that require planning, filesystem access, and delegation, we've built [Deep Agents](https://docs.langchain.com/oss/python/deepagents/overview) — an agent harness on top of LangGraph that provides built-in tools, context management, and skills out of the box. |
| 36 | +Each part is independently runnable — you can stop at any layer and have a working agent for that scope. |
78 | 37 |
|
79 | 38 | ## Pre-work |
80 | 39 |
|
81 | | -### Clone the LangGraph 101 repo |
82 | | -``` |
83 | | -git clone https://github.com/langchain-ai/langgraph-101.git |
| 40 | +### Clone the repo |
| 41 | +```bash |
| 42 | +git clone <repo-url> |
| 43 | +cd deepagents-workshop |
84 | 44 | ``` |
85 | 45 |
|
86 | | - |
87 | | -### Create an environment |
88 | | -Ensure you have a recent version of pip and python installed |
89 | | -``` |
90 | | -$ cd langgraph-101 |
91 | | -# Copy the .env.example file to .env |
| 46 | +### Configure environment variables |
| 47 | +```bash |
92 | 48 | cp .env.example .env |
| 49 | +# Fill in your model + Tavily keys |
93 | 50 | ``` |
94 | | -If you run into issues with setting up the python environment or acquiring the necessary API keys due to any restrictions (ex. corporate policy), contact your LangChain representative and we'll find a work-around! |
95 | 51 |
|
96 | | -### Package Installation |
97 | | -Ensure you have a recent version of pip and python installed |
98 | | -``` |
| 52 | +If corporate policy blocks API keys, contact your LangChain representative and we'll find a workaround. |
| 53 | + |
| 54 | +### Install dependencies |
| 55 | +This project uses [`uv`](https://github.com/astral-sh/uv): |
| 56 | +```bash |
99 | 57 | # Install uv if you haven't already |
100 | 58 | pip install uv |
101 | 59 |
|
102 | | -# Install the package, allowing for pre-release |
| 60 | +# Install the project |
103 | 61 | uv sync |
104 | 62 |
|
105 | 63 | # Activate the virtual environment |
106 | 64 | source .venv/bin/activate |
107 | 65 | ``` |
108 | 66 |
|
109 | | -### Running Agents Locally |
110 | | - |
111 | | -You can run the agents in this repository locally using `langgraph dev`. This gives you: |
112 | | -- A local API server for your agents |
113 | | -- LangGraph Studio UI for testing and debugging |
114 | | -- Hot-reloading during development |
115 | | - |
116 | | -```bash |
117 | | -# From the root directory, start the LangGraph development server |
118 | | -langgraph dev |
119 | | - |
120 | | -# This will start a local server and provide: |
121 | | -# - API endpoint for your agents (typically http://localhost:2024) |
122 | | -# - LangGraph Studio UI link |
123 | | -``` |
124 | | - |
125 | | -The `langgraph.json` configuration file defines which agents are available. You can interact with agents via the API or through LangGraph Studio's visual interface. |
126 | | - |
127 | | -For more details, see the [LangGraph CLI documentation](https://docs.langchain.com/langsmith/cli#langgraph-cli). |
128 | | - |
129 | | -### Model Configuration |
| 67 | +## Running the Notebook |
130 | 68 |
|
131 | | -This repository uses a **centralized utils module** (`utils/`) to avoid code duplication. All model configurations and shared utilities are defined here: |
132 | | -- **`utils/models.py`** - LLM model initialization (OpenAI, Anthropic, Azure, Bedrock, Vertex AI) |
133 | | -- **`utils/utils.py`** - Shared utility functions (`show_graph`, `get_engine_for_chinook_db`) |
| 69 | +Open `notebooks/deepagents-travel-planner.ipynb` in Jupyter, PyCharm, or VS Code, select the workshop's `.venv` as the kernel, and run cells in order. |
134 | 70 |
|
135 | | -**Default**: OpenAI with `o3-mini` model. To switch providers, edit `utils/models.py` following the instructions below. |
| 71 | +## Model Configuration |
136 | 72 |
|
137 | | -**Note**: Notebooks automatically add the project root to Python's path, so they can import from `utils` regardless of which subdirectory they're in. |
| 73 | +Model selection is centralized in `utils/models.py`. The default is OpenAI; the file contains commented-out blocks for Azure OpenAI, AWS Bedrock, and Google Vertex AI — uncomment the section matching your provider and fill in the relevant env vars in `.env`. |
138 | 74 |
|
139 | | -### Azure OpenAI Instructions |
140 | | - |
141 | | -If you are using Azure OpenAI instead of OpenAI, follow these steps: |
142 | | - |
143 | | -1. **Set environment variables** in your `.env` file: |
144 | | - ``` |
145 | | - AZURE_OPENAI_API_KEY=your_api_key |
146 | | - AZURE_OPENAI_ENDPOINT=your_endpoint |
147 | | - AZURE_OPENAI_API_VERSION=2024-03-01-preview |
148 | | - ``` |
149 | | - |
150 | | -2. **Update `utils/models.py`**: |
151 | | - - Comment out the "Default Models" section (lines 20-28) |
152 | | - - Uncomment the "AZURE OpenAI Version" section (lines 31-57) |
153 | | - - Configure the `azure_deployment` name to match your deployment |
154 | | - |
155 | | -3. **Done!** All agents and notebooks will automatically use the Azure model |
156 | | - |
157 | | -### AWS Bedrock Instructions |
158 | | - |
159 | | -If you are using AWS Bedrock instead of OpenAI, follow these steps: |
160 | | - |
161 | | -1. **Set environment variables** in your `.env` file: |
162 | | - ``` |
163 | | - AWS_ACCESS_KEY_ID=your_access_key |
164 | | - AWS_SECRET_ACCESS_KEY=your_secret_key |
165 | | - AWS_REGION_NAME=us-east-1 |
166 | | - AWS_MODEL_ARN=your_model_arn |
167 | | - ``` |
168 | | - |
169 | | -2. **Update `utils/models.py`**: |
170 | | - - Comment out the "Default Models" section (lines 20-28) |
171 | | - - Uncomment the "Bedrock Version" section (lines 60-78) |
172 | | - - Configure the model settings as needed |
173 | | - |
174 | | -3. **Done!** All agents and notebooks will automatically use the Bedrock model |
175 | | - |
176 | | -### Google Vertex AI Instructions |
177 | | - |
178 | | -If you are using Google Vertex AI instead of OpenAI, follow these steps: |
179 | | - |
180 | | -1. **Set up Google Cloud credentials** |
181 | | - - Create a service account in your Google Cloud project with Vertex AI permissions |
182 | | - - Download the service account JSON key file |
183 | | - - Save it as `vertexCred.json` in the project root directory |
184 | | - |
185 | | -2. **Configure environment variables** in your `.env` file: |
186 | | - ``` |
187 | | - GOOGLE_APPLICATION_CREDENTIALS=./vertexCred.json |
188 | | - ``` |
189 | | - |
190 | | -3. **Update `utils/models.py`**: |
191 | | - - Comment out the "Default Models" section (lines 20-28) |
192 | | - - Uncomment the "Google Vertex AI version" section (lines 81-100) |
193 | | - - The setup automatically handles credential paths using `Path(__file__)` |
194 | | - |
195 | | -4. **Done!** All agents and notebooks will automatically use the Vertex AI model |
196 | | - |
197 | | -**Note:** Make sure `vertexCred.json` is added to your `.gitignore` to avoid committing credentials. |
198 | | - |
199 | | -## Getting Started |
200 | | - |
201 | | -### Recommended Learning Path |
202 | | - |
203 | | -1. **Start with 101** - `notebooks/101/` |
204 | | - - Begin with `101_langchain_langgraph.ipynb` to learn LangChain + LangGraph fundamentals |
205 | | - - Continue with `102_middleware.ipynb` for middleware and human-in-the-loop patterns |
| 75 | +### Azure OpenAI |
| 76 | +``` |
| 77 | +AZURE_OPENAI_API_KEY=... |
| 78 | +AZURE_OPENAI_ENDPOINT=... |
| 79 | +AZURE_OPENAI_API_VERSION=2024-03-01-preview |
| 80 | +``` |
206 | 81 |
|
207 | | -2. **Progress to 201** - `notebooks/201/` |
208 | | - - Explore `email_agent.ipynb` for a complete stateful agent example |
209 | | - - Build multi-agent systems with `multi_agent.ipynb` |
210 | | - - Learn Deep Agents with `deepagents.ipynb` -- progressively build a research agent with AGENTS.md, skills, backends, memory, and HITL |
| 82 | +### AWS Bedrock |
| 83 | +``` |
| 84 | +AWS_ACCESS_KEY_ID=... |
| 85 | +AWS_SECRET_ACCESS_KEY=... |
| 86 | +AWS_REGION_NAME=us-east-1 |
| 87 | +AWS_MODEL_ARN=... |
| 88 | +``` |
211 | 89 |
|
212 | | -3. **Run Agents in Studio** |
213 | | - - Use `langgraph dev` to launch all agents in LangGraph Studio |
214 | | - - Try the Deep Agent (`agents/deep_agent/`) -- ask it to research a topic and write a LinkedIn post |
| 90 | +### Google Vertex AI |
| 91 | +``` |
| 92 | +GOOGLE_APPLICATION_CREDENTIALS=./vertexCred.json |
| 93 | +``` |
| 94 | +Make sure `vertexCred.json` is in `.gitignore`. |
215 | 95 |
|
216 | | -### Resources |
| 96 | +## Resources |
217 | 97 |
|
218 | | -- **[LangChain Documentation](https://docs.langchain.com/oss/python/langchain/overview)** - Complete LangChain reference |
219 | | -- **[LangGraph Documentation](https://docs.langchain.com/oss/python/langgraph/overview)** - LangGraph guides and API reference |
220 | | -- **[Deep Agents Documentation](https://docs.langchain.com/oss/python/deepagents/)** - Deep Agents harness reference |
221 | | -- **[LangChain vs LangGraph vs Deep Agents](https://docs.langchain.com/oss/python/concepts/products)** - How the frameworks relate |
222 | | -- **[LangChain Academy](https://academy.langchain.com/)** - Free courses with video tutorials |
223 | | -- **[LangSmith](https://smith.langchain.com)** - Debugging and monitoring for LLM applications |
| 98 | +- **[Deep Agents Documentation](https://docs.langchain.com/oss/python/deepagents/)** — harness reference, backends, middleware |
| 99 | +- **[LangChain Documentation](https://docs.langchain.com/oss/python/langchain/overview)** — `create_agent`, tools, middleware |
| 100 | +- **[LangGraph Documentation](https://docs.langchain.com/oss/python/langgraph/overview)** — state, interrupts, `Store`, checkpointers |
| 101 | +- **[LangChain vs LangGraph vs Deep Agents](https://docs.langchain.com/oss/python/concepts/products)** — how the layers relate |
| 102 | +- **[LangSmith](https://smith.langchain.com)** — tracing and debugging the agent's tool calls and subagent fan-outs |
0 commit comments