Skip to content

Brian Toolkit

The BrianToolkit is a langchain toolkit that can be imported in your agent to interact with the Brian APIs and execute operations with a wallet.

Usage

You can import directly the BrianToolkit in your agent without the need of using the createBrianAgent function:

import { BrianToolkit } from "@brian-ai/langchain";
 
const { tools } = new BrianToolkit({
  apiKey: "your-brian-api-key",
  privateKeyOrAccount: "your-private-key-or-account",
  options: { ...brianToolkitOptions },
});
 
// import the tools in your langchain agent

The brianToolkitOption object is an object that can contain the following properties:

type BrianToolkitOptions = {
  gelatoApiKey?: string;
};

Check the Gelato Integration page for more information on how the gelatoApiKey option is used.

Tools

Every tool inside the BrianToolkit is an object of the following class that extends the DynamicStructuredTool class from langchain:

type BrianToolOptions = {
  gelatoApiKey?: string;
};
 
class BrianTool extends DynamicStructuredTool {
  brianSDK: BrianSDK;
  account: Account;
  options?: BrianToolOptions;
 
  constructor(
    fields: DynamicStructuredToolInput & {
      brianSDK: BrianSDK;
      account: Account;
      options?: BrianToolOptions;
    }
  ) {
    super(fields);
    this.brianSDK = fields.brianSDK;
    this.account = fields.account;
  }
}

Every tool this way has access to the BrianSDK instance and to the Account instance that are used to interact with the Brian APIs and the wallet respectively.

These are all the tools currently supported by the toolkit.

Balance tool

The balance tool is a tool that allows the agent to retrieve the balance of a native/ERC-20 token of a given wallet.

await balanceTool.invoke({
  token: "USDC",
  chain: "Base",
  address: "orbulo.eth",
});

Borrow tool

The borrow tool is a tool that allows the agent to borrow a given amount of a token from AAVE.

await borrowTool.invoke({
  token: "USDC",
  chain: "Ethereum",
  amount: 100,
});

Bridge tool

The bridge tool is a tool that allows the agent to bridge tokens from one chain to another.

await bridgeTool.invoke({
  tokenIn: "USDC",
  inputChain: "Base",
  outputChain: "zkSync",
  amount: 100,
});

Create pool tool

The create pool tool is a tool that allows the agent to create a new pool on Uniswap on Ethereum, Base, Polygon, Arbitrum or Optimism.

This tool is really powerful in combination with the deployToken tool.

Deploy NFT tool

The deploy NFT tool is a tool that allows the agent to deploy a new NFT Smart Contract on a given chain (via chainId).

await deployNFTTool.invoke({
  chainId: 1,
  name: "BrianNFT",
  symbol: "BNFT",
  baseURI: "https://brianknows.org",
});

Deploy Token tool

The deploy token token is a tool that allows the agent to deploy a new ERC-20 token on a given chain (via chainId).

await deployTokenTool.invoke({
  chainId: 1,
  name: "BrianToken",
  symbol: "BRT",
  totalSupply: 10000000,
});

Deposit tool

The deposit tool is a tool that allows the agent to deposit a given amount of a token inside a protocol.

await depositTool.invoke({
  tokenIn: "USDC",
  chain: "Ethereum",
  amount: 100,
  protocol: "AAVE",
});

Networks tool

The networks tool is a utility tool that allows the agent to retrieve all the networks supported by Brian, alongside with their chain ID.

await networksTool.invoke();

Repay tool

The repay tool is a tool that allows the agent to repay a given amount of borrowed tokens to AAVE.

await repayTool.invoke({
  token: "USDC",
  chain: "Ethereum",
  amount: 100,
});

Swap tool

The swap tool is a tool that allows the agent to swap two tokens (native -> native, native -> erc20, erc20 -> native).

It also supports cross-chain swaps and swaps that specifiy an address receiver.

await swapTool.invoke({
  tokenIn: "USDC",
  tokenOut: "ETH",
  amount: 100,
  chain: "Base",
});

Transfer tool

The transfer tool is a tool that allows the agent to transfer a given amount of a token to a given address.

await transferTool.invoke({
  token: "USDC",
  amount: 100,
  receiver: "orbulo.eth",
});

Withdraw tool

The withdraw tool is a tool that allows the agent to withdraw a given amount of previously deposited tokens inside a protocol.

await withdrawTool.invoke({
  tokenIn: "USDC",
  chain: "Ethereum",
  amount: 100,
  protocol: "AAVE",
});