math

package
v0.1.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 10, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package math provides mathematical tools (a unified arithmetic tool and a calculator/expression evaluator) that can be registered with the tool registry. These tools allow agents to perform precise arithmetic instead of relying on the LLM's inherent (and sometimes inaccurate) numeric reasoning.

Problem: LLMs hallucinate numeric results — even simple division can produce wrong answers. This package gives agents a deterministic math engine that always returns correct results.

Safety guards:

  • Expression length limit (1000 chars) prevents computational bombs
  • 5-second evaluation timeout prevents runaway expressions like pow(pow(2,1000),1000)
  • Division by zero returns a clear error
  • Domain errors (sqrt of negative, log of zero) return descriptive errors

Dependencies:

  • github.com/expr-lang/expr — safe, sandboxed expression evaluation (Go, 6.7k+ ⭐)
  • No external system dependencies

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ToolProvider

type ToolProvider struct{}

ToolProvider wraps the mathematical tools and satisfies the tools.ToolProviders interface so it can be passed directly to tools.NewRegistry. Without this, math tools would need to be constructed inline inside the registry.

func NewToolProvider

func NewToolProvider() *ToolProvider

NewToolProvider creates a ToolProvider for the mathematical tools.

func (*ToolProvider) GetTools

func (p *ToolProvider) GetTools() []tool.Tool

GetTools returns the mathematical tools: a unified arithmetic tool (math) and an expression evaluator (calculator).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL