ERC-7662 AI agent NFT (AI Agent NFTs)
Draft · NFTs & multi-token · created 2024-03-26
A standard that allows creating and trading NFTs containing an AI agent's name, description, model, and prompt information. It is recommended that the prompt be encrypted so that only the NFT owner can view it.
Why it is needed
An AI agent consists of a name, a description, the AI model it will use, and a prompt (the instructions that define its behavior). To mint such an agent as an NFT and trade it, the prompt has to be stored somewhere, but existing ERC-721 offers no place for it other than token metadata, which anyone can see. That means someone who never bought the NFT could simply take the prompt. Prompts are also often too large to store directly on chain. And without a common format for agent data, marketplaces and agent management services each mint and read NFTs differently, so they end up incompatible with each other. This standard solves the problem by defining a common structure for agent data and recommending that prompts be kept in decentralized storage, encrypted so that only the NFT owner can decrypt them.
What to implement
event AgentUpdated(uint256 indexed tokenId);: An event signaling that the agent data for a given token has been updated.event AgentCreated(string name, string description, string model, address recipient, uint256 tokenId): A recommended event that announces key information when a new agent token is minted.
In depth
The IERC7662 interface
A contract that conforms to this standard must implement all of ERC-721's minting and transfer functions, plus the Agent interface. The core is the getAgentData(uint256 tokenId) function, which returns six values for a given token: name, description, model (the AI model used), userPromptURI (the user prompt URI), systemPromptURI (the system prompt URI), and promptsEncrypted (whether the prompts are encrypted). A mapping between token ID and agent data must also be implemented. The interface also defines the AgentUpdated(uint256 indexed tokenId) event.
Two approaches to keeping prompts private
The source text compares two approaches. The first keeps the mapping itself private and restricts access to functions only the NFT owner can call, but even then the prompt URL itself is exposed, which can reveal its contents. The second, recommended approach keeps the mapping public but encrypts the prompt URI and ties the decryption condition to the NFT owner through a custom contract parameter set at encryption time (for example, ownerOf(tokenId)). A public mapping also has the advantage that anyone can verify the existence of the name, description, model, and encrypted prompt URI. In addition, which encryption method or platform was used should be queryable as a data attribute of the NFT, so that platforms can handle decryption predictably.
Prompts are stored as decentralized storage URLs
Prompts can be quite large, making it unsuitable to store them directly on chain. So this standard proposes uploading prompts to decentralized storage and keeping that URL in the NFT's agent struct. Since existing ERC-721 has nowhere to put the prompt other than token metadata, and metadata is accessible to anyone, not just the NFT owner, the standard instead places it in a custom Agent struct and restricts access to the NFT holder.
Requirements for the minting function and encryption feature
A conforming contract MUST implement a function for minting new agent tokens. This function must take all agent attributes, name, description, model, userPromptURI, and systemPromptURI, as parameters, mint the token to the specified recipient, attach the attributes to the new token, and SHOULD emit a creation event. It is also RECOMMENDED to provide a prompt encryption feature: only the token owner should be able to perform encryption, which must update both prompt URIs to their encrypted versions and set a flag indicating the prompts are encrypted. Emitting an AgentCreated(name, description, model, recipient, tokenId) event at minting time is recommended.
Notation for dynamic variables and marketplace display
To use dynamic variables that get values substituted in before execution, the user prompt MUST wrap them in ${}, for example ${dynamicVariableName}. This lets programs such as web forms or automation systems recognize the variables and handle them appropriately. It is also recommended to add model data to ERC-721 so marketplaces can easily display agent information. The model name reveals the platform in use; the source text gives gpt-4-0125-preview as an example for OpenAI and claude-3-opus-20240229 for Anthropic. The standard's name and description fields can be used to display the agent's name and description.
ERC-721 compatibility and reference implementation
This standard is an extension that adds data and functionality to ERC-721 while remaining fully backward compatible. Existing functions such as transferFrom, approve, and balanceOf retain their original functionality and interfaces, so existing ERC-721 wallets and services can interact with these tokens without modification. In the reference implementation, the prompt is encrypted using the encryption platform's custom EVMContractParameters so that only the NFT holder can decrypt it, and the URL of the encrypted data is kept in decentralized storage. Because encryption and setting the decryption condition require a token ID, the NFT is minted first, and then an addEncryptedPrompts function is used to add the encrypted prompt URIs. The reference contract is located in the assets folder of the source document.
Still at the Draft stage
This proposal is in Draft status, and its contents may change going forward. The Security Considerations section of the source document is also still unwritten (TODO), so anyone implementing or referencing it should recheck the proposal's latest status and security discussion.