← All tools

Data & Analysis

Calculator

Deterministic math for financial analysis.

calculator

Overview

A reliable math evaluator. Language models are famously shaky at arithmetic, so this tool does the actual sums — ratios, growth rates, percentages — and returns the exact number.

How it works

Parses and evaluates arithmetic expressions (addition, subtraction, multiplication, division, powers, parentheses) and returns the exact numeric result. Intended for day-to-day financial math — ratios, growth rates, percentages. For calculus or symbolic algebra, use Wolfram Alpha instead.

Example

When a user asks:

What's the P/E ratio if price is 190 and EPS is 6.13?

the agent calls the tool:

calculator(expression="190 / 6.13")

and gets back: 30.9951…

Use it in a workflow

Wire this tool into a SwarmAI crew. Use the YAML DSL for declarative workflows, or the Java builder API when you want full programmatic control.

YAML DSL

# modeling.yaml
name: modeling-crew
process: SEQUENTIAL

agents:
  - id: modeler
    role: Financial Modeler
    goal: Do precise arithmetic without LLM drift
    tools:
      - calculator

tasks:
  - id: modeling-task
    agent: modeler
    description: Compute Apple's P/E ratio given price=190 and EPS=6.13.

Java

import ai.intelliswarm.swarmai.agent.Agent;
import ai.intelliswarm.swarmai.task.Task;
import ai.intelliswarm.swarmai.swarm.Swarm;
import ai.intelliswarm.swarmai.swarm.SwarmOutput;
import ai.intelliswarm.swarmai.process.ProcessType;
import ai.intelliswarm.swarmai.tool.common.CalculatorTool;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.beans.factory.annotation.Autowired;

@Autowired ChatClient chatClient;
@Autowired CalculatorTool calculatorTool;

Agent modeler = Agent.builder()
    .role("Financial Modeler")
    .goal("Do precise arithmetic without LLM drift")
    .chatClient(chatClient)
    .tool(calculatorTool)
    .build();

Task modelerTask = Task.builder()
    .description("Compute Apple's P/E ratio given price=190 and EPS=6.13.")
    .agent(modeler)
    .build();

SwarmOutput result = Swarm.builder()
    .agent(modeler)
    .task(modelerTask)
    .process(ProcessType.SEQUENTIAL)
    .build()
    .kickoff();

What it's good for

Real scenarios where agents put this tool to work.

P/E, P/B, ROE ratio math in finance crews
Growth-rate and CAGR computations
Safe arithmetic validation in analyst pipelines
Quick numeric expressions without invoking Wolfram

Source

Implementation lives at swarmai-tools/src/main/java/ai/intelliswarm/swarmai/tool/common/CalculatorTool.java in the swarm-ai repository.

Open calculator on GitHub →