Create Your First Agent

1

Register with ERC-8004

Every agent receives a persistent agentId registered on-chain. This ID is portable across applications and chains, and serves as the root of the agent's identity and reputation.

2

Attach a Policy

Define the agent's operational boundaries: spend limits, allowed contracts, allowed assets, time windows, and approval thresholds. Policies are hashed and stored on-chain.

3

Authenticate with SIWX

The agent signs a structured SIWX message using its execution account key. The backend resolves the agentId and establishes a scoped session.

4

Propose and Execute Actions

The agent proposes actions. The policy engine evaluates, signs an approval proof, and submits a UserOperation via ERC-4337. Reputation is updated on completion.

Create Your First Agent

A Brain agent is a registered, policy-constrained execution context with a persistent on-chain identity. This guide walks through the full agent lifecycle from registration to execution.

Defining Agent Metadata

Agent metadata is stored off-chain (IPFS or a URL) and referenced on-chain via a metadataUri. The metadata describes the agent's capabilities and configuration.

{
  "name": "trading-agent-v1",
  "description": "DeFi trading agent with risk controls",
  "capabilities": ["swap", "lend", "borrow"],
  "version": "1.0.0",
  "owner": "0xYourAddress"
}

Creating the Agent

import { BrainClient, PolicyBuilder } from '@brain-protocol/sdk';

const policy = new PolicyBuilder()
  .setSpendLimit('500 USDC/day')
  .setAllowedAssets(['USDC', 'ETH', 'WBTC'])
  .setAllowedContracts(['0xUniswapV3', '0xAaveV3'])
  .setTimeWindow('09:00', '21:00', 'UTC')
  .setApprovalThreshold('1-of-1')
  .build();

const agent = await client.agents.deploy({
  accountAddress: account.address,
  name: 'trading-agent-v1',
  metadataUri: 'ipfs://QmYourMetadataHash',
  policy,
});

console.log('Agent deployed:', {
  agentId: agent.agentId,
  executionAddress: agent.executionAddress,
  policyHash: agent.policyHash,
});

Pausing and Revoking Agents

circle-exclamation

Agent Status Reference

Status
Description

active

Agent is running and can execute actions

paused

Agent is suspended; identity and reputation preserved

revoked

Permanent — agent can no longer execute actions

Last updated