ERC-8301 On-chain execution standard for AI agents (AI Agent Execution)
Draft · Other · created 2026-06-15
A standard interface that lets a smart contract delegate tasks to AI agents and record the responses and proofs on chain so that anyone can verify the process.
Why it is needed
Current standards for connecting AI agents to blockchains each handle their own area well, such as identity (ERC-8004), transactions (ERC-8183), and tool registration (ERC-8257), but the actual mechanism for assigning tasks to agents and receiving results back differs by protocol. ERC-8183 packages tasks as free-form strings, while ERC-8004 leaves execution itself to off-chain convention. As a result, agent developers must write separate integration code for each protocol, and an agent built for one protocol is hard to reuse as is on another. Also, when task distribution and verification are left to off-chain coordination, the reliability of the outcome depends on how much a specific agent or operator is trusted, and it is hard for outsiders to tell if a step was skipped or the order was changed.
What to implement
function getAgentTask(bytes32 taskHash) external view returns (AgentTask memory task, bool proven);: Returns the stored AgentTask and whether that task is in a proven state on the evidence chain.function onAgentReply(AgentReply calldata reply) external returns (bytes32 replyHash);: An agent submits a response to a task assigned to it.function onAgentProve(bytes32[] calldata replyHashes, bytes calldata proof) external;: Submits proof data for already-recorded responses to put them into a proven state.
In depth
AgentTask and AgentReply structure
AgentTask consists of stage, taskSeq (a sequence number within the run), inputHash, input (plaintext, may be empty), timestamp, expiresAt, prevReplyHashes (the responses that triggered this task, empty for the initial task), and workflowRunId. AgentReply consists of operationId, outputHash, output (plaintext, may be empty), timestamp, replier, prevTaskHashes (the tasks the response refers to, which must not be empty), and workflowRunId. The input and output plaintext need not be on chain, but inputHash and outputHash always commit to the content.
Computing taskHash and replyHash
taskHash is computed as the keccak256 of the abi.encode of stage, taskSeq, inputHash, timestamp, expiresAt, the keccak256 of prevReplyHashes, and workflowRunId; the input plaintext is excluded. Even when prevReplyHashes is an empty array, the hash inside it is fixed as keccak256(abi.encodePacked([])), which is 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470, and must not be treated specially as bytes32(0). replyHash is computed from operationId, outputHash, timestamp, replier, the hash of prevTaskHashes, and workflowRunId.
Retry handling via operationId
operationId must not be 0, and must be set by whoever first submits the reply and kept unchanged across retries. The contract first uses workflowRunId, replier, and operationId to construct an operationKey and checks whether it is already bound. If the replyDigest (the core content excluding timestamp) is the same, it is treated as a logical retry: the existing replyHash is returned as is and the state is not changed again. If the digest differs, it is treated as an operationId collision and reverts.
onAgentReply validation order
The contract first checks that reply.replier == msg.sender and that operationId is not 0, then looks up operationKey/replyDigest to determine whether this is a retry, then checks whether each task in prevTaskHashes is a valid task belonging to the same workflowRunId, whether execution is Pending, and whether the referenced tasks are still eligible to receive a reply, and finally checks that reply.timestamp is later than the timestamps of the referenced tasks and no later than block.timestamp. If all checks pass, it computes and stores replyHash, emits AgentReplyAnchored, and if the current stage is async, immediately evaluates the gate.
onAgentProve and proof verification
onAgentProve takes the list of already-recorded replyHashes and the proof data and calls the verifier. inputHash is not supplied by the caller but pulled from the stored prevTaskHashes[0] task, preventing a hash-substitution attack. Before calling the verifier, all referenced tasks must be in the proven state, otherwise it reverts. The verifier can be either IAgentVerifier, which binds identity, or IProofVerifier, which is identity-agnostic; the implementation chooses. If verification fails, the existing state is preserved so it can be retried later; if it succeeds, the reply is marked proven, and if that reply belongs to the current synchronous stage, the gate is evaluated.
Gate modes and termination handling
The gate is evaluated right after onAgentReply in async mode, and after a successful onAgentProve in sync mode. The result is one of: pass (transition to the next stage), retry, abort (Failed), or silent ignore (leave the stage open as is). The final gate that ends in success must always be synchronous, and on passing, a new final AgentTask representing the completed state is created and stored. This task has stage set to a value denoting termination (e.g., type(uint8).max), inputHash set to 0, prevReplyHashes set to all replies that satisfied the gate, and timestamp and expiresAt filled with the block.timestamp at completion. After this, WorkflowCompleted is emitted and any new onAgentReply/onAgentProve for that run is rejected.
Evidence chain and proven propagation
AgentTask and AgentReply alternately reference each other via prevReplyHashes/prevTaskHashes, forming a bidirectional chain. A task is proven when prevReplyHashes is empty (the initial task) or when every reply in it is proven, and a reply is proven when all tasks it references are proven and the proof is either exempted or onAgentProve has succeeded. This proven flag is merely a cache that avoids retracing the entire chain every time; the actual basis of trust is the hash linkage itself, which anyone can trace directly from result().finalTaskHash back to the initial task.
Static FSM vs dynamic FSM, and the current status of the standard
A static FSM fixes all stages and transitions at deployment time, preventing operators from skipping declared stages and structurally preventing omissions. This suits cases like audits or regulatory evidence where every stage must be proven to have executed. In a dynamic FSM, as in competitive selection, commit-reveal, or BFT voting, the actual path is determined at runtime based on gate evaluation and reply content; in that case, detecting omissions requires additional mechanisms such as a pre-declared expected path or timeouts. This proposal is still in Draft status, so details may change or be discontinued.
Things to watch out for
- Gate logic is outside the standard: This ERC only defines the calling interface and does not define what the gate actually checks. A malicious or poorly built workflow contract could have a gate that always passes, or could emit WorkflowCompleted(Success) without any verification. The fact that finalTaskHash is nonzero only guarantees gate enforcement when the contract is correctly implemented.
- Public exposure of input plaintext: The input plaintext carried in transaction data or events is exposed as is, even though it is committed as a hash. Sensitive input should be left empty, with delivery handled through a separate private channel.
- Reentrancy: External hooks should be called only after the reply is stored and AgentReplyAnchored is emitted, to prevent a callback from processing the same submission twice. Reentrancy protection is also needed during proof verification, and a reply should only be marked proven after verification succeeds.
- Task expiry and timeouts: A read-only query can show a timeout without changing state, but an actual retry or transition requires a transaction. To avoid dispatching a task whose expiry time has already passed, a nonzero deadline should be compared against the current block time at dispatch.
- Forwarded replies (proxy): When a proxy calls onAgentReply on behalf of someone else, both msg.sender and reply.replier become the proxy's address. How the proxy authenticates the actual agent and approves submission on its behalf is left to the application.