Gonesis
  • Introduction
  • ChatCoin.App
  • De-AI Agent
    • AI721
    • Workflow
    • Best Practice: The Example of Azuki Collection
    • Best Practice: The Example of AI Agent
  • Ecosystem
    • Gonesis C1
    • Gonesis Ring 💍
  • Links
    • Website
    • X
    • Discord
    • Brand Kit
Powered by GitBook
On this page
  • Introduction
  • What is AI721
  • Why we need AI721
  • How it works
  • How to describe AI Agent on chain?
  • How to design a workflow
  • How to access the AI agents described by AI721?
  • Implementing token URI of AI metadata
  • Best Practice
  • Example

Was this helpful?

  1. De-AI Agent

AI721

Make AI agent indexable and verifiable on the blockchain.

PreviousDe-AI AgentNextWorkflow

Last updated 9 months ago

Was this helpful?

Version: 0.2

Last Updated: 2024-06-15

Introduction

What is AI721

AI721 introduces a standard that extends the AI capabilities of ERC721. It's used to index AI agent on chain, describe the AI personality and copabilities of your AI agent, and verify if a specific personality belongs to a particular AI agent. This makes your AI agent become digital asset on the blockchain.

AI721 will not make any break changes on ERC721. It can be merged with ERC721, or deployed as an independent contract and associated with an existing ERC721 contract.

Yes, AI721 is essentially NFT(non-fungible token) with AI capabilities.

We call it AI-NFT for short.

Why we need AI721

LLMs enable everyone to create AI personalities with any prompt. You can create any kinds of characters with different personalities with some tools like . However, it's centralized, non-transparent, and unable to achieve consensus.

If we want to describe AI personalities in a decentralized environment , and access it without relying on any centralized 3rd parties, we need to define a standard to implement this process, ensuring that anyone can obtain the same AI personality through the same protocol.

AI721 is the key to make it happen.

How it works

In the AI721 protocol, the AI Personality of an AI-NFT is defined by these core components below:

  • LLM: The large language model that can comprehend and generate human language text. It provides basic AI capabilities for your AI-NFT.

  • Trait model: A collection-level function that inputs the AI-NFT's traits and outputs a set of prompt, defining the independent personality that is only related to its traits, as an initial state.

  • Memory: The memories, or knowledge that form the final AI personality, manifested through promps in conversation with the AI agent.

    • Public Memory: A predefined and public memory that anyone can use to form an AI personality.

    • Private Memory: A user-level private memory that shared with your AI agent, can be only read by the NFT owner.

How to describe AI Agent on chain?

AI Metadata Standard

AI721 defines a new kind of JSON metadata to describe an AI personality. The metadata standard includes three important parameters to index the AI personality. This metadata is different from the one for ERC721, and can be stored on-chain or off-chain.

Parameter
Format
Description

llm

URI

The uri to access LLM that is stored in off-chain storages.

trait_model

string/URI

public_memories

URI

(Optional) The uri to access the list of public memories needed to form an AI agent.

workflow

URI

(Optional) The uri to access the workflow file that describes the action chain of an AI agent.

Trait Model Example

A typical traits array from the metadata of a certain NFT is like:

{
  "attributes": [ 
    {
      "trait_type": "Base", 
      "value": "Starfish"
    }, 
    {
      "trait_type": "Eyes", 
      "value": "Big"
    }, 
    {
      "trait_type": "Mouth", 
      "value": "Surprised"
    }, 
  ],
}

We need to convert it to:

{
    "Base":"Starfish",
    "Eyes":"Big",
    "Mouth":"Surprised"
}

Then the trait_model could be like:

"You have these traits below:
- Base: {{Base}}, means the basic nation
- Eyes: {{Eyes}}, means what your eyes are look like
- Mouth: {{Mouth}}, means what your month are look like
- Influence: High, means your reputation
- Personality: Analytical, Pragmatic, Influential
"

On the application side, after you retrieve trait_model , you can render the final prompt by filling in specific traits data with Jinja2.

Memory Structure

A single memory is described as a JSON file.

