Skip to main content

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.
  • 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 SQLitePlugin for 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

Usage

Importing the Library

from cryptocom_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 cryptocom_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": "DEVELOPER_SDK_API_KEY",
        "private-key": "PRIVATE_KEY",
    },
    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)

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)

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


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

cryptocom_agent_client-1.1.0-py3-none-any.whl (67.4 kB view details)

Uploaded Python 3

File details

Details for the file cryptocom_agent_client-1.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for cryptocom_agent_client-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 eff7906a8ba863da9d788c01f192df4da345e9e737cc4cf6fe9af213843f76b1
MD5 39b607a5e9e5b734a724139cddd8180e
BLAKE2b-256 e31d71d5abaedc51941794b95da6e29fd710867f9fe9b6722fef4c3e3ae17528

See more details on using hashes here.

Supported by

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