File size: 1,054 Bytes
102e47e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
from transformers import Tool
from sympy import symbols, Eq, solve, simplify, diff, integrate, sympify

class SolveEquationTool(Tool):
    name = "solve_equation"
    description = "Solves a basic equation for x. Format: '2*x + 3 = 7'"

    def __call__(self, equation: str) -> str:
        x = symbols('x')
        try:
            lhs, rhs = equation.split("=")
            eq = Eq(sympify(lhs), sympify(rhs))
            sol = solve(eq, x)
            return f"x = {sol}"
        except Exception as e:
            return f"Error solving equation: {str(e)}"

class ExplainSolutionTool(Tool):
    name = "explain_solution"
    description = "Explains the steps to solve a math problem."

    def __call__(self, problem: str) -> str:
        # Minimalist inline explanation; in a real agent, call an LLM
        if "2*x + 3 = 7" in problem:
            return "Step 1: Subtract 3 from both sides β†’ 2x = 4\nStep 2: Divide both sides by 2 β†’ x = 2"
        return "This agent only explains '2*x + 3 = 7' as a hardcoded example. Extend me with an LLM!"