f45e780abafca936580d21e5ebea6b2e221a8f56
LangGraph Agent with Memory and Tool Confirmation
This project demonstrates a simple conversational agent built with LangGraph that:
- Remembers the conversation history across turns using an in‑memory checkpoint.
- Pauses before invoking any tool, asking the user for confirmation.
- Uses the Rich library for pretty console output.
Prerequisites
- Python 3.10+
- An OpenAI API key (set as the
OPENAI_API_KEYenvironment variable).
Installation
# Clone the repository (or copy the files)
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
python src/main.py
You will see a prompt:
Start chat. Type 'exit' to quit.
You:
Type any message. If the agent decides to use a tool (e.g., the echo tool), it will pause and ask:
Agent wants to call tool: echo({"text":"Hello"})
Разрешить? (Y/n):
- Type
Yor press Enter to allow the tool to run. - Type
nto cancel the tool call.
The conversation history is preserved across turns, so the agent can refer back to earlier messages.
Customizing
- Tools: Add more tools by defining functions decorated with
@toolfromlangchain.tools. - Memory: Replace
MemorySaver()with a persistent checkpoint (e.g.,RedisSaver) for long‑term storage. - Prompt: Modify the
system_promptincreate_agentto change the agent’s behavior.
License
MIT License
Description
Languages
Python
100%