Skip to content

TCLee/agent-langgraph

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build an Agent with LangGraph

Overview

By themselves, language models can't take actions - they just output text. A big use case for LangChain is creating agents. Agents are systems that use an LLM as a reasoning engine to determine which actions to take and what the inputs to those actions should be. The results of those actions can then be fed back into the agent and it determines whether more actions are needed, or whether it is okay to finish.

LangGraph is an extension of LangChain specifically aimed at creating highly controllable and customizable agents.

In the notebook we will build an agent that can interact with a search engine. You will be able to ask this agent questions, watch it call the search tool, and have conversations with it.

The code in the notebook is adapted from the LangGraph tutorial: Introduction to LangGraph.

Setup

Git

Clone this repository to your local computer by running:

git clone https://github.com/TCLee/agent-langgraph

Conda

  1. You will need conda in order to install the required packages to run the notebook. Installing conda.

  2. Make sure the current working directory is this cloned project's directory:

    cd /path/to/agent-langgraph
  3. Create the environment from the environment.yml file:

    conda env create -f environment.yml -p ./env

    This will create a new environment in a subdirectory of the project directory called env, (i.e., agent-langgraph/env)

  4. Activate the environment:

    conda activate ./env

Environment variables

This project makes use of python-dotenv to load in the environment variables from a .env file.

Create a .env file in the root directory of this cloned repository (i.e., agent-langgraph/.env):

# Google Gemini API
GOOGLE_API_KEY="your-google-secret-key"

# Tavily Search API
TAVILY_API_KEY="your-tavily-secret-key"

# Optional. Recommended to see what's going on 
# under the hood of LangGraph and LangChain.
LANGSMITH_API_KEY="your-langsmith-secret-key"
LANGCHAIN_TRACING_V2="true"
LANGCHAIN_PROJECT="LangGraph Tutorial"

Fill it in with your own API keys.

Google Gemini

The LLM that we will use in the notebook is Google's Gemini 1.5 Flash, since it offers a free tier for us to play around with.

To use the Gemini API, you'll need an API key. If you do not already have one, create a key in Google AI Studio.

Get an API key

Tavily Search

Tavily's Search API is a search engine built specifically for AI agents (LLMs), delivering real-time, accurate, and factual results at speed.

(Optional) LangSmith

Many of the applications you build with LangChain will contain multiple steps with multiple invocations of LLM calls. As these applications get more and more complex, it becomes crucial to be able to inspect what exactly is going on inside your chain or agent. The best way to do this is with LangSmith.

Jupyter Notebook

The conda environment includes an installation of Jupyter Lab. Start Jupyter Lab from your terminal:

jupyter lab

In Jupyter Lab, open the notebook agent_langgraph.ipynb and follow the instructions there.

About

Build an agent with LangGraph

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published