6ed97e505b7fd22c12125b6519944ac581760cb6
Human‑in‑the‑Loop Agent
This repository implements a simple command‑line agent that pauses before each tool call and asks the user to approve or reject the action. It uses LangChain and LangGraph's HumanInTheLoopMiddleware.
Prerequisites
- Python 3.11+ (tested with 3.11 and 3.12)
- An OpenAI API key or a local LLM compatible with the OpenAI API (e.g., Ollama)
Setup
# Create a virtual environment
python -m venv .venv
source .venv/bin/activate
# Install dependencies
pip install -r requirements.txt
Configuration
OpenAI API key
export OPENAI_API_KEY="YOUR_KEY"
Local model (e.g., Ollama)
If you run a local model, edit agent.py and uncomment/adjust the base_url and api_key arguments in the ChatOpenAI constructor:
ChatOpenAI(
base_url="http://localhost:11434/v1",
api_key="ollama",
model="llama3",
)
Usage
python agent.py
You will be prompted to enter a question. The agent will invoke the get_weather tool and pause for confirmation.
Enter your question: What is the weather in Kazan today?
Action 1: get_weather
Arguments: {'city': 'Kazan', 'date': 'today'}
Decision (a=approve, r=reject): a
Agent response:
Weather in Kazan on today
If you reject an action, you will be asked for a reason, which is sent back to the agent as feedback.
License
MIT
Description
Languages
Python
100%