Skip to content

phillippbertram/langgraph-agent

Repository files navigation

langgraph-agent

A demonstration of a ReAct-style agent using LangGraph and LangChain with tool use, reasoning, and stateful execution.

Features

  • ReAct Agent: Uses the ReAct pattern for reasoning and acting.
  • Tool Use: Integrates search (via Tavily) and a custom triple tool.
  • Stateful Execution: Built on LangGraph's state machine for agent control flow.
  • Debug Logging: Easily enable debug logs for development and troubleshooting.

Project Structure

main.py         # Entry point, builds and runs the agent graph
nodes.py        # Node functions for agent reasoning and tool execution
react.py        # Agent, tools, and prompt setup
state.py        # AgentState definition for LangGraph
graph.png       # Visual representation of the agent graph
pyproject.toml  # Dependencies and project metadata

Requirements

  • Python 3.10+
  • API keys for OpenAI and Tavily (set as environment variables)

Installation

# Clone the repo
git clone https://github.com/phillippbetram/langgraph-agent.git
cd langgraph-agent

# (Recommended) Create a virtual environment
python -m venv .venv
source .venv/bin/activate

# Install dependencies
pip install -r requirements.txt
# or, if using poetry/pdm, use your preferred tool

Environment Variables

Create a .env file in the project root with your API keys:

OPENAI_API_KEY=your-openai-key
TAVILY_API_KEY=your-tavily-key

Usage

Run the agent with:

python main.py

This will:

  • Build the agent graph
  • Print a greeting
  • Run a sample query: "what is the weather in Berlin, germany? List it and then triple it"
  • Print the agent's output

Debugging

Debug logs for LangGraph and LangChain are enabled by default in main.py:

import logging
from langchain.globals import set_debug

set_debug(True)
logging.basicConfig(level=logging.DEBUG)
logging.getLogger("langgraph").setLevel(logging.DEBUG)
logging.getLogger("langchain").setLevel(logging.DEBUG)
logging.getLogger("langchain_core").setLevel(logging.DEBUG)

Customization

  • Add tools: Edit react.py and add to the tools list.
  • Change prompts: Swap out the prompt in react.py using LangChain Hub or your own template.
  • Modify agent logic: Adjust the state machine in main.py or node functions in nodes.py.

License

See LICENSE.

About

No description, website, or topics provided.

Resources

License

Stars

0 stars

Watchers

1 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages