A collection of AI agents built with LangChain and LangGraph, implementing a Human-in-the-Loop (HITL) architecture. This project demonstrates how to securely integrate Large Language Models (LLMs) with external systems (Databases, Email), giving the user final control over sensitive operations.
- Human-in-the-Loop (HITL): Halts agent execution before critical actions (e.g., writing to DB, sending emails).
- Interactive CLI: Clean terminal interface for approving or rejecting agent actions.
- Impact Analysis (SQL): Previews the consequences of SQL queries (e.g., rows to be updated) before execution.
- Memory Checkpointing: The agent's state is persisted, allowing workflows to resume seamlessly after user intervention.
- Python 3.10+
- LangChain / LangGraph
- Groq API (or Ollama for local models)
- SQLite (using the Chinook sample database)
-
Clone the repository:
git clone https://github.com/Inexpli/LangChain-Agents cd LangChain-Agents -
Create and activate a virtual environment:
python -m venv venv source venv/bin/activate # Windows: venv\Scripts\activate
-
Install dependencies:
pip install -r requirements.txt
-
Environment Setup:
API_KEY=your_groq_api_key # Or use local models by Ollama
Simulates an email assistant. The agent reads the "latest email" and proposes a reply. Approval is required before sending.
python email_agent.pyAPPROVAL REQUIRED - EMAIL SEND OPERATION
====================================================================================================
Email to send:
To: [email protected]
Subject: Re: Meeting
Body: Hi Mark, next week works for me. Let's reschedule.
====================================================================================================
[a] Approve - Send the email
[r] Reject - Cancel the email
A database management agent (defaults to Chinook.db).
It allows arbitrary queries, but modifications like (INSERT, UPDATE, DELETE, CREATE, DROP, ALTER and TRUNCATE) require approval.
python sql_agent.pyAPPROVAL REQUIRED - WRITE OPERATION
================================================================================
Query to execute:
UPDATE Artist SET Name = 'Records AI' WHERE ArtistId = 276
================================================================================
Rows that will be updated:
[(276, 'Old Name')]
================================================================================
[a] Approve - Execute the query
[r] Reject - Cancel the query
[v] View - Show query again
[p] Preview - Show impact preview again
A correcting assistant for Obsidian notes. The agent reviews a note and suggests improvements. Approval is required before applying changes. It can change the content of the note and also the title.
python obsidian_agent.py================================================================================
CURRENT: Bananas don't contain potassium
================================================================================
Bananas don't contain potassium.
================================================================================
================================================================================
PROPOSED: Bananas contain potassium
================================================================================
Bananas are a rich source of potassium, providing about 358 mg per 100 g serving.
================================================================================
Options:
[a] Approve - Apply the changes
[r] Reject - Skip this note and continue
The SQL Agent has permissions to modify the database. Despite the Human Approval mechanism, it is recommended to:
- Use this code primarily on test/development databases.
- Carefully verify SQL queries generated by the LLM before approving them.
The entire repository is under the MIT license.