Skip to content

Commit

Permalink
AgentKit - Default Agent Config (#2505)
Browse files Browse the repository at this point in the history
* I add files for plugin-agentkit

* instructions added to gitignore.

* I update package name.

* I add updated files.

* I add ENV requirements to prevent default Eliza bugs.

* rollback index

* simple agentkit import.

* I load existing wallet data for provider.

* remove dev logging

* Update pnpm-lock.yaml

* update .env.example and support non 'base-sepolia'

* Update pnpm-lock.yaml

* Update package lock for smoke tests.

* I rollback changes to pnpm-lock file.

* fixing smoke tests for pnpm missing

* rollback changes to agent start file.

* I rollback changes to smoke test.

* Update pnpm-lock.yaml

* packages/plugin-agentkit/README.md - package name
    - actual: @ai16z/plugin-agentkit
    - required: @elizaos/plugin-agentkit

* add example network for agentkit.

* update plugin-agentkit README package name to correct ORG prefix.

* agent/src/index.ts - default plugin
    - actual:agentKitPlugin missing from AgentRuntime.plugins
    - required: agentKitPlugin added to AgentRuntime.plugins

* stylish build logging.

* wallet read from ENV instead of function variable.

* remove unintended changes to agent index.

---------

Co-authored-by: Sayo <82053242+wtfsayo@users.noreply.github.com>
Co-authored-by: Sayo <hi@sayo.wtf>
  • Loading branch information
3 people authored Jan 19, 2025
1 parent 9319fd3 commit 631cd6d
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 34 deletions.
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -368,9 +368,9 @@ COINBASE_GENERATED_WALLET_HEX_SEED= # Not your address but the wallet hex seed f
COINBASE_NOTIFICATION_URI= # For webhook plugin the uri you want to send the webhook to for dummy ones use https://webhook.site

# Coinbase AgentKit
COINBASE_AGENT_KIT_NETWORK= # defaults to 'base-sepolia'
CDP_API_KEY_NAME=
CDP_API_KEY_PRIVATE_KEY=
CDP_AGENT_KIT_NETWORK=base-sepolia # Optional: Defaults to base-sepolia

# Coinbase Charity Configuration
IS_CHARITABLE=false # Set to true to enable charity donations
Expand Down
6 changes: 5 additions & 1 deletion agent/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { TelegramClientInterface } from "@elizaos/client-telegram";
import { TwitterClientInterface } from "@elizaos/client-twitter";
import { FarcasterClientInterface } from "@elizaos/client-farcaster";
import { DirectClient } from "@elizaos/client-direct";
import { agentKitPlugin } from "@elizaos/plugin-agentkit";
// import { ReclaimAdapter } from "@elizaos/plugin-reclaim";
import { PrimusAdapter } from "@elizaos/plugin-primus";
import { elizaCodeinPlugin, onchainJson } from "@elizaos/plugin-iq6900";
Expand Down Expand Up @@ -250,7 +251,6 @@ export async function loadCharacterFromOnchain(): Promise<Character[]> {
}
}


