Skip to main content

Overview

Lifecycle methods manage the agent’s operational state. An agent transitions through several states from creation to deactivation. All methods in this section are called on an Agent instance.

State Diagram

The agent follows this state machine during its lifecycle: The AgentStatus enum maps to these states:

activate(options)

Activates the agent by registering the initial deposit, token, and protocol selection. Call this after the user has sent their deposit transaction.

Parameters

Address
required
The EOA address that owns the smart account.
Address
required
The deposit token address (e.g., USDC).
string[]
required
List of protocol names the agent should allocate to. Must contain at least one protocol.
string
required
The transaction hash of the user’s deposit into the smart account.
ConstraintConfig[]
Optional allocation constraints (min/max amounts per protocol, excluded protocols).

Return Type

Example

Activation with Constraints


deactivate(options?)

Deactivates the agent and optionally transfers remaining funds back to the owner. The agent withdraws from all protocols before deactivating.

Parameters

boolean
Whether to transfer funds back to the owner’s EOA. Defaults to true.

Return Type

Example

Deactivation is asynchronous. The agent enters the DEACTIVATING state and may take time to withdraw from all protocols. Use agent.waitForDeactivation() to poll until the process completes.

topUp(txHash)

Records an additional deposit into an already-active agent. Call this after the user sends a follow-up deposit transaction to the smart account.

Parameters

string
required
The transaction hash of the additional deposit.

Return Type

Example

The agent must be in the ACTIVATED state to accept a top-up. If the agent is deactivating or deactivated, the call will fail.

run()

Triggers a manual optimization run. The agent evaluates current protocol yields and rebalances allocations if a better distribution is found.

Return Type

Example

Agents also run automatically on a schedule. Use run() when you want to trigger an immediate rebalancing, for example after market conditions change.

Complete Lifecycle Example

Next Steps

Monitoring

Track portfolio value, APR, and performance history

Agent Overview

All Agent methods at a glance