UNPKG

@brian-ai/langchain

Version:

Repository containing the LangchainJS toolkit for creating powerful web3 agents.

272 lines (258 loc) 9.8 kB
import { BaseTracer, Run } from '@langchain/core/tracers/base'; import { HandlerContext } from '@xmtp/message-kit'; import { LanguageModelLike } from '@langchain/core/language_models/base'; import { BrianSDK } from '@brian-ai/sdk'; import { BaseToolkit, ToolInterface } from '@langchain/core/tools'; import { Hex, Account } from 'viem'; import { AgentExecutor } from 'langchain/agents'; import * as _langchain_core_dist_types_zod from '@langchain/core/dist/types/zod'; import { Wallet, WalletData } from '@coinbase/coinbase-sdk'; import { Account as Account$1 } from 'starknet'; import { NeynarAPIClient } from '@neynar/nodejs-sdk'; import { Scraper } from 'agent-twitter-client'; import { MemoryVectorStore } from 'langchain/vectorstores/memory'; import { SupabaseVectorStore } from '@langchain/community/vectorstores/supabase'; type XMTPCallbackHandlerOptions = { onChainStart?: boolean; onChainEnd?: boolean; onChainError?: boolean; onLLMStart?: boolean; onLLMEnd?: boolean; onLLMError?: boolean; onToolStart?: boolean; onToolEnd?: boolean; onToolError?: boolean; onRetrieverStart?: boolean; onRetrieverEnd?: boolean; onRetrieverError?: boolean; onAgentAction?: boolean; }; /** * @dev XMTP callback handler class. */ declare class XMTPCallbackHandler extends BaseTracer { name: "xmtp_callback_handler"; xmtpHandler: HandlerContext; llm: LanguageModelLike; instructions: string; options: XMTPCallbackHandlerOptions; protected persistRun(run: Run): Promise<void>; constructor(xmtpHandler: HandlerContext, llm: LanguageModelLike, instructions: string | undefined, options?: XMTPCallbackHandlerOptions); /** * Method used to get all the parent runs of a given run. * @param run The run whose parents are to be retrieved. * @returns An array of parent runs. */ getParents(run: Run): Run[]; /** * Method used to get a string representation of the run's lineage, which * is used in logging. * @param run The run whose lineage is to be retrieved. * @returns A string representation of the run's lineage. */ getBreadcrumbs(run: Run): string; /** * Method used to log the start of a chain run. * @param run The chain run that has started. * @returns void */ onChainStart(run: Run): Promise<void>; /** * Method used to log the end of a chain run. * @param run The chain run that has ended. * @returns void */ onChainEnd(run: Run): Promise<void>; /** * Method used to log any errors of a chain run. * @param run The chain run that has errored. * @returns void */ onChainError(run: Run): Promise<void>; /** * Method used to log the start of an LLM run. * @param run The LLM run that has started. * @returns void */ onLLMStart(run: Run): Promise<void>; /** * Method used to log the end of an LLM run. * @param run The LLM run that has ended. * @returns void */ onLLMEnd(run: Run): Promise<void>; /** * Method used to log any errors of an LLM run. * @param run The LLM run that has errored. * @returns void */ onLLMError(run: Run): Promise<void>; /** * Method used to log the start of a tool run. * @param run The tool run that has started. * @returns void */ onToolStart(run: Run): Promise<void>; /** * Method used to log the end of a tool run. * @param run The tool run that has ended. * @returns void */ onToolEnd(run: Run): Promise<void>; /** * Method used to log any errors of a tool run. * @param run The tool run that has errored. * @returns void */ onToolError(run: Run): Promise<void>; /** * Method used to log the start of a retriever run. * @param run The retriever run that has started. * @returns void */ onRetrieverStart(run: Run): Promise<void>; /** * Method used to log the end of a retriever run. * @param run The retriever run that has ended. * @returns void */ onRetrieverEnd(run: Run): Promise<void>; /** * Method used to log any errors of a retriever run. * @param run The retriever run that has errored. * @returns void */ onRetrieverError(run: Run): Promise<void>; /** * Method used to log the action selected by the agent. * @param run The run in which the agent action occurred. * @returns void */ onAgentAction(run: Run): Promise<void>; } type BrianToolOptions = { gelatoApiKey?: string; etherscanApiKey?: string; }; type BrianToolkitOptions = { apiKey: string; privateKeyOrAccount: Hex | Account; apiUrl?: string; options?: BrianToolOptions; }; declare class BrianToolkit extends BaseToolkit { account: Account; brianSDK: BrianSDK; tools: ToolInterface[]; constructor({ apiKey, apiUrl, privateKeyOrAccount, options, }: BrianToolkitOptions); } type BrianCDPToolkitOptions = { apiKey: string; apiUrl?: string; wallet?: Wallet; walletData?: WalletData; coinbaseApiKeyName?: string; coinbaseApiKeySecret?: string; coinbaseFilePath?: string; coinbaseOptions?: { useServerSigner?: boolean; debugging?: boolean; basePath?: string; }; }; declare class BrianCDPToolkit extends BaseToolkit { brianSDK: BrianSDK; tools: ToolInterface[]; wallet?: Wallet; walletData?: WalletData; constructor({ apiKey, apiUrl, coinbaseApiKeyName, coinbaseApiKeySecret, coinbaseFilePath, coinbaseOptions, }: BrianCDPToolkitOptions); setup({ wallet, walletData, }: { wallet?: Wallet; walletData?: WalletData; }): Promise<ToolInterface<_langchain_core_dist_types_zod.ZodObjectAny>[]>; } type FarcasterToolkitOptions = { neynarApiKey: string; signerUUID: string; }; declare class FarcasterToolkit extends BaseToolkit { neynar: NeynarAPIClient; signerUUID: string; tools: ToolInterface[]; constructor({ neynarApiKey, signerUUID }: FarcasterToolkitOptions); } type BrianStarknetToolkitOptions = { apiKey: string; account: Account$1; apiUrl?: string; }; declare class BrianStarknetToolkit extends BaseToolkit { account: Account$1; brianSDK: BrianSDK; tools: ToolInterface[]; constructor({ apiKey, apiUrl, account }: BrianStarknetToolkitOptions); } type TwitterToolkitOptions = { twitterUsername: string; twitterPassword: string; twitterEmail?: string; }; declare class TwitterToolkit extends BaseToolkit { scraper: Scraper; cookies: any[]; tools: ToolInterface[]; constructor(); setup({ twitterUsername, twitterPassword, twitterEmail, }: TwitterToolkitOptions): Promise<void>; } type BrianAgentOptions = BrianToolkitOptions & { llm: LanguageModelLike; instructions?: string; xmtpHandler?: HandlerContext; xmtpHandlerOptions?: XMTPCallbackHandlerOptions; tools?: ToolInterface[]; }; /** * @dev creates a new "default" Brian agent. * @param {BrianAgentOptions} options - the options for initializing the agent. * @returns {Promise<AgentExecutor>} - the agent executor. */ declare const createBrianAgent: ({ instructions, apiKey, apiUrl, privateKeyOrAccount, llm, xmtpHandler, xmtpHandlerOptions, options, tools: customTools, }: BrianAgentOptions) => Promise<AgentExecutor>; type BrianAgentCDPOptions = BrianCDPToolkitOptions & { llm: LanguageModelLike; instructions?: string; xmtpHandler?: HandlerContext; xmtpHandlerOptions?: XMTPCallbackHandlerOptions; tools?: ToolInterface[]; }; /** * @dev creates a new "default" Brian CDP agent. * @param {BrianAgentCDPOptions} options - the options for initializing the agent. * @returns {Promise<AgentExecutor>} - the agent executor. */ declare const createBrianCDPAgent: ({ instructions, apiKey, apiUrl, wallet, walletData, coinbaseApiKeyName, coinbaseApiKeySecret, coinbaseFilePath, coinbaseOptions, llm, xmtpHandler, xmtpHandlerOptions, tools: customTools, }: BrianAgentCDPOptions) => Promise<AgentExecutor>; type BrianStarknetAgentOptions = BrianStarknetToolkitOptions & { llm: LanguageModelLike; instructions?: string; xmtpHandler?: HandlerContext; xmtpHandlerOptions?: XMTPCallbackHandlerOptions; tools?: ToolInterface[]; }; /** * @dev creates a new "default" Brian Starknet agent. * @param {BrianStarknetAgentOptions} options - the options for initializing the agent. * @returns {Promise<AgentExecutor>} - the agent executor. */ declare const createBrianStarknetAgent: ({ instructions, apiKey, apiUrl, account, llm, xmtpHandler, xmtpHandlerOptions, tools: customTools, }: BrianStarknetAgentOptions) => Promise<AgentExecutor>; type FarcasterMemoryStoreOptions = { neynarApiKey: string; fid: number; }; declare const createFarcasterMemoryVectorStore: ({ neynarApiKey, fid, }: FarcasterMemoryStoreOptions) => Promise<MemoryVectorStore>; type FarcasterSupabaseStore = { neynarApiKey: string; fid: number; supabaseApiKey: string; supabaseUrl: string; }; declare const createFarcasterSupabaseVectorStore: ({ neynarApiKey, fid, supabaseApiKey, supabaseUrl, }: FarcasterSupabaseStore) => Promise<SupabaseVectorStore>; export { type BrianAgentCDPOptions, type BrianAgentOptions, BrianCDPToolkit, type BrianCDPToolkitOptions, type BrianStarknetAgentOptions, BrianStarknetToolkit, type BrianStarknetToolkitOptions, BrianToolkit, type BrianToolkitOptions, FarcasterToolkit, type FarcasterToolkitOptions, TwitterToolkit, type TwitterToolkitOptions, XMTPCallbackHandler, type XMTPCallbackHandlerOptions, createBrianAgent, createBrianCDPAgent, createBrianStarknetAgent, createFarcasterMemoryVectorStore, createFarcasterSupabaseVectorStore };