This repository contains a basic Langchain agent that interacts with the Tavily and OpenAI APIs while also enabling on-chain transactions via the Safe ETH SDK. The agent is designed to run in a containerized environment through Olas' quickstart.
Langchain is a powerful framework for developing applications with Large Language Models (LLMs). It simplifies the integration of different AI tools, memory, and external APIs, making it easier to build intelligent agents that interact with diverse data sources.
Olas is a decentralized compute marketplace that enables developers to deploy and monetize AI services in a trustless environment. By leveraging Olas' infrastructure, this agent can operate within a permissionless, decentralized environment while handling API interactions and on-chain transactions.
- LLM-powered agent using OpenAI API for natural language processing.
- Web search capability powered by Tavily API for retrieving real-time information.
- Blockchain transactions enabled via Safe ETH SDK to perform secure on-chain operations.
- Wallet abstraction and containerized execution using Olas Quickstart.
Before setting up the environment, ensure you have the following installed:
-
Create a virtual environment and install the dependencies:
poetry shell poetry install
-
Setup the .env file by duplicating the
.env.examplefile and renaming it to.env.cp .env.example .env
Then fill in the required environment variables.
-
Start agent execution:
python langchain_hello_world/main.py
When executing this agent through Olas Quickstart the safe wallet and agent private key will be automatically setup, however you can follow these steps if you want to test transactions execution locally:
-
Prepare some wallet address that will act as the signer of your local transactions. Setup the
ethereum_private_key.txtfile by duplicating theethereum_private_key.txt.examplefile and renaming it toethereum_private_key.txt.cp ./agent_key/ethereum_private_key.txt.example ./agent_key/ethereum_private_key.txt
Then fill in your wallet private key. Be carefull with extra characters in the file.
-
Deploy a Safes on Gnosis (it's free) and set your wallet address the signer. Set the signature threshold to 1 out of 4. Do not forget to activate your safe.
-
Create a Tenderly account and from your dashboard create a fork of Gnosis chain (virtual testnet).
-
From Tenderly, fund your wallet and Safe with some xDAI.
-
Then add the following variables to your .env file:
CONNECTION_LEDGER_CONFIG_LEDGER_APIS_GNOSIS_ADDRESS- Set it to your Tenderly fork Admin RPCCONNECTION_CONFIGS_CONFIG_SAFE_CONTRACT_ADDRESSES- A dictionary with the safe contract address created on step 2 as the value and the network as the key, for example:
CONNECTION_CONFIGS_CONFIG_SAFE_CONTRACT_ADDRESSES={"gnosis":"0x242Ee6B9aa082a31243BDb23c127A36C49BAf4E1"} -
Start agent execution and you should see some transactions being executed on Tenderly explorer:
python langchain_hello_world/main.py
To deploy this agent to Olas you will need to have a docker image configured, ensure you have Docker installed and follow the steps below to test and publish your image. The tag of your image will need to match your agent hash. #TODO: Add link to SDK Starter guide
#Build the image, to be executed where Dockerfile is
docker build -t langchain-hello-world .
#Run the container
docker run --env-file .env langchain-hello-world --rm
#Login to docker
docker login
#Tag the image built previously
docker tag langchain-hello-world <docker_repo_name>/langchain-hello-world:<tag_name>
#Push it to a public docker hub repository
docker push <docker_repo_name>/langchain-hello-world:<tag_name>
Feel free to submit issues or pull requests if you want to improve this repository. Contributions are welcome!
This project is licensed under the MIT License.