Skip to content

Inexpli/LangChain-Agents

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🤖 LangChain-Agents

Python LangChain SQLite License

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.

🚀 Features

  • 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.

🛠️ Tech Stack

  • Python 3.10+
  • LangChain / LangGraph
  • Groq API (or Ollama for local models)
  • SQLite (using the Chinook sample database)

📦 Installation

  1. Clone the repository:

    git clone https://github.com/Inexpli/LangChain-Agents
    cd LangChain-Agents
  2. Create and activate a virtual environment:

    python -m venv venv
    source venv/bin/activate  # Windows: venv\Scripts\activate
  3. Install dependencies:

    pip install -r requirements.txt
  4. Environment Setup:

    API_KEY=your_groq_api_key # Or use local models by Ollama

🕹️ Usage

Email Agent

Simulates an email assistant. The agent reads the "latest email" and proposes a reply. Approval is required before sending.

python email_agent.py

Interaction Example:

APPROVAL 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

SQL Agent

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.py

Interaction Example:

APPROVAL 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

Obsidian Agent

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

Interaction Example:

================================================================================
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

⚠️ Security Notice

The SQL Agent has permissions to modify the database. Despite the Human Approval mechanism, it is recommended to:

  1. Use this code primarily on test/development databases.
  2. Carefully verify SQL queries generated by the LLM before approving them.

📄 License

The entire repository is under the MIT license.

About

A repository implementing autonomous AI agents using LangChain and LangGraph.

Topics

Resources

License

Stars

Watchers

Forks

Contributors