Framework adapters for Crypto.com blockchain tools - convert to LangGraph, OpenAI, Anthropic, and MCP formats
Project description
Cryptocom Tool Adapters
Framework adapters for Crypto.com blockchain tools - convert framework-agnostic tools to LangGraph, OpenAI, Anthropic, and MCP formats.
Installation
# Install with specific framework support
pip install cryptocom-tool-adapters[langgraph] # For LangGraph
pip install cryptocom-tool-adapters[openai] # For OpenAI SDK
pip install cryptocom-tool-adapters[anthropic] # For Anthropic SDK
pip install cryptocom-tool-adapters[langchain] # For LangChain (without LangGraph)
# Install with all framework support
pip install cryptocom-tool-adapters[all]
Quick Start
LangGraph Adapter
Convert tools to LangGraph format with state injection:
from cryptocom_tool_adapters import to_langgraph_tool
# Example tool using the framework-agnostic protocol
class TransferTool:
name = "transfer_native_token"
description = "Transfer native tokens to an address"
parameters_schema = {
"type": "object",
"properties": {
"wallet_address": {"type": "string"},
"to": {"type": "string"},
"amount": {"type": "number"},
},
"required": ["wallet_address", "to", "amount"],
}
def execute(self, **kwargs):
return kwargs
transfer_tool = TransferTool()
# Define how to extract context from LangGraph state
def extract_wallet_from_state(state: dict) -> dict:
wallets = state.get("wallets", {})
active = wallets.get("active", "")
return {"wallet_address": active}
# Convert to LangGraph tool (wallet_address injected from state)
transfer_lg = to_langgraph_tool(
transfer_tool,
extract_wallet_from_state,
injected_param_names=["wallet_address"],
)
# Use in LangGraph agent
from langgraph.prebuilt import create_react_agent
agent = create_react_agent(llm, tools=[transfer_lg])
OpenAI SDK Adapter
Convert tools to OpenAI function calling format:
import json
import os
from cryptocom_tools_token import GetNativeBalanceTool
from cryptocom_tool_adapters import to_openai_function, create_openai_executor
from openai import OpenAI
# Initialize tool and client
balance_tool = GetNativeBalanceTool(api_key=os.getenv("CRYPTOCOM_DEVELOPER_PLATFORM_API_KEY"))
client = OpenAI()
# Convert to OpenAI function format
tool_schema = to_openai_function(balance_tool)
# Use in OpenAI API call
response = client.chat.completions.create(
model="gpt-4",
messages=[{"role": "user", "content": "Check balance of 0x123..."}],
tools=[tool_schema],
tool_choice="auto"
)
# Execute tool calls
executor = create_openai_executor(balance_tool)
for tool_call in response.choices[0].message.tool_calls:
if tool_call.function.name == balance_tool.name:
args = json.loads(tool_call.function.arguments)
result = executor(args)
Anthropic SDK Adapter
Convert tools to Anthropic tool format:
from cryptocom_tools_wallet import CreateWalletTool
from cryptocom_tool_adapters import to_anthropic_tool, create_anthropic_executor
from anthropic import Anthropic
# Initialize tool and client
wallet_tool = CreateWalletTool(wallet_state)
client = Anthropic()
# Convert to Anthropic tool format
tool_schema = to_anthropic_tool(wallet_tool)
# Use in Anthropic API call
response = client.messages.create(
model="claude-3-opus-20240229",
messages=[{"role": "user", "content": "Create a new wallet"}],
tools=[tool_schema],
max_tokens=1024
)
# Execute tool calls
executor = create_anthropic_executor(wallet_tool)
for content in response.content:
if content.type == "tool_use":
result = executor(content.input)
LangChain Adapter (without LangGraph)
Pre-bind context for simple LangChain usage:
from cryptocom_tool_adapters import to_langchain_tool
transfer_tool = TransferTool()
# Pre-bind context (wallet address)
context = {"wallet_address": "0x1234..."}
transfer_lc = to_langchain_tool(transfer_tool, context)
# Use in LangChain agent
from langchain.agents import create_tool_calling_agent
agent = create_tool_calling_agent(llm, [swap_lc], prompt)
MCP Adapter
Convert tools to Model Context Protocol format:
import os
from cryptocom_tools_explorer import GetTransactionByHashTool
from cryptocom_tool_adapters import to_mcp_tool, create_mcp_handler
# Initialize tool
tx_tool = GetTransactionByHashTool(api_key=os.getenv("CRYPTOCOM_DEVELOPER_PLATFORM_API_KEY"))
# Convert to MCP format
tool_def = to_mcp_tool(tx_tool)
# Create handler for execution
handler = create_mcp_handler(tx_tool)
# Process MCP requests
request = {"arguments": {"hash": "0xabc..."}}
response = handler(request["arguments"])
# Returns: {"success": true, "result": {...}}
Features
- Framework-agnostic core: Tools have no framework dependencies
- Multiple adapters: Support for LangGraph, LangChain, OpenAI, Anthropic, and MCP
- Type-safe: Full type hints with Protocol definitions
- Context injection: Flexible state/context management for each framework
- Minimal dependencies: Only import what you need with optional dependencies
Adapter Reference
LangGraph Functions
to_langgraph_tool(tool, state_extractor): Convert with custom state extractionwith_injected_state(tool, state_keys, mapping): Simple state key injection
OpenAI Functions
to_openai_function(tool, context): Convert to OpenAI function schemacreate_openai_executor(tool, context): Create executor for tool calls
Anthropic Functions
to_anthropic_tool(tool, context): Convert to Anthropic tool schemacreate_anthropic_executor(tool, context): Create executor for tool use
LangChain Functions
to_langchain_tool(tool, context): Convert to StructuredTool with pre-bound context
MCP Functions
to_mcp_tool(tool, context): Convert to MCP tool definitioncreate_mcp_handler(tool, context): Create MCP request handler
Development
# Clone the repository
git clone https://github.com/crypto-com/agent-client-py.git
cd agent-client-py/cryptocom-tool-adapters
# Install in development mode
pip install -e ".[dev]"
# Run tests
pytest
# Run type checking
basedpyright
# Run linting
ruff check src/
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file cryptocom_tool_adapters-2.0.0.tar.gz.
File metadata
- Download URL: cryptocom_tool_adapters-2.0.0.tar.gz
- Upload date:
- Size: 27.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
efa9b891a23146e53985f32b95f47cfde77cd7db8ae3c3d5c0593fe3702d73f0
|
|
| MD5 |
7894857c4026a9f5c301d037fac19996
|
|
| BLAKE2b-256 |
5787d4214d394de61f90844120b6221c4a0a242890c38c7ecae715eea32bfdff
|