Skip to main content

Method Signature

agent.activate(params: ActivateParams): Promise<ActivateResponse>

Description

Activates an autonomous agent to manage capital in a smart account. Once activated, the agent continuously monitors APRs and automatically rebalances funds across selected protocols for optimal yield.

Parameters

wallet
Address
required
Smart account address to activate.
origin_wallet
Address
required
User’s origin wallet (EOA or smart wallet).
initial_token
Address
required
Token address deposited (e.g., USDC address).
selected_protocols
string[]
required
Array of protocol names the agent can use. Get available protocols with getProtocols().Example: ["aave", "compound", "moonwell"]
tx_hash
string
Optional but recommended. Deposit transaction hash for verification.
constraints
ConstraintConfig[]
Optional constraints to control agent behavior.Example:
[{
  kind: 'min_protocols',
  params: { min_protocols: 2 }
}]

Return Value

message
string
Success message confirming activation.
wallet
string
Smart account address that was activated.

Example

import { GizaAgent, Chain } from '@giza/agent-sdk';

const giza = new GizaAgent({ chainId: Chain.BASE });

const USDC_BASE = '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913';

await giza.agent.activate({
  wallet: smartAccountAddress,
  origin_wallet: userWallet,
  initial_token: USDC_BASE,
  selected_protocols: ['aave', 'compound', 'moonwell'],
  tx_hash: depositTxHash, // Optional but recommended
  constraints: [
    {
      kind: 'min_protocols',
      params: { min_protocols: 2 } // Always diversify
    },
    {
      kind: 'max_amount_per_protocol',
      params: { max_amount: '5000000000' } // Cap at 5000 USDC per protocol
    }
  ]
});

console.log('✅ Agent activated and optimizing!');

Constraints

Available constraint types:
ConstraintDescriptionParameters
min_protocolsMinimum protocols to use{ min_protocols: number }
max_amount_per_protocolCap per any protocol{ max_amount: string }
max_allocation_amount_per_protocolCap specific protocol{ protocol: string, max_amount: string }
exclude_protocolBlacklist protocol{ protocol: string }
min_amountMin per protocol{ min_amount: string }

Error Handling

import { ValidationError, GizaAPIError } from '@giza/agent-sdk';

try {
  await giza.agent.activate({
    wallet: smartAccountAddress,
    origin_wallet: userWallet,
    initial_token: USDC_ADDRESS,
    selected_protocols: ['aave', 'compound'],
  });
} catch (error) {
  if (error instanceof ValidationError) {
    console.error('Invalid parameters:', error.message);
  } else if (error instanceof GizaAPIError) {
    console.error('Activation failed:', error.message);
    // Check if funds were deposited
    // Check if protocols are available
  }
}

Common Errors

ErrorCauseSolution
ValidationError: At least one protocol must be selectedEmpty protocols arrayProvide at least one protocol
GizaAPIError: No deposits foundSmart account has no balanceEnsure user deposited funds first
GizaAPIError: Invalid protocolProtocol not availableCheck available protocols with getProtocols()

Notes

Activation initiates the process but agents may take a few moments to start optimizing. Check status with getPortfolio().
Including the deposit tx_hash helps verify funds and speeds up activation.
Choose at least 2-3 protocols for diversification and better optimization opportunities.

Next Steps