Skip to main content

Radius plugin for JSON-RPC

Project description

Radius AI Agent Toolkit - JSON-RPC Plugin

This plugin enables AI agents to make remote procedure calls using the JSON-RPC protocol through a standardized interface, allowing them to interact with any JSON-RPC endpoint.

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-plugin-jsonrpc

# Required dependencies
pip install radius-ai-agent-sdk
pip install aiohttp

Prerequisites

  • Python >=3.10
  • radius-ai-agent-sdk >=0.1.0
  • aiohttp >=3.8.6

Usage

from radius_plugins.jsonrpc import jsonrpc, JSONRpcPluginOptions
from radius_wallets.web3 import create_radius_wallet
from radius_adapters.langchain import get_on_chain_tools

# Create a Radius wallet
wallet = create_radius_wallet(
    rpc_url=os.environ.get("RPC_PROVIDER_URL"),
    private_key=os.environ.get("WALLET_PRIVATE_KEY")
)

# Initialize the JSON-RPC plugin
jsonrpc_plugin = jsonrpc(JSONRpcPluginOptions(
    endpoint="https://your-json-rpc-endpoint.com"
))

# Create AI agent tools with the JSON-RPC plugin
tools = get_on_chain_tools(
    wallet=wallet,
    plugins=[jsonrpc_plugin]
)

Example: Making a JSON-RPC Call

# Example of using the JSON-RPC plugin through an AI agent
from langchain_core.prompts import ChatPromptTemplate
from langchain_core.runnables import RunnablePassthrough
from langchain_openai import ChatOpenAI

model = ChatOpenAI(model="gpt-4o")
agent = model.bind_tools(tools)

prompt = ChatPromptTemplate.from_messages([
    ("system", "You are a helpful assistant that can make JSON-RPC calls."),
    ("user", "{input}")
])

chain = prompt | RunnablePassthrough.assign(
    agent_response=lambda x: agent.invoke(x)
) | (lambda x: x["agent_response"])

result = chain.invoke({
    "input": """Make a JSON-RPC call to get the latest block number using:
                method: 'eth_blockNumber',
                params: [],
                id: 1,
                jsonrpc: '2.0'"""
})

# The AI will use the json_rpc_func tool to execute this request

API Reference

jsonrpc(options: JSONRpcPluginOptions)

Creates a new JSON-RPC plugin instance.

Parameters:

  • options (JSONRpcPluginOptions): Configuration options for the JSON-RPC plugin
    • endpoint (str): The URL of the JSON-RPC endpoint

Returns:

  • A JSONRpcPlugin instance that can be used with AI agent frameworks

Provided Tools

The JSON-RPC plugin provides the following AI agent tool:

json_rpc_func

Makes a remote procedure call to a JSON-RPC endpoint.

Parameters:

  • method (str): A string containing the name of the method to be invoked
  • params (list): A structured value that holds the parameter values to be used during the invocation of the method
  • id (int): An identifier established by the client that must contain a string, number, or null
  • jsonrpc (str): A string that specifies the version of the JSON-RPC protocol must be exactly '2.0'

Example:

try:
    result = await json_rpc_tool.execute({
        "method": "eth_getBalance",
        "params": ["0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48", "latest"],
        "id": 1,
        "jsonrpc": "2.0"
    })
    print(f"JSON-RPC call result: {result}")
except Exception as e:
    print(f"JSON-RPC call failed: {str(e)}")

Note on Tool Naming: The tool name in this documentation (json_rpc_func) matches the actual name used at runtime. The @Tool decorator in the implementation automatically converts camelCase method names to snake_case for the final tool names.

Features

  • Asynchronous JSON-RPC calls
  • HTTP/HTTPS transport support
  • Error handling and response parsing
  • Type-safe implementations with Pydantic
  • Built on aiohttp for high performance

Development Setup

1. Clone the Repository

git clone git@github.com:radiustechsystems/ai-agent-toolkit.git
cd ai-agent-toolkit/python/src/plugins/jsonrpc

2. Install Development Dependencies

pip install -e ".[dev]"

3. Run Tests

pytest

Related Packages

Resources

Contributing

Please see the Contributing Guide for detailed information about contributing to this toolkit.

License

This project is licensed under the MIT License.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

radius_ai_agent_sdk_plugin_jsonrpc-1.0.0.tar.gz (7.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

File details

Details for the file radius_ai_agent_sdk_plugin_jsonrpc-1.0.0.tar.gz.

File metadata

File hashes

Hashes for radius_ai_agent_sdk_plugin_jsonrpc-1.0.0.tar.gz
Algorithm Hash digest
SHA256 fde384fc54da7987d13f1dc5ad804d8ccd3bd5cd0114477e5250b76de22b3a7c
MD5 66201ed130de83cb118052001666958e
BLAKE2b-256 01395127a19c9f241413b4af25bbb74dd2b7c723db76ad83e291b53c6c186695

See more details on using hashes here.

File details

Details for the file radius_ai_agent_sdk_plugin_jsonrpc-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for radius_ai_agent_sdk_plugin_jsonrpc-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 368f88ae0663a4fab7796cf2e53f1cc4ca8b1850271c395a3a45d7318563acf9
MD5 1d5b56b5ea001f0c03cd9e5c1933d4d2
BLAKE2b-256 da8887954ac37e9728e177a8d4693d9c0350c24f2d92ed4340c069a86f8737ba

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page