Skip to main content

Agents.sol

Overview

The Agents.sol contract is the core registry and economic coordination layer for Nexis AI agents. It manages agent registration, staking mechanisms, reputation systems, proof-of-inference recording, and delegation permissions. The contract is implemented as an upgradeable (UUPS) module with role-based access control. Contract Location: /nexis-appchain/packages/contracts-bedrock/contracts/Agents.sol

Key Features

  • Agent Registration: Decentralized registry for AI agents with metadata and service endpoints
  • Multi-Asset Staking: Support for ETH and ERC20 token staking with unbonding periods
  • Reputation System: Multi-dimensional reputation tracking across reliability, accuracy, performance, and trustworthiness
  • Proof of Inference: On-chain commitment and attestation of AI model outputs
  • Delegation Framework: Granular permission delegation for metadata, inference, and withdrawal operations
  • Treasury Integration: Automated routing of slashed stakes and penalties to treasury pools

Architecture


Contract Roles

Access Control Roles

Delegation Permissions


Core Data Structures

AgentSummary

InferenceCommitment

StakeView

PendingWithdrawal

ReputationDelta


Agent Registration & Metadata

register

Register a new agent in the registry.
Parameters:
  • agentId: Unique identifier for the agent (chosen by registrant)
  • metadata: IPFS/Arweave URI containing agent description, capabilities, model info
  • serviceURI: Service endpoint for invoking the agent (HTTP API, gRPC, WebSocket, etc.)
Emits: AgentRegistered(address indexed owner, uint256 indexed agentId, string metadata, string serviceURI) Example:
Reverts:
  • AgentAlreadyRegistered(uint256 agentId, address currentOwner) if agent ID is taken

updateMetadata

Update agent metadata URI (owner or metadata delegate only).
Example:

updateServiceURI

Update agent service endpoint.

transferAgentOwnership

Transfer agent ownership to a new address.
Emits: AgentOwnershipTransferred(uint256 indexed agentId, address indexed previousOwner, address indexed newOwner)

Staking System

stakeETH

Stake native ETH to an agent.
Parameters:
  • agentId: Agent to stake for
  • msg.value: Amount of ETH to stake
Emits: StakeIncreased(uint256 indexed agentId, address indexed asset, address indexed staker, uint256 amount, uint256 totalStaked) Example:

stakeERC20

Stake ERC20 tokens to an agent.
Parameters:
  • agentId: Agent to stake for
  • token: ERC20 token address
  • amount: Token amount (in token’s smallest unit)
Prerequisites:
  • Caller must approve Agents contract to spend tokens
Example:

requestWithdrawal

Initiate unbonding period for stake withdrawal.
Parameters:
  • agentId: Agent ID
  • asset: Asset address (address(0) for ETH)
  • amount: Amount to withdraw
Behavior:
  • Immediately reduces active stake
  • Creates pending withdrawal entry with release timestamp
  • Release time = block.timestamp + unbondingPeriod[asset]
Emits: UnbondingInitiated(uint256 indexed agentId, address indexed asset, uint256 amount, uint64 releaseTime) Example:

claimWithdrawals

Claim matured withdrawals (or force early exit with penalty).
Parameters:
  • agentId: Agent ID
  • asset: Asset address
  • maxEntries: Maximum withdrawal queue entries to process (0 = unlimited)
  • receiver: Recipient address (address(0) = agent owner)
  • forceEarly: If true, claim withdrawals before unbonding period ends (incurs penalty)
Returns:
  • releasedAmount: Amount transferred to receiver
  • penaltyAmount: Penalty deducted (sent to treasury)
Emits:
  • WithdrawalExecuted(...) for normal withdrawals
  • EarlyWithdrawal(...) if forceEarly is true
Example:

cancelWithdrawal

Cancel a pending withdrawal and restore stake.
Parameters:
  • queueIndex: Index in withdrawal queue (relative to head)
Emits: WithdrawalCancelled(uint256 indexed agentId, address indexed asset, uint256 amount)

stakeBalances

Query stake amounts for an agent.
Returns:
Example:

Stake Locking (Task Integration)

lockStake

Lock stake for task execution (callable by Tasks contract via TASK_MODULE_ROLE).
Emits: StakeLocked(uint256 indexed agentId, address indexed asset, uint256 amount, uint256 newLockedBalance)

unlockStake

Unlock stake after task completion.
Emits: StakeUnlocked(uint256 indexed agentId, address indexed asset, uint256 amount, uint256 newLockedBalance)

Slashing

slashStake

