LangChainBitcoin

LangChainBitcoin is a suite of tools that enables langchain agents to directly interact with Bitcoin and also the Lightning Network. This package has two main features:

Features

Installation

To install the LangChainL402 project, you can clone the repository directly from GitHub:

git clone https://github.com/lightninglabs/LangChainBitcoin.git
cd LangChainBitcoin

Please ensure you have all the necessary Python dependencies installed. You can install them using pip:

pip install -r requirements.txt

Usage

LLM Agent Bitcoin Tools

Check out the contained Jupyter notebook for an interactive example you can run/remix: LLM Bitcoin Tools.

L402 API Traversal

Check out the contained Jupyter notebook for an interactive example you can run/remix: LangChain402.

This project provides classes to handle Lightning payments (e.g., LndNode, LightningNode) and to manage HTTP requests with L402-based authentication (RequestsL402Wrapper, ResponseTextWrapper).

First, initialize the LndNode with your Lightning node's details. Then, you can use the modified L402APIChain wrapper around the normal APIChain class to instantiate an L402-aware API Chain. If the server responds with a 402 Payment Required status code, the library will automatically handle the payment and retry the request.

Here is a basic example:

import requests

from lightning import LndNode

from l402_api_chain import L402APIChain
from langchain_openai import OpenAI

# Initialize LndNode
Add node data to the .env.shared file

# Add API data
Specifics of the serivce to be used can be added to API_DOCS via utils.py

# Instruction the AI agent
Instructions can be delivered to the AI agent via agent_executor.invoke main.py