Langchain

AgentiPy Integrations: LangChain

AgentiPy seamlessly integrates with LangChain, empowering your AI agents to perform complex operations directly on the Solana blockchain. This integration provides out-of-the-box, pre-configured tooling that simplifies the development of sophisticated AI-driven decentralized applications (dApps).

This document outlines how to set up and use AgentiPy's LangChain integration to build a console-based Solana blockchain assistant.

Key Features

  • Pre-configured Tools: Access Solana blockchain functionalities as readily available LangChain tools.

  • Low-Code Integration: Focus on your agent's logic, not boilerplate code for blockchain interactions.

  • AI-Powered Blockchain Operations: Leverage Large Language Models (LLMs) to intelligently select and execute Solana functions based on natural language queries.

  • Console Application Ready: Easily demonstrate and test blockchain operations directly from your terminal.

Prerequisites

Before you begin, ensure you have the following:

  1. Python 3.9+: Installed on your system.

  2. Solana Wallet Private Key: A base58-encoded private key for a Solana wallet with some SOL (for gas fees) and potentially other tokens you wish to interact with.

    • Important: For development and testing, it's highly recommended to use a devnet private key and devnet SOL. Never use your mainnet private key for testing or in insecure environments.

  3. OpenAI API Key: An API key from OpenAI to use their gpt-4o-mini model.

Installation

You'll need to install AgentiPy, LangChain, OpenAI's Python client, and python-dotenv:

Setup Environment Variables

Create a file named .env in the root directory of your project (where your Python script will be located). Add your private key and OpenAI API key to this file:

Replace "YOUR_BASE58_ENCODED_SOLANA_PRIVATE_KEY" and "YOUR_OPENAI_API_KEY" with your actual keys.

Code Explanation: Solana Blockchain Assistant

The following Python script demonstrates a console-based AI assistant powered by AgentiPy's LangChain integration. It uses langgraph to create an agent that can dynamically call Solana-related tools based on user input.

How to Run

  1. Save the code: Save the script above as solana_assistant.py (or any other .py file).

  2. Ensure .env file exists: Make sure your .env file is in the same directory as solana_assistant.py and contains your SOLANA_PRIVATE_KEY and OPENAI_API_KEY.

  3. Run from terminal: Open your terminal or command prompt, navigate to the directory where you saved the file, and run:

The assistant will start and prompt you for input.

Example Usage

Once the application is running, you can type questions into the console:

Last updated