A demonstration of a ReAct-style agent using LangGraph and LangChain with tool use, reasoning, and stateful execution.
- ReAct Agent: Uses the ReAct pattern for reasoning and acting.
- Tool Use: Integrates search (via Tavily) and a custom
tripletool. - Stateful Execution: Built on LangGraph's state machine for agent control flow.
- Debug Logging: Easily enable debug logs for development and troubleshooting.
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
- Python 3.10+
- API keys for OpenAI and Tavily (set as environment variables)
# 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 toolCreate a .env file in the project root with your API keys:
OPENAI_API_KEY=your-openai-key
TAVILY_API_KEY=your-tavily-key
Run the agent with:
python main.pyThis 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
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)- Add tools: Edit
react.pyand add to thetoolslist. - Change prompts: Swap out the prompt in
react.pyusing LangChain Hub or your own template. - Modify agent logic: Adjust the state machine in
main.pyor node functions innodes.py.
See LICENSE.