Files
task_69a86305c46fd26feae6bc…/README.md
T
2026-06-02 14:43:27 +00:00

64 lines
1.4 KiB
Markdown
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# HumanintheLoop Agent
This repository implements a simple commandline 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
```bash
# Create a virtual environment
python -m venv .venv
source .venv/bin/activate
# Install dependencies
pip install -r requirements.txt
```
## Configuration
*OpenAI API key*
```bash
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:
```python
ChatOpenAI(
base_url="http://localhost:11434/v1",
api_key="ollama",
model="llama3",
)
```
## Usage
```bash
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