Crypto.com AI Agent Service API

This service is part of the Crypto.com AI Agent SDK, designed to facilitate querying blockchain services via Natural Language Processing (NLP) integrated with OpenAI. The core logic of the service interprets user queries, matches them with blockchain functions, and interacts with blockchain nodes and explorers.

Background

The Crypto.com AI Agent Service API integrates multiple technologies to provide a seamless interaction with blockchain services via natural language queries. The core logic is divided into several components:

  1. Agent Logic: This stores the core mapping logic between user input and blockchain functions. It uses OpenAI's NLP capabilities to map the user’s query to the corresponding blockchain function.

  2. Blockchain Service: A collection of blockchain commands such as getLatestBlock, createWallet, etc. These commands interact with blockchain nodes to retrieve or perform actions.

  3. Explorer Integration: This component interacts with blockchain explorers to retrieve additional blockchain data using the Cronos explorer APIs.

Features

  • NLP Query Mapping: Maps user queries to blockchain functions using OpenAI.

  • Blockchain Commands: Perform blockchain-specific commands such as retrieving blocks, creating wallets, and more.

  • Explorer API Integration: Fetch blockchain data from the Cronos explorer APIs.

  • Health Monitoring: A health check route to monitor the API’s status and uptime.

How It works

The service exposes two main API routes:

  1. Health Check Route: Provides basic uptime and response time of the service, allowing users or automated systems to monitor the API.

  2. Query Route: Allows the user to input a query in natural language, which is processed by the core Agent logic. This logic, powered by OpenAI, maps the input to a specific blockchain function and executes the corresponding action on the blockchain.

The architecture:

  • The query server accepts a query and processes it through the agent logic.

  • OpenAI processes the query using NLP and matches it with a relevant function.

  • The matched function is then executed by interacting with the blockchain service or explorer APIs to retrieve or perform the desired action.

API Endpoints

Health Check

  • Endpoint: /healthcheck

  • Method: GET

  • Description: Returns the uptime and health status of the service.

Example:

curl https://ai-agent-api.crypto.com/healthcheck

Response Example:

{
  "status": "success",
  "result": {
    "uptime": 120.34,
    "responsetime": [0, 252939],
    "message": "OK",
    "timestamp": 1632846348163
  }
}

Query Route

  • Endpoint: /api/v1/cdc-ai-agent-service/query

  • Method: POST

  • Description: Takes a natural language query, maps it to a blockchain command via OpenAI, and executes the command.

Example: Getting the latest block - With get latest block

{
  "query": "get latest block",
  "options": {
    "openAI": {
      "apiKey": "<your-openai-api-key>"
    },
    "chain": {
      "id": 282,
      "name": "cronos-zkevm-testnet",
      "rpc": "https://testnet.zkevm.cronos.org"
    },
    "explorer": {
      "apiKey": "<your-explorer-api-key>"
    },
    "wallet": {
      "mnemonic": "<your-mnemonic-phrase>"
    }
  }
}

Here are the key details for:

Cronos zkEVM

Cronos EVM

Response Example:

{
  "status": "success",
  "result": {
    "action": "getBlock",
    "message": "Retrieved latest block",
    "data": {
      "blockNumber": 123456,
      "timestamp": "2023-09-12T10:12:15Z"
    }
  }
}

Last updated