Radius AI Agent Toolkit - LangChain Adapter
This adapter provides integration between the Radius AI Agent Toolkit and LangChain, allowing you to easily add Radius capabilities to AI agents built with LangChain.
This package is part of the Radius AI Agent Toolkit, which provides tools for integrating AI agents with the Radius platform.
Installation
# Install this specific package
pip install radius-ai-agent-sdk-adapter-langchain
# Required dependencies
pip install radius-ai-agent-sdk
pip install langchain langchain-core
Prerequisites
- Python >=3.10
- LangChain installed in your project:
pip install langchain langchain-core langchain-openai
- OpenAI API key or other LLM provider credentials
- Radius wallet setup with a funded account
Usage
import os
from dotenv import load_dotenv
from langchain_openai import ChatOpenAI
from langchain.agents import AgentExecutor, create_tool_calling_agent
from langchain_core.prompts import ChatPromptTemplate
from web3 import Web3
from eth_account import Account
from radius_adapters.langchain import get_on_chain_tools
from radius_wallets.evm import send_eth
from radius_wallets.web3 import Web3EVMWalletClient
# Load environment variables
load_dotenv()
# 1. Setup Web3 and wallet
w3 = Web3(Web3.HTTPProvider(os.getenv("RPC_PROVIDER_URL")))
private_key = os.getenv("WALLET_PRIVATE_KEY")
assert private_key is not None, "You must set WALLET_PRIVATE_KEY environment variable"
account = Account.from_key(private_key)
print(f"Wallet address: {account.address}")
# 2. Configure the tools for LangChain
tools = get_on_chain_tools(
wallet=Web3EVMWalletClient(w3),
plugins=[
send_eth(), # Enable ETH transfers
],
)
print(f"Configured {len(tools)} tools for LangChain")
for tool in tools:
print(f" - {tool.name}: {tool.description}")
# 3. Create a LangChain agent with the tools
llm = ChatOpenAI(temperature=0)
prompt = ChatPromptTemplate.from_messages([
("system", "You are a helpful AI assistant with blockchain capabilities."),
("human", "{input}"),
("placeholder", "{agent_scratchpad}"),
])
# Create and run the agent
agent = create_tool_calling_agent(llm, tools, prompt)
agent_executor = AgentExecutor(agent=agent, tools=tools, verbose=True)
# Example usage
result = agent_executor.invoke({
"input": "What is my wallet address?"
})
print(result["output"])
If you want to include ERC20 token support, you would add:
from radius_plugins.erc20 import erc20, ERC20PluginOptions
from radius_plugins.erc20.token import USDC
# Then in the plugins array:
tools = get_on_chain_tools(
wallet=Web3EVMWalletClient(w3),
plugins=[
send_eth(),
erc20(options=ERC20PluginOptions(tokens=[USDC])) # Add ERC20 token support
],
)
API Reference
get_on_chain_tools(wallet, plugins)
Creates a collection of tools compatible with LangChain that provides access to configured Radius features.
Parameters:
wallet(WalletClientBase): A Radius wallet instanceplugins(List[Any]): List of plugin instances to enable
Returns:
- (List[BaseTool]): An array of LangChain-compatible tools that can be used with LangChain agents
Default Tools:
The get_on_chain_tools function automatically provides the following wallet-related tools:
get_address: Get the address of the walletget_chain: Get the chain of the walletget_balance: Get the balance of an addresssign_message: Sign a message with the walletsimulate_transaction: Simulate a transaction to check if it would succeedresolve_address: Resolve an ENS name to an addressget_transaction_status: Check the status of a transaction
Example:
tools = get_on_chain_tools(
wallet=Web3EVMWalletClient(w3),
plugins=[
send_eth(),
erc20(options=ERC20PluginOptions(tokens=[USDC]))
],
)
Integration Examples
For complete examples integrating this adapter with LangChain, see:
Development Setup
1. Clone the Repository
git clone git@github.com:radiustechsystems/ai-agent-toolkit.git
cd ai-agent-toolkit/python/src/adapters/langchain
2. Install Development Dependencies
pip install -e ".[dev]"
3. Run Tests
pytest
Troubleshooting
Error: Missing LangChain Dependencies
If you encounter errors related to missing LangChain dependencies, ensure you have installed all required packages:
pip install langchain langchain-core langchain-openai
Error: Cannot Create Agent Executor
The LangChain agent creation API may change between versions. If you encounter errors creating the agent executor:
- Check your LangChain version and ensure compatibility
- Verify that your tools have the expected structure (name, description, and function)
- Check the LangChain documentation for the latest API patterns
Related Packages
- radius-ai-agent-sdk: Core abstractions and base classes
- radius-ai-agent-sdk-wallet-evm: EVM wallet functionality
- radius-ai-agent-sdk-plugin-erc20: ERC20 token operations
- radius-ai-agent-sdk-plugin-uniswap: Uniswap operations
Resources
Contributing
Please see the Contributing Guide for detailed information about contributing to this toolkit.
License
This project is licensed under the MIT License
Metadata
Release files for radius-ai-agent-sdk-adapter-langchain 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| radius_ai_agent_sdk_adapter_langchain-1.0.0.tar.gz | 8.8 kB | Without provenance | Details for radius_ai_agent_sdk_adapter_langchain-1.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| radius_ai_agent_sdk_adapter_langchain-1.0.0-py3-none-any.whl | Python 3 | none | any | Details for radius_ai_agent_sdk_adapter_langchain-1.0.0-py3-none-any.whl |
Total release size: 16.1 kB
Release files / radius_ai_agent_sdk_adapter_langchain-1.0.0.tar.gz
| Download URL | radius_ai_agent_sdk_adapter_langchain-1.0.0.tar.gz |
|---|---|
| Size | 8.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c2246f5bbceb21c07bf17c3d4728d0e2c3100cca8fde3cd59fa39474561cc344
|
|
BLAKE2b-256 checksum How to use checksums |
39c6b6fd0478e99938a9ecdf8d24454ed78a8bafc9e2ae31b53795a6d3fccfa8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.11.2
|
Release files / radius_ai_agent_sdk_adapter_langchain-1.0.0-py3-none-any.whl
| Download URL | radius_ai_agent_sdk_adapter_langchain-1.0.0-py3-none-any.whl |
|---|---|
| Size | 7.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
7b831a39c2583e8e013043fd603a9ff04154e52d9710a403492249ed2364f02f
|
|
BLAKE2b-256 checksum How to use checksums |
d5ceafab20dcda6bf6754e2c3f36bf1023d3462cab4d8fcea144d5e7f0bfafd6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.11.2
|
Security for radius-ai-agent-sdk-adapter-langchain 1.0.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.