Slash agent stake as penalty (callable by SLASHER_ROLE).
Behavior:
  • Reduces agent’s staked balance
  • Transfers slashed amount to Treasury
  • Treasury distributes across pools (40% treasury, 30% insurance, 30% rewards)
Emits: StakeSlashed(uint256 indexed agentId, address indexed asset, uint256 amount) Example:

Reputation System

Reputation Dimensions

Nexis agents are evaluated across four default dimensions: Each dimension is weighted equally by default (2500 BPS each = 25%).

adjustReputation

Adjust agent reputation in a specific dimension (callable by REPUTATION_ROLE).
Parameters:
  • dimension: Reputation dimension identifier
  • delta: Reputation change (positive or negative)
  • reason: Human-readable justification
Emits: ReputationAdjusted(uint256 indexed agentId, bytes32 indexed dimension, int256 newScore, string reason) Example:

aggregatedReputation

Calculate weighted aggregate reputation score.
Formula:
Returns: Weighted average reputation score (can be negative) Example:

updateReputationWeight

Update weighting for a reputation dimension (admin only).
Parameters:
  • weight: Weight in basis points (0-10000)

Inference Recording & Verification

recordInference

Record proof-of-inference commitment on-chain.
Parameters:
  • inputHash: Hash of inference input data
  • outputHash: Hash of model output/prediction
  • modelHash: Hash identifying model version
  • taskId: Associated task ID (0 if none)
  • proofURI: URI to proof artifacts (ZK proof, execution trace, etc.)
Returns: Unique inference ID (keccak256(agentId, nonce, inputHash, outputHash)) Authorization: Agent owner, inference delegate, or ORACLE_ROLE Emits: InferenceRecorded(...) Example:

attestInference

Attest to inference validity (callable by VERIFIER_ROLE).
Parameters:
  • inferenceId: Inference to attest
  • success: Whether inference passed verification
  • uri: URI to attestation report/details
  • deltas: Reputation adjustments to apply
Behavior:
  • Records attestation on-chain
  • Applies reputation deltas
  • If associated with a task, triggers Tasks.onInferenceVerified()
Emits: InferenceAttested(...) Example:

getInference

Retrieve inference commitment and attestation.
Example:

Delegation

setDelegate

Grant or revoke delegation permissions.
Parameters:
  • delegate: Address to grant/revoke permissions
  • permission: PERMISSION_METADATA, PERMISSION_INFERENCE, or PERMISSION_WITHDRAW
  • enabled: true to grant, false to revoke
Emits: DelegateUpdated(uint256 indexed agentId, address indexed delegate, bytes32 indexed permission, bool enabled) Example:

hasDelegatedPermission

Check if an address has delegated permission.
Example:

Discovery & Aggregation

listAgents

List agents with pagination.
Parameters:
  • offset: Starting index
  • limit: Maximum results (0 = all remaining)
Example:

aggregatedStats

Get network-wide statistics.
Returns:
Example:

Admin Functions

pause / unpause

Emergency pause contract operations.

setTreasury

Update treasury contract address.

setTasksContract

Set Tasks contract for inference verification callbacks.

setUnbondingPeriod

Configure unbonding period for an asset.
Example:

setEarlyExitPenalty

Set early withdrawal penalty in basis points.
Parameters:
  • bps: Penalty in basis points (0-10000, e.g., 500 = 5%)

Events Reference

Agent Lifecycle

Staking Events

Inference Events

Reputation Events

Delegation Events


Integration Examples

Full Agent Lifecycle


Security Considerations

Reentrancy Protection

All external functions handling value transfers are protected with nonReentrant modifier.

Access Control

  • Critical functions use role-based access control
  • Agent owners must explicitly delegate permissions
  • Delegation is granular (metadata, inference, withdrawal)

Upgradeability

  • UUPS proxy pattern for upgrades
  • Only DEFAULT_ADMIN_ROLE can authorize upgrades

Stake Safety

  • Locked stake cannot be withdrawn
  • Unbonding periods prevent instant exits
  • Early exit penalties discourage premature withdrawal

Gas Optimization Tips

  1. Batch Withdrawals: Use maxEntries parameter to limit gas costs
  2. Queue Management: Cancel unwanted withdrawals to avoid processing costs
  3. Delegation: Use delegates for frequent operations instead of owner multisig
  4. View Functions: Always use callStatic for queries to avoid unnecessary transactions


ABI & Deployment

ABI Location: /nexis-appchain/packages/contracts-bedrock/artifacts/contracts/Agents.sol/Agents.json Network Addresses:

Support & Resources