Docs/Examples/Ai Agent Loop

AIAgentLoop (Neutral AI Scheduling)

Fires AgentTick events on schedule so off-chain AI workers can act on-chain without any single operator controlling the cadence.


Overview

AIAgentLoop is the simplest possible AutoLoop agent. It does nothing on-chain except fire an AgentTick event. The value is entirely in what it prevents: no single operator controls when the AI agent runs, which matters for any LLM-based workflow where timing affects fairness or predictability.

PropertyValue
Base contractAutoLoopCompatible (no VRF)
VRF usageNone
Gas per tick~28k
Sourceautoloop/src/agents/AIAgentLoop.sol
Tests13 passing (unit + fuzz)

Why AutoLoop Is Structurally Required

LLM agents need neutral on-chain scheduling. When an AI agent holds assets or makes decisions that affect other parties, the party that controls when the agent runs holds informational and timing power. AutoLoop provides a neutral cadence that no single principal can manipulate.

Mechanics

  • shouldProgressLoop() returns true when block.timestamp - lastTick >= tickInterval and totalTicks < maxTicks (or maxTicks == 0 for unlimited)
  • progressLoop() increments totalTicks, updates lastTick, and emits AgentTick(loopID, tickNumber, instructionHash, timestamp)
  • Instruction hash: a bytes32 value pointing to an IPFS CID or similar content address. Off-chain workers fetch instructions from the hash and act accordingly
  • maxTicks: optional limit — set to 0 for an infinite loop

Extending

Off-chain workers subscribe to AgentTick events and:

  1. Decode instructionHash from the event
  2. Fetch the instruction document (e.g., IPFS, Arweave)
  3. Execute the action (token transfer, API call, LLM inference → on-chain response)

Deploy

forge create src/agents/AIAgentLoop.sol:AIAgentLoop \
  --constructor-args 3600 0 \
  --rpc-url $RPC_URL --private-key $PRIVATE_KEY --broadcast

Args: tickInterval (seconds), maxTicks (0 = unlimited).

Dashboard

View AIAgentLoop on the AutoLoop Dashboard.