A Python client to interact with @cryptocom/agent
Project description
Crypto.com Agent Client
The Crypto.com Agent Client is a Python library designed to integrate advanced conversational AI capabilities with blockchain functionality. It provides tools, plugins, and utilities to build robust and extensible agent workflows with graphs and Crypto.com blockchain integrations.
Features
Conversational AI Integration
- Build conversational agents with state-of-the-art Large Language Models (LLMs) like OpenAI's GPT series, Anthropic's Claude, and Meta's Llama 4.
- AWS Bedrock support with Claude models, Knowledge Base integration for RAG, and Guardrails for content filtering.
- Customize agent behavior using plugins for personality and instructions.
Blockchain Integration
-
Perform blockchain-specific operations with pre-built functions:
- Create wallets.
- Retrieve native and ERC20 token balances.
- Fetch transactions by hash.
- Transfer tokens.
Extensible Tools
- Extend agent functionality with custom user-defined tools.
- Simple decorator-based implementation using
@tool.
Persistent Storage
- Use
SQLitePluginfor local state persistence. - Seamlessly store and retrieve agent states.
LangFuse Monitoring
- Integrate with LangFuse for real-time telemetry and interaction monitoring.
- Enable detailed analytics for agent performance and usage.
Plugin System
- Flexible plugin configuration for tools, storage, personality, and telemetry.
- Easily swap or extend functionality without modifying core logic.
Custom Instructions
- Tailor agent responses using flexible instructions.
- Combine personality settings for tone, verbosity, and language.
Easy Initialization
- Initialize with just a few lines of code.
- Include blockchain, LLM, and plugin configurations.
Installation
Install the package from PyPI:
pip install cryptocom-agent-client
For AWS Bedrock support, ensure boto3 is installed:
pip install cryptocom-agent-client boto3
Usage
Importing the Library
from crypto_com_agent_client import Agent, tool, SQLitePlugin
Getting Started
Agent Initialization
To get started, initialize the SDK with your API key. To obtain an API key, create an account and a project at: https://developer.crypto.com
from crypto_com_agent_client import Agent, tool
@tool
def get_weather(location: str) -> str:
return f"The weather in {location} is sunny."
agent = Agent.init(
llm_config={
"provider": "OpenAI",
"model": "gpt-4",
"provider-api-key": "OPENAI_API_KEY",
},
blockchain_config={
"api-key": "SDK_API_KEY",
"explorer-api-key": "EXPLORER_API_KEY",
"private-key": "PRIVATE_KEY",
"sso-wallet-url": "your-sso-wallet-url",
},
plugins={
"personality": {
"tone": "friendly",
"language": "English",
"verbosity": "high",
},
"instructions": "You are a humorous assistant that always includes a joke in your responses.",
"tools": [get_weather],
"storage": SQLitePlugin(db_path="agent_state.db"),
"langfuse": {
"public-key": "user-public-key",
"secret-key": "user-secret-key",
"host": "https://langfuse.example.com",
},
},
)
response = agent.interact("What's the weather in Berlin?")
print(response)
Security Warning: Private Key Storage
Private keys generated and stored locally on a developer's or end-user's machine may be exposed to compromise due to inadequate protection of the local environment. If the machine is infected with malware, improperly secured, or lacks encryption and access controls, unauthorized parties could gain access to the private key material. This could result in irreversible loss of digital assets, unauthorized transactions, or compromise of wallet integrity.
Using Llama 4 with Groq Provider
agent = Agent.init(
llm_config={
"provider": "Groq",
"model": "meta-llama/llama-4-scout-17b-16e-instruct",
"provider-api-key": "GROQ_API_KEY",
"temperature": 0.7,
},
blockchain_config={
"api-key": "DEVELOPER_SDK_API_KEY",
},
plugins={
"personality": {
"tone": "friendly",
"language": "English",
"verbosity": "medium",
},
"instructions": "You are a helpful blockchain assistant powered by Llama 4."
},
)
response = agent.interact("How can I create a wallet on Cronos?")
print(response)
Using AWS Bedrock
Basic Setup
from crypto_com_agent_client import Agent
agent = Agent.init(
llm_config={
"provider": "Bedrock",
"model": "anthropic.claude-3-haiku-20240307-v1:0",
"provider-api-key": "ACCESS_KEY:SECRET_KEY:us-east-1", # Or use AWS environment variables
"temperature": 0.7,
},
blockchain_config={
"api-key": "DEVELOPER_SDK_API_KEY",
},
plugins={
"instructions": "You are a helpful blockchain assistant powered by AWS Bedrock."
},
)
response = agent.interact("What is blockchain technology?")
print(response)
Note: For production, use AWS IAM roles or environment variables instead of hardcoding credentials:
- Set
AWS_ACCESS_KEY_ID,AWS_SECRET_ACCESS_KEY, andAWS_DEFAULT_REGION - Or use IAM roles when running on AWS infrastructure
Knowledge Base Integration (RAG)
Connect to AWS Bedrock Knowledge Base for enhanced responses with your own data:
agent = Agent.init(
llm_config={
"provider": "Bedrock",
"model": "anthropic.claude-3-sonnet-20240229-v1:0",
"knowledge_base_id": "YOUR_KB_ID", # Your AWS Knowledge Base ID
"min_relevance_score": 0.5, # Filter results below 50% relevance
"temperature": 0.3,
},
blockchain_config={
"api-key": "DEVELOPER_SDK_API_KEY",
},
)
# The agent will automatically query the knowledge base for relevant context
response = agent.interact("What are our company's blockchain policies?")
print(response)
Environment Variables:
export AWS_KNOWLEDGEBASE_ID="your-knowledge-base-id"
export AWS_DEFAULT_REGION="us-east-1"
Guardrails Configuration
Add content filtering and safety controls with AWS Bedrock Guardrails:
agent = Agent.init(
llm_config={
"provider": "Bedrock",
"model": "anthropic.claude-3-haiku-20240307-v1:0",
"guardrail_id": "YOUR_GUARDRAIL_ID",
"guardrail_version": "1", # Or use "DRAFT" for testing
"temperature": 0.7,
},
blockchain_config={
"api-key": "DEVELOPER_SDK_API_KEY",
},
)
# Guardrails will automatically filter inappropriate content
response = agent.interact("Help me with blockchain development")
print(response)
Environment Variables:
export AWS_GUARDRAIL_ID="your-guardrail-id"
export AWS_GUARDRAIL_VERSION="1"
Complete Bedrock Example
Combining all features for a production-ready setup:
import os
from crypto_com_agent_client import Agent, SQLitePlugin
# Use environment variables for sensitive data
os.environ["AWS_DEFAULT_REGION"] = "us-east-1"
agent = Agent.init(
llm_config={
"provider": "Bedrock",
"model": "anthropic.claude-3-sonnet-20240229-v1:0",
"knowledge_base_id": os.getenv("AWS_KNOWLEDGEBASE_ID"),
"guardrail_id": os.getenv("AWS_GUARDRAIL_ID"),
"guardrail_version": "1",
"min_relevance_score": 0.6,
"temperature": 0.4,
"debug_logging": True, # Enable to see knowledge base queries
},
blockchain_config={
"api-key": os.getenv("DEVELOPER_SDK_API_KEY"),
},
plugins={
"storage": SQLitePlugin(db_path="bedrock_agent.db"),
"personality": {
"tone": "professional",
"language": "English",
"verbosity": "medium",
},
"instructions": "You are an AI assistant with access to company knowledge base. Provide accurate, helpful responses based on available information."
},
)
response = agent.interact("What are the latest blockchain trends?")
print(response)
Plugins
Storage Plugin
agent = Agent.init(
llm_config={...},
blockchain_config={...},
plugins={
"storage": SQLitePlugin(db_path="agent_state.db")
},
)
LangFuse Plugin
agent = Agent.init(
llm_config={...},
blockchain_config={...},
plugins={
"langfuse": {
"public-key": "user-public-key",
"secret-key": "user-secret-key",
"host": "https://langfuse.example.com",
}
},
)
Personality Plugin
agent = Agent.init(
llm_config={...},
blockchain_config={...},
plugins={
"personality": {
"tone": "friendly",
"language": "English",
"verbosity": "high",
},
},
)
Tools
Defining Tools
@tool
def get_weather(location: str) -> str:
return f"The weather in {location} is sunny."
@tool
def greet_user(name: str) -> str:
return f"Hello, {name}! How can I assist you today?"
@tool
def calculate_sum(a: int, b: int) -> int:
return a + b
Using Tools
agent = Agent.init(
llm_config={...},
blockchain_config={...},
plugins={
"tools": [get_weather, greet_user, calculate_sum],
},
)
response = agent.interact("What's the weather in Berlin?")
print(response)
Blockchain Functions
Pre-Built Functions
create_wallet()get_native_balance(address: str)get_erc20_balance(address: str, token: str)get_transaction_by_hash(tx_hash: str)transfer_token(from_address: str, to_address: str, amount: int, token: str)
Example Usage
agent = Agent.init(...)
response = agent.interact("Create 2 Wallets")
print(response)
Custom Instructions
agent = Agent.init(
llm_config={...},
blockchain_config={...},
plugins={
"instructions": "Be concise and professional."
},
)
API
Agent
Agent.init(...): Initializes the agent with configuration for LLM, blockchain, and plugins.Agent.interact(input: str): Sends input to the agent and returns the response.
Tool Decorator
@tool: Decorator used to register a function as an agent tool.
Contributing
We welcome contributions! Please follow the guidelines in the repository.
License
This project is licensed under the MIT License. See the LICENSE file for details.
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 Distributions
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file cryptocom_agent_client-1.3.6-py3-none-any.whl.
File metadata
- Download URL: cryptocom_agent_client-1.3.6-py3-none-any.whl
- Upload date:
- Size: 91.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
484a8c2bb0380ec4cd0d08f332c0c0c70ae8051d9cc73934cbe94569fc910106
|
|
| MD5 |
17649602124024df116edfb7e46bfd97
|
|
| BLAKE2b-256 |
5f5ba9cfade2bf7d0aa3b97440dc26331a75316b733f020186f5230e2c2e5042
|