async function loadCharactersFromUrl(url: string): Promise<Character[]> {
try {
const response = await fetch(url);
Expand Down Expand Up @@ -869,6 +869,10 @@ export async function createAgent(
? elizaCodeinPlugin
: null,
bootstrapPlugin,
getSecret(character, "CDP_API_KEY_NAME") &&
getSecret(character, "CDP_API_KEY_PRIVATE_KEY")
? agentKitPlugin
: null,
getSecret(character, "DEXSCREENER_API_KEY")
? dexScreenerPlugin
: null,
Expand Down
46 changes: 23 additions & 23 deletions packages/plugin-agentkit/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,18 @@ pnpm install
```env
CDP_API_KEY_NAME=your_key_name
CDP_API_KEY_PRIVATE_KEY=your_private_key
CDP_AGENT_KIT_NETWORK=base-sepolia # Optional: Defaults to base-sepolia
```

3. Add the plugin to your character configuration:

```json
{
"plugins": ["@ai16z/plugin-agentkit"],
"plugins": ["@elizaos/plugin-agentkit"],
"settings": {
"secrets": {
"CDP_API_KEY_NAME": "your_key_name",
"CDP_API_KEY_PRIVATE_KEY": "your_private_key",
"networkId": "base-sepolia"
"CDP_API_KEY_PRIVATE_KEY": "your_private_key"
}
}
}
Expand All @@ -36,18 +36,18 @@ CDP_API_KEY_PRIVATE_KEY=your_private_key

The plugin provides access to the following CDP AgentKit tools:

- `GET_WALLET_DETAILS`: Get wallet information
- `DEPLOY_NFT`: Deploy a new NFT collection
- `DEPLOY_TOKEN`: Deploy a new token
- `GET_BALANCE`: Check token or NFT balance
- `MINT_NFT`: Mint NFTs from a collection
- `REGISTER_BASENAME`: Register a basename for NFTs
- `REQUEST_FAUCET_FUNDS`: Request testnet funds
- `TRADE`: Execute trades
- `TRANSFER`: Transfer tokens or NFTs
- `WOW_BUY_TOKEN`: Buy WOW tokens
- `WOW_SELL_TOKEN`: Sell WOW tokens
- `WOW_CREATE_TOKEN`: Create new WOW tokens
- `GET_WALLET_DETAILS`: Get wallet information
- `DEPLOY_NFT`: Deploy a new NFT collection
- `DEPLOY_TOKEN`: Deploy a new token
- `GET_BALANCE`: Check token or NFT balance
- `MINT_NFT`: Mint NFTs from a collection
- `REGISTER_BASENAME`: Register a basename for NFTs
- `REQUEST_FAUCET_FUNDS`: Request testnet funds
- `TRADE`: Execute trades
- `TRANSFER`: Transfer tokens or NFTs
- `WOW_BUY_TOKEN`: Buy WOW tokens
- `WOW_SELL_TOKEN`: Sell WOW tokens
- `WOW_CREATE_TOKEN`: Create new WOW tokens

## Usage Examples

Expand Down Expand Up @@ -91,19 +91,19 @@ pnpm dev

## Dependencies

- @elizaos/core
- @coinbase/cdp-agentkit-core
- @coinbase/cdp-langchain
- @langchain/core
- @elizaos/core
- @coinbase/cdp-agentkit-core
- @coinbase/cdp-langchain
- @langchain/core

## Network Support

The plugin currently supports the following networks:
The plugin supports the following networks:

- Base Sepolia (default)
- Base Mainnet
- Base Sepolia (default)
- Base Mainnet

Configure the network using the `networkId` setting in your character configuration.
Configure the network using the `CDP_AGENT_KIT_NETWORK` environment variable.

## Troubleshooting

Expand Down
5 changes: 3 additions & 2 deletions packages/plugin-agentkit/src/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,9 @@ export async function getAgentKitActions({
const client = await getClient();
let currentState =
state ?? (await runtime.composeState(message));
currentState =
await runtime.updateRecentMessageState(currentState);
currentState = await runtime.updateRecentMessageState(
currentState
);

const parameterContext = composeParameterContext(
tool,
Expand Down
8 changes: 8 additions & 0 deletions packages/plugin-agentkit/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@ import type { Plugin } from "@elizaos/core";
import { walletProvider, getClient } from "./provider";
import { getAgentKitActions } from "./actions";

// Initial banner
console.log("\n┌════════════════════════════════════════┐");
console.log("│ AGENTKIT PLUGIN │");
console.log("├────────────────────────────────────────┤");
console.log("│ Initializing AgentKit Plugin... │");
console.log("│ Version: 0.0.1 │");
console.log("└════════════════════════════════════════┘");

export const agentKitPlugin: Plugin = {
name: "[AgentKit] Integration",
description: "AgentKit integration plugin",
Expand Down
10 changes: 3 additions & 7 deletions packages/plugin-agentkit/src/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ import * as fs from "fs";

const WALLET_DATA_FILE = "wallet_data.txt";

export async function getClient(
networkId = "base-sepolia"
): Promise<CdpAgentkit> {
export async function getClient(): Promise<CdpAgentkit> {
let walletDataStr: string | null = null;

// Read existing wallet data if available
Expand All @@ -22,7 +20,7 @@ export async function getClient(
// Configure CDP AgentKit
const config = {
cdpWalletData: walletDataStr || undefined,
networkId,
networkId: process.env.CDP_AGENT_KIT_NETWORK || "base-sepolia",
};

const agentkit = await CdpAgentkit.configureWithWallet(config);
Expand All @@ -36,9 +34,7 @@ export async function getClient(
export const walletProvider: Provider = {
async get(runtime: IAgentRuntime): Promise<string | null> {
try {
const client = await getClient(
runtime.getSetting("COINBASE_AGENT_KIT_NETWORK")
);
const client = await getClient();
const address = (await (client as any).wallet.addresses)[0].id;
return `AgentKit Wallet Address: ${address}`;
} catch (error) {
Expand Down

0 comments on commit 631cd6d

Please sign in to comment.