Self-Hosting AI-Agent-Server
Introduction
By following this example, we will be able to self-host the AI element of the SDK, specifically the AI agent client
, independently. This offers developers and projects greater control and flexibility compared to using the AI agent API directly. Underneath, the AI agent client utilizes the package to obtain data and interact with Cronos Chains. The example is fully opensource and can be found in this repository
Step 1 - Clone the repository:
Step 2 - Install dependencies:
Step 3 - Create a .env
file with the following content:
We can follow the guide in Explorer API keys to obtain our Explorer_API_Key
, the explorer API keys of different Cronos chains
The example is configured for the Cronos zkEVM Testnet. When connecting to another network, please update the chain in Client.init within agent.service.ts
accordingly.
Step 4 - Run the development server / Production build:
Run the development server by
Once done, the AI agent client
will be running under localhost:8000
OR
Production build by
Afterwards, we can interact with the AI agent client
in a similar manner
API Endpoints
Health Check
Endpoint:
/healthcheck
Method:
GET
Description: Returns the uptime and health status of the service.
Response Example:
Query Route
More query example can be found in Functions and Example Queries of AI agent services
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.
Request Body Example:
Response Example:
Experimental feature - Assigning a key to the AI Agent
Please note that the following is an experimental feature intended for demonstration purposes only. Use this feature with caution, as it may result in the loss of funds.
As introduced in this pull request, developers can follow the instructions to assign a private key directly to the AI agent, enabling it to perform transactions on the user's behalf.
In particular, we need to update the agent.service.ts
file and the .env
file with additional variables, such as the key to be assigned, the RPC URL for transaction broadcasting (see Cronos zkEVM Sepolia Testnet URLs) and the DEX router for swaping:
Developers may also refer to the experimental
branch of this repository for further reference.
Last updated