Class: CircuitBreaker::Executors::LLM::CalculatorTool

Inherits:
Tool
  • Object
show all
Defined in:
lib/circuit_breaker/executors/llm/tools.rb

Instance Attribute Summary

Attributes inherited from Tool

#description, #name, #parameters

Instance Method Summary collapse

Methods inherited from Tool

#to_h

Constructor Details

#initializeCalculatorTool

Returns a new instance of CalculatorTool.



75
76
77
78
79
80
81
82
83
# File 'lib/circuit_breaker/executors/llm/tools.rb', line 75

def initialize
  super(
    name: 'calculator',
    description: 'Perform mathematical calculations',
    parameters: {
      expression: { type: 'string', description: 'The mathematical expression to evaluate' }
    }
  )
end

Instance Method Details

#execute(expression:) ⇒ Object



85
86
87
88
89
90
# File 'lib/circuit_breaker/executors/llm/tools.rb', line 85

def execute(expression:)
  # Implement safe evaluation logic here
  { result: eval(expression).to_s }
rescue => e
  { error: e.message }
end