🤖Working with Agents

Complete guide for managing AI agents using the Somnia Agent Kit SDK.

Overview

The SDK provides simple methods to register, query, and manage AI agents on the Somnia blockchain.

Initialize SDK

import { SomniaAgentKit, SOMNIA_NETWORKS } from 'somnia-agent-kit';

const kit = new SomniaAgentKit({
  network: SOMNIA_NETWORKS.testnet,
  contracts: {
    agentRegistry: '0xC9f3452090EEB519467DEa4a390976D38C008347',
    agentManager: '0x77F6dC5924652e32DBa0B4329De0a44a2C95691E',
    agentExecutor: '0x157C56dEdbAB6caD541109daabA4663Fc016026e',
    agentVault: '0x7cEe3142A9c6d15529C322035041af697B2B5129',
  },
  privateKey: process.env.PRIVATE_KEY, // Optional for read operations
});

await kit.initialize();

Register Agent

Register a new AI agent on-chain:

circle-info

Note: The registerAgent function takes 4 parameters: name, description, ipfsMetadata, and capabilities array.

Query Agents

Get Total Agents

Get Agent by ID

Get Agents by Owner

Get All Agents

circle-exclamation

Update Agent

Update Agent Info

Manage Agent Status

Set Agent Status

circle-info

Note: Use setAgentStatus(agentId, isActive) instead of separate deactivateAgent() and reactivateAgent() methods.

Transfer Ownership

Listen to Events

Agent Registered Event

Agent Updated Event

Agent Status Changed Event

Complete Example

Best Practices

1. Always Initialize SDK

2. Handle Errors

3. Check Agent Exists

4. Verify Ownership

See Also

Last updated