Maths

Guide to use Maths tool on your AI agent using Vity Toolkit

Perform elementary math operations (add, subtract, multiply, divide, average, min, max) on arrays of numbers.

Quick Start

1

Install the package.

npm install vity-toolkit langchain @langchain/openai
2

Initialize Vity Toolkit and Langchain.

import { ChatOpenAI } from "@langchain/openai";
import { App, LangchainToolkit } from "vity-toolkit";
import { createOpenAIFunctionsAgent, AgentExecutor } from "langchain/agents";
import { ChatPromptTemplate } from "@langchain/core/prompts";

const model = new ChatOpenAI({ model: "gpt-4o" });
const toolKit = new LangchainToolkit();
3

Add the tool.

const tools = toolKit.getTools({ apps: [App.BASIC_MATH] });
4

Define the Agent.

const prompt = ChatPromptTemplate.fromMessages([
    ["system", "You are a precise calculator that can perform simple math using the Basic Math tool."],
    ["placeholder", "{chat_history}"],
    ["human", "{input}"],
    ["placeholder", "{agent_scratchpad}"],
]);

const agent = createToolCallingAgent({ llm: model, tools, prompt });

const agentExecutor = new AgentExecutor({
    agent,
    tools,
    verbose: false,
});
5

Execute the Agent.

const response = await agentExecutor.invoke({ input: "Multiply 4 and 8, then tell me the result." });
console.log(response);

Supported Actions

Action
Description
Action.BASIC_MATH_SOLVE

Perform simple math operations such as add, subtract, multiply, divide, average, min, and max on an array of numbers.

Last updated