Tools

Tools are user-defined functions that enhance the agent’s capabilities and are integrated into the AI Agent SDK as plugins. They allow the AI agent to fetch data, perform computations, and interact with external APIs. Tools need to be decorated with @tool to be recognized and registered in the AI Agent. It can serve various purposes, from fetching data to performing calculations, and integrating with external APIs.

Set Up

Before defining a tool, import the @tool decorator to register the function properly:

from crypto_com_agent_client import tool

Implementation Examples

  1. Custom Greeting Tool This tool generates a personalized greeting message for a user.

@tool
def greet_user(name: str) -> str:
    """
    Generate a personalized greeting message.

    Args:
        name (str): The name of the user to greet.

    Returns:
        str: A greeting message addressed to the user.
    """
    return f"Hello, {name}! How can I assist you today?"
  1. Token Information Tool This tool retrieves token information from Cronos EVM using the VVS Finance API (a third-party Cronos project). It fetches liquidity and volume data from underlying subgraphs.

  1. APR Query Tool This example demonstrates how to query APR from blockchain projects. Here, we integrate H2 Finance (a third-party Cronos project) leveraging its API to incorporate it as a plugin within the AI Agent SDK. The AI agent can automatically parse the JSON response, extract relevant information, and provide structured answers to various APR-related queries.

  1. Cronos Blockchain Status Tool

    This blockchain status tool provides real-time insights into the Cronos EVM and Cronos zkEVM networks. With a single function call, users can access key network metrics, including the latest block number, current gas prices, transaction count in the most recent block, network difficulty, and timestamp details. The tool interacts directly with blockchain nodes via standard RPC endpoints, to ensure accurate and up-to-date status reports in a structured format. It offers developers instant access to the Cronos chains' performance data without requiring complex setup or configuration.

Using Tools in the Agent

To use the tools in your agent, initialize it with the required configurations:

Query and Response

Take get_h2_apr for example, the AI Agent can automatically extract information from the result JSON and provide answers to various queries. Developers don’t need to manually search for specific fields in the JSON response - the AI Agent SDK handles that for you.

Example Query (APY)

Response

Example Query (APR)

Response

Last updated

Was this helpful?