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
Metadata
Release files for cryptocom-tool-adapters 2.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 | |
|---|---|---|---|---|
| cryptocom_tool_adapters-2.0.0.tar.gz | 27.6 kB | Without provenance | Details |
Release files / cryptocom_tool_adapters-2.0.0.tar.gz
| Download URL | cryptocom_tool_adapters-2.0.0.tar.gz |
|---|---|
| Size | 27.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
efa9b891a23146e53985f32b95f47cfde77cd7db8ae3c3d5c0593fe3702d73f0
|
|
BLAKE2b-256 checksum How to use checksums |
5787d4214d394de61f90844120b6221c4a0a242890c38c7ecae715eea32bfdff
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.9
|
Security for cryptocom-tool-adapters 2.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.