main
Interactive LangGraph Agent with Memory and Tool Confirmation
This project demonstrates a simple interactive agent built with LangGraph that:
- Maintains conversation memory across turns.
- Pauses before invoking tools and asks the user for confirmation.
- Uses the
richlibrary for pretty console output.
Prerequisites
- Python 3.10 or newer
- An OpenAI API key (set as the environment variable
OPENAI_API_KEY)
Installation
# Clone the repository
git clone https://github.com/yourusername/langgraph-agent.git
cd langgraph-agent
# Create a virtual environment (optional but recommended)
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
# Install dependencies
pip install -r requirements.txt
Usage
# Ensure your OpenAI API key is set
export OPENAI_API_KEY="sk-..."
# Run the agent
python src/main.py
You will see a prompt where you can type messages. The agent will respond, and if it needs to use the calculator tool, it will pause and ask for your confirmation before executing the tool.
Type exit to quit the program.
How It Works
- Memory:
MemorySaverstores the conversation history, allowing the agent to remember previous messages. - Interrupt Before Tool Calls: The agent is configured with
interrupt_before=['tools'], causing it to pause before calling any tool. - User Confirmation: When the agent pauses, it prints the pending tool call and asks you whether to proceed. If you confirm, the agent resumes; otherwise, the tool call is cancelled.
Feel free to extend the toolset or modify the system prompt to suit your needs.
Description
Languages
Python
100%