Parameter
Type
Description

name

string

The name of this memory

description

string

(Optional) The description of this memory

logo

string

(Optional) The logo url or the memory

memory

string

The serialized form of this memory.

Workflow Structure

A workflow is a configuration described as a JSON file.

engine

string

version

number

(Optional) The engine version.

data

object

The DSL to describe the workflow of the AI agent.

Based on this design, AI721 can support various current and future AI agent workflow protocols, and use the corresponding engines to run AI agent services.

URI Format Supported

Format
Description

llm://{model}

Access a given LLM by calling APIs hosted by a party. This is only applicable for llm.

For examples:

  • "gpt-4" means gpt-4 model or its extended versions provided by OpenAI.

  • "gemini-1.0" means gemini-1.0 model or its extended versions provided by Google.

  • "any" means any LLMs can be used.

*The name must follow the naming conventions used in the API parameters provided by major model manufacturers.

ipfs://{cid}

The resources stored in IPFS/Filecoin. e.g. ipfs://QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR

ar://{cid}

The resources stored in Arweave. e.g. ar://k2g_3kYsPx-meD-AlyHhkUDYbUczlZ-M-bsKO6_oqY4

http(s)://{domain}/{path}

An typical http(s) url to locate resources.

... More formats from DePIN partners

How to design a workflow

How to access the AI agents described by AI721?

  1. Call tokenURI by tokenId of an AI721 contract, and pull the AI metadata of the NFT.

  2. Retrieve the LLM by llm and run as a service;

  3. Retrieve the trait model by trait_model. Input the traits set of the NFT to the model to obtain a set of prompt, and then integrate these prompt into the LLM you get in the previous step;

  4. (Optional) Retrieve one of the public memories from the public_memories , and integrate it into the LLM you get in the previous step. This allows you to quickly create a predefined AI personality.

  5. (Optional) Retrieve workflow and load it locally for the application layer to trigger at any time. If the workflow involves external LLMs, you can either replace them with the dedicated LLM from Step 4th or continue using the external LLM interface described by the DSL.

After these steps, you'll get your AI agent ready to use, with a pre-defined personality.

Implementing token URI of AI metadata

As what you have done for ERC721, you MUST implement tokenURI and return a URI where we can find the metadata.

Best Practice

You can deploy an AI721 contract inherit from ERC721 to issue AI-NFT. In this way, you MUST directly add new AIMetadata fields to ERC721 metadata. The application layer will call tokenURI(uint256 _tokenId) to access the metadata of an NFT and its AI personality directly.

Merged Metadata Example

// Merge AIMetadata with ERC721 metadata 
{
  // ERC721 metadata fields
  "description": "Friendly OpenSea Creature that enjoys long swims in the ocean.", 
  "external_url": "https://openseacreatures.io/3", 
  "image": "https://storage.googleapis.com/opensea-prod.appspot.com/puffs/3.png", 
  "name": "Dave Starbelly",
  "attributes": [ 
    {
      "trait_type": "Base", 
      "value": "Starfish"
    }, 
    {
      "trait_type": "Eyes", 
      "value": "Big"
    }, 
    {
      "trait_type": "Mouth", 
      "value": "Surprised"
    }, 
  ],
  // AI fields
  "llm":"llm://gpt-4",
  "trait_model":"
  - Base: {{Base}}
  - Eyes: {{Eyes}}
  - Mouth: {{Mouth}}
  - Influence: High
  - Personality: Analytical, Pragmatic, Influential
  ",
  "public_memories":"https://gonesis.ai/traveler/100/memories",
  "workflow":""
}

If your ERC721 contract was already deployed and you want to add AI capabilities for it, you need to deploy an independent AI721 contract, and use AILinker (a public smart contract) to link your ERC721 contract to AI721 contract.

Token URI for AI metadata

The independent AI721 contract MUST implement tokenURI and return a URI where we can find the metadata. This metadata MUST inherits from the original one and adds AI-related fields.

/**
 * @dev Returns the metadata URI for a given token ID.
 */
