Actions are grouped into action providers, which may have specific dependencies like API keys. You can find all of the action providers and actions supported by AgentKit at the following links:

Generally, Node.js supports more crypto-specific actions than the Python version.

By default, AgentKit supports the following actions in the ‘wallet’ action provider:

  • get_wallet_details - Get details about the Wallet, like the address
  • native_transfer - Transfer native asset between addresses
  • get_balance - Get the balance of the native asset

Adding Action Provider Groupings

Adding an existing action provider to your agent is a two-step process:

  1. Import the action provider to your file
  2. Add the action provider to your AgentKit instance
import {
  AgentKit,
  CdpWalletProvider,
  walletActionProvider,
  erc721ActionProvider,
  cdpApiActionProvider,
  cdpWalletActionProvider,
  pythActionProvider,
} from "@coinbase/agentkit";

const erc721 = erc721ActionProvider();
const pyth = pythActionProvider();
const wallet = walletActionProvider(); // default action package: get balance, native transfer, and get wallet details
const cdp = cdpApiActionProvider({ // for providers that require API keys include them in their instantiation
  apiKeyName: process.env.CDP_API_KEY_NAME,
  apiKeyPrivateKey: process.env.CDP_API_KEY_PRIVATE_KEY?.replace(/\\n/g, "\n"),
});

const agentKit = await AgentKit.from({
  walletProvider,
  actionProviders: [erc721, pyth, wallet, cdp],
});

Creating an Action Provider

Action providers define the actions that an agent can take. They are created by subclassing the ActionProvider abstract class.

import { ActionProvider, WalletProvider, Network } from "@coinbase/agentkit";

// Define an action provider that uses a wallet provider.
class MyActionProvider extends ActionProvider<WalletProvider> {
constructor() {
    super("my-action-provider", []);
}

// Define if the action provider supports the given network
supportsNetwork = (network: Network) => true;
}

Adding Actions to an Action Provider

Actions are defined as instance methods on the action provider class with the @CreateAction decorator. Actions can use a wallet provider or not and always return a Promise that resolves to a string.

Required Typescript Compiler Options

Creating actions with the @CreateAction decorator requires the following compilerOptions to be included in your project’s tsconfig.json.

{
    "compilerOptions": {
        "experimentalDecorators": true,
        "emitDecoratorMetadata": true
    }
} 

Steps to create an action

  1. Define the action schema. Action schemas are defined using the zod library.
import { z } from "zod";

export const MyActionSchema = z.object({
  myField: z.string(),
});
  1. Define the action implementation.
import { ActionProvider, WalletProvider, Network, CreateAction } from "@coinbase/agentkit";

class MyActionProvider extends ActionProvider<WalletProvider> {
    constructor() {
        super("my-action-provider", []);
    }

    @CreateAction({
        name: "my-action",
        description: "My action description",
        schema: MyActionSchema,
    })
    async myAction(args: z.infer<typeof MyActionSchema>): Promise<string> {
        return args.myField;
    }

    supportsNetwork = (network: Network) => true;
}

export const myActionProvider = () => new MyActionProvider();

Adding Actions to your Action Provider that use a Wallet Provider

Actions that use a wallet provider can be defined as instance methods on the action provider class with the @CreateAction decorator that have a WalletProvider as the first parameter.

class MyActionProvider extends ActionProvider<WalletProvider> {
    constructor() {
        super("my-action-provider", []);
    }

    @CreateAction({
        name: "my-action",
        description: "My action description",
        schema: MyActionSchema,
    })
    async myAction(walletProvider: WalletProvider, args: z.infer<typeof MyActionSchema>): Promise<string> {
        return walletProvider.signMessage(args.myField);
    }

    supportsNetwork = (network: Network) => true;
}

Adding an Action Provider to your AgentKit instance

const agentKit = new AgentKit({
  cdpApiKeyName: "CDP API KEY NAME",
  cdpApiKeyPrivate: "CDP API KEY PRIVATE KEY",
  actionProviders: [myActionProvider()],
});

For actions to be made available for any agent, we welcome open-source contributions to AgentKit for adding more actions! Please see our contribution guide for more information.