Contract To Agent
Last updated
Last updated
Socials
X (Twitter)The contract-to-agent
tool enables you to scaffold an agent based on a NEAR contract that has an ABI. This process makes integration with the NEAR protocol seamless by providing a structured template for agent development. Here's a step-by-step guide to get started:
Scaffold the Agent: Run the following command to start creating your agent. You will be prompted for necessary inputs:
Contract ID: Provide the contract ID. Ensure the contract has a well-defined ABI.
Description: Offer a detailed description of the contract's functionalities, which will guide the behavior of the agent.
Optional Directory: Specify a directory where you want to generate the agent files, or leave it blank to use the default.
If you just want to run your agent and don't want to know how it works then skip to 2. The rest of the flow will continue as described below, but before following that we can take a look at what was generated, if you open your index.ts you should see a simple express server
This should contain endpoints for each of your smart contract methods regardless of if they are read of write calls, notice the writes return a valid transaction object that will be executed by the runtime using the "generate-transaction" tool
The most important part is this endpoint:
Here your Open API Spec will be handled. This is how your agent knows how to interact with your API. If your agent isn't able to use your api correctly even though its functional this is probably the issue. Make sure your instruction field is explicit, some prompt engineering will be necessary
You can learn more about it here Manifest If your contract is too complex for the scaffolding to work completely this will still work as very easy good starting point for your agent.
Generate an API Key: If everything went well you will see this window open. If you don't already have a wallet you will first be prompted to create one first. Once you have signed the message you will have an API Key automatically generated for you and put into your environment variables.
Develop and Test Agent: After creating an API Key you will be booted into the agent playground where you can start testing your agent. Based on the instructions and the contract methods we can see the agent was able to understand what the available methods are and should be able to make view and write contract calls out of the box
If you ever close the execution you can run everything again by running your server and make-agent again