function tokenURI(uint256 _tokenId) public view returns (string memory) {
  string memory baseAIMetadataURI = ''; // Base AI metadata uri for your collection
  return string(abi.encodePacked(
      baseAIMetadataURI,
      _toString(_tokenId)
  ));
}

You can utilize an existing AILinker contract, or deploy your independent one. As the ecosystem grows, creators can link the same ERC721 contract to multiple AI721 contracts across different apps.

Gonesis team will deploy an official AILinker contract, and provide a public UI to facilitate the link configuration for creators.

AILinker Code Snippet

/**
 * @dev Links an ERC721 contract to multiple AI721 contracts.
 * @param erc721Contract The address of the ERC721 contract.
 * @param ai721Contracts An array of addresses representing the AI721 contracts to be linked.
 * 
 * Requirements:
 * 
 * - The caller must be the owner of the input erc721Contract
 * - The input ai721Contracts must impl aiMetadataURI
 */
function linkERC721ToAI721(address erc721Contract, address[] memory ai721Contracts) external {
    // Validate that the caller is the owner of the ERC721 contract
    require(msg.sender == Ownable(erc721Contract).owner(), "AILinker: Caller is not the owner of the ERC721 contract");
    // TODO: Add additional validation for ai721Contracts implementation of aiMetadataURI
    
    // Store the link between the ERC721 contract and the AI721 contracts
    links[erc721Contract] = ai721Contracts;
}

/**
 * @dev Retrieves the AI721 contracts linked to a specific ERC721 contract.
 * @param erc721Contract The address of the ERC721 contract.
 * @return An array of addresses representing the linked AI721 contracts.
 */
function getAI721Contracts(address erc721Contract) external view returns (address[] memory) {
    return links[erc721Contract];
}

Best Practice

We assume you already have deployed an ERC721 contract. So there are the steps to link your ERC721 contract to an AI721 contract. By establishing this link, you can add AI personalities to the NFTs in your ERC721 collection, and enable interaction through the applications.

Step 1: Prepare AI metadata

Step 2: Deploy AI721 contract

Deploy the AI721 contract for your ERC721 collection. This contract needs to implement the tokenURI interface to allow access to the AI metadata of the collection.

Step 3: Link ERC721 to AI721

You must link your ERC721 contract to the AI721 contract you just deployed, in an AILinker contract provided by the app layer. The app layer will use it to see which ERC721 is linked to a specific AI721 collection.

These are the steps to link ERC721 to AI721. By following these steps, you can associate AI metadata with your ERC721 collection, and enable interaction with the AI721 applications.

Please ensure to follow security best practices and perform proper testing and validation of your collection and contracts when deploying the contracts and configuration.

We recommend the application layer to firstly access AI metadata embedded in ERC721 contract to query AI personalities. If not found, then use AILinker to query.

Example

Workflow: A workflow is defined as a structured sequence of operations that organizes tasks into manageable steps. Compatible with the data structure of the workflow on .

Check .

The prompt template that generates the final prompt from the traits and other storyline of AI-NFT, by using placeholders of the form ${trait_type} , to define an independent and unique personality. Check .

The application layer can choose from these memories to create specific AI agents, like a virtual lawyer, math teacher, or virtual girlfriend/boyfriend. Check and .

We use as the templating engine for trait model.{{Base}}, {{Eyes}}, {{Mouth}} are all placeholders in the template that will be replaced with traits.Base, traits.Eyes and traits.Mouth of a specific AI-NFT.

The engine that can run the workflow given by workflow.data. For example, If the workflow originates from , or is compatible with this platform, set this field to “dify”.

The application layer can determine how to access these models' API endpoints, for example, by registering a developer account at

Check the .

Prepare AI metadata for your collection according to . If you want a quick start, you can choose from a selection of pre-trained AI metadata that we will make publicly available.

character.ai
dify.ai
Jinja2
section
An example for Azuki
An example for AI Agents
AI Metadata Standard
URI Format Supported
Trait Model Example
URI Format Supported
Memory Structure
dify.ai
openai.com.