Skip to content

Commit

Permalink
chore: adapt agent to bino
Browse files Browse the repository at this point in the history
  • Loading branch information
nicky-ru committed Dec 17, 2024
1 parent d46aa49 commit dc4cc0d
Show file tree
Hide file tree
Showing 3 changed files with 22,647 additions and 17,875 deletions.
17 changes: 1 addition & 16 deletions agent/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,33 +23,18 @@
"@ai16z/client-direct": "workspace:*",
"@ai16z/client-discord": "workspace:*",
"@ai16z/client-farcaster": "workspace:*",
"@ai16z/client-lens": "workspace:*",
"@ai16z/client-telegram": "workspace:*",
"@ai16z/client-twitter": "workspace:*",
"@ai16z/client-slack": "workspace:*",
"@ai16z/eliza": "workspace:*",
"@ai16z/plugin-0g": "workspace:*",
"@ai16z/plugin-aptos": "workspace:*",
"@ai16z/plugin-bootstrap": "workspace:*",
"@ai16z/plugin-intiface": "workspace:*",
"@ai16z/plugin-coinbase": "workspace:*",
"@ai16z/plugin-conflux": "workspace:*",
"@ai16z/plugin-evm": "workspace:*",
"@ai16z/plugin-flow": "workspace:*",
"@ai16z/plugin-story": "workspace:*",
"@ai16z/plugin-goat": "workspace:*",
"@ai16z/plugin-icp": "workspace:*",
"@ai16z/plugin-image-generation": "workspace:*",
"@ai16z/plugin-nft-generation": "workspace:*",
"@ai16z/plugin-node": "workspace:*",
"@ai16z/plugin-solana": "workspace:*",
"@ai16z/plugin-starknet": "workspace:*",
"@ai16z/plugin-ton": "workspace:*",
"@ai16z/plugin-sui": "workspace:*",
"@ai16z/plugin-tee": "workspace:*",
"@ai16z/plugin-multiversx": "workspace:*",
"@ai16z/plugin-near": "workspace:*",
"@ai16z/plugin-zksync-era": "workspace:*",
"@ai16z/plugin-web-search": "workspace:*",
"readline": "1.3.0",
"ws": "8.18.0",
"yargs": "17.7.2"
Expand Down
111 changes: 5 additions & 106 deletions agent/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@ import { SqliteDatabaseAdapter } from "@ai16z/adapter-sqlite";
import { AutoClientInterface } from "@ai16z/client-auto";
import { DiscordClientInterface } from "@ai16z/client-discord";
import { FarcasterAgentClient } from "@ai16z/client-farcaster";
import { LensAgentClient } from "@ai16z/client-lens";
import { SlackClientInterface } from "@ai16z/client-slack";
import { TelegramClientInterface } from "@ai16z/client-telegram";
import { TwitterClientInterface } from "@ai16z/client-twitter";
import { webSearchPlugin } from "@ai16z/plugin-web-search";
import {
AgentRuntime,
CacheManager,
Expand All @@ -15,7 +14,6 @@ import {
DbCacheAdapter,
defaultCharacter,
elizaLogger,
FsCacheAdapter,
IAgentRuntime,
ICacheManager,
IDatabaseAdapter,
Expand All @@ -25,34 +23,13 @@ import {
stringToUuid,
validateCharacterConfig,
} from "@ai16z/eliza";
import { zgPlugin } from "@ai16z/plugin-0g";
import { bootstrapPlugin } from "@ai16z/plugin-bootstrap";
import createGoatPlugin from "@ai16z/plugin-goat";
// import { intifacePlugin } from "@ai16z/plugin-intiface";
import { DirectClient } from "@ai16z/client-direct";
import { aptosPlugin } from "@ai16z/plugin-aptos";
import {
advancedTradePlugin,
coinbaseCommercePlugin,
coinbaseMassPaymentsPlugin,
tokenContractPlugin,
tradePlugin,
webhookPlugin,
} from "@ai16z/plugin-coinbase";
import { confluxPlugin } from "@ai16z/plugin-conflux";
import { evmPlugin } from "@ai16z/plugin-evm";
import { storyPlugin } from "@ai16z/plugin-story";
import { flowPlugin } from "@ai16z/plugin-flow";
import { imageGenerationPlugin } from "@ai16z/plugin-image-generation";
import { multiversxPlugin } from "@ai16z/plugin-multiversx";
import { nearPlugin } from "@ai16z/plugin-near";
import { nftGenerationPlugin } from "@ai16z/plugin-nft-generation";
import { createNodePlugin } from "@ai16z/plugin-node";
import { solanaPlugin } from "@ai16z/plugin-solana";
import { suiPlugin } from "@ai16z/plugin-sui";
import { TEEMode, teePlugin } from "@ai16z/plugin-tee";
import { tonPlugin } from "@ai16z/plugin-ton";
import { zksyncEraPlugin } from "@ai16z/plugin-zksync-era";
import Database from "better-sqlite3";
import fs from "fs";
import path from "path";
Expand Down Expand Up @@ -382,20 +359,9 @@ export async function initializeClients(
clients.farcaster = farcasterClient;
}
}
if (clientTypes.includes("lens")) {
const lensClient = new LensAgentClient(runtime);
lensClient.start();
clients.lens = lensClient;
}

elizaLogger.log("client keys", Object.keys(clients));

// TODO: Add Slack client to the list
if (clientTypes.includes("slack")) {
const slackClient = await SlackClientInterface.start(runtime);
if (slackClient) clients.push(slackClient);
}

if (character.plugins?.length > 0) {
for (const plugin of character.plugins) {
// if plugin has clients, add those..
Expand Down Expand Up @@ -466,13 +432,6 @@ export async function createAgent(
throw new Error("Invalid TEE configuration");
}

let goatPlugin: any | undefined;
if (getSecret(character, "ALCHEMY_API_KEY")) {
goatPlugin = await createGoatPlugin((secret) =>
getSecret(character, secret)
);
}

return new AgentRuntime({
databaseAdapter: db,
token,
Expand All @@ -482,72 +441,19 @@ export async function createAgent(
// character.plugins are handled when clients are added
plugins: [
bootstrapPlugin,
getSecret(character, "CONFLUX_CORE_PRIVATE_KEY")
? confluxPlugin
: null,
nodePlugin,
getSecret(character, "SOLANA_PUBLIC_KEY") ||
(getSecret(character, "WALLET_PUBLIC_KEY") &&
!getSecret(character, "WALLET_PUBLIC_KEY")?.startsWith("0x"))
? solanaPlugin
: null,
(getSecret(character, "NEAR_ADDRESS") ||
getSecret(character, "NEAR_WALLET_PUBLIC_KEY")) &&
getSecret(character, "NEAR_WALLET_SECRET_KEY")
? nearPlugin
: null,
webSearchPlugin,
getSecret(character, "EVM_PUBLIC_KEY") ||
(getSecret(character, "WALLET_PUBLIC_KEY") &&
getSecret(character, "WALLET_PUBLIC_KEY")?.startsWith("0x"))
? evmPlugin
: null,
(getSecret(character, "SOLANA_PUBLIC_KEY") ||
(getSecret(character, "WALLET_PUBLIC_KEY") &&
!getSecret(character, "WALLET_PUBLIC_KEY")?.startsWith(
"0x"
))) &&
getSecret(character, "SOLANA_ADMIN_PUBLIC_KEY") &&
getSecret(character, "SOLANA_PRIVATE_KEY") &&
getSecret(character, "SOLANA_ADMIN_PRIVATE_KEY")
? nftGenerationPlugin
: null,
getSecret(character, "ZEROG_PRIVATE_KEY") ? zgPlugin : null,
getSecret(character, "COINBASE_COMMERCE_KEY")
? coinbaseCommercePlugin
: null,
getSecret(character, "FAL_API_KEY") ||
getSecret(character, "OPENAI_API_KEY") ||
getSecret(character, "VENICE_API_KEY") ||
getSecret(character, "HEURIST_API_KEY")
? imageGenerationPlugin
: null,
...(getSecret(character, "COINBASE_API_KEY") &&
getSecret(character, "COINBASE_PRIVATE_KEY")
? [
coinbaseMassPaymentsPlugin,
tradePlugin,
tokenContractPlugin,
advancedTradePlugin,
]
: []),
...(teeMode !== TEEMode.OFF && walletSecretSalt
? [teePlugin, solanaPlugin]
: []),
getSecret(character, "COINBASE_API_KEY") &&
getSecret(character, "COINBASE_PRIVATE_KEY") &&
getSecret(character, "COINBASE_NOTIFICATION_URI")
? webhookPlugin
: null,
getSecret(character, "ALCHEMY_API_KEY") ? goatPlugin : null,
getSecret(character, "FLOW_ADDRESS") &&
getSecret(character, "FLOW_PRIVATE_KEY")
? flowPlugin
: null,
getSecret(character, "APTOS_PRIVATE_KEY") ? aptosPlugin : null,
getSecret(character, "MVX_PRIVATE_KEY") ? multiversxPlugin : null,
getSecret(character, "ZKSYNC_PRIVATE_KEY") ? zksyncEraPlugin : null,
getSecret(character, "TON_PRIVATE_KEY") ? tonPlugin : null,
getSecret(character, "SUI_PRIVATE_KEY") ? suiPlugin : null,
getSecret(character, "STORY_PRIVATE_KEY") ? storyPlugin : null,
].filter(Boolean),
providers: [],
Expand All @@ -559,13 +465,6 @@ export async function createAgent(
});
}

function initializeFsCache(baseDir: string, character: Character) {
const cacheDir = path.resolve(baseDir, character.id, "cache");

const cache = new CacheManager(new FsCacheAdapter(cacheDir));
return cache;
}

function initializeDbCache(character: Character, db: IDatabaseCacheAdapter) {
const cache = new CacheManager(new DbCacheAdapter(db, character.id));
return cache;
Expand Down Expand Up @@ -648,9 +547,9 @@ const startAgents = async () => {
}

// upload some agent functionality into directClient
directClient.startAgent = async character => {
// wrap it so we don't have to inject directClient later
return startAgent(character, directClient)
directClient.startAgent = async (character) => {
// wrap it so we don't have to inject directClient later
return startAgent(character, directClient);
};
directClient.start(serverPort);

Expand Down
Loading

0 comments on commit dc4cc0d

Please sign in to comment.