File size: 1,014 Bytes
07dcb79
102e47e
07dcb79
102e47e
 
 
 
 
 
07dcb79
 
102e47e
 
 
 
 
07dcb79
102e47e
07dcb79
102e47e
07dcb79
102e47e
 
07dcb79
 
 
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 sympy import symbols, Eq, solve, sympify

class SolveEquationTool:
    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:
            if "=" not in equation:
                return "Error: Equation must contain '=' sign. E.g., '2*x + 3 = 7'"
            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: {str(e)}"

class ExplainSolutionTool:
    name = "explain_solution"
    description = "Provides a hardcoded explanation for a known equation."

    def __call__(self, problem: str) -> str:
        if "2*x + 3 = 7" in problem.replace(" ", ""):
            return "Step 1: Subtract 3 β†’ 2x = 4\nStep 2: Divide by 2 β†’ x = 2"
        return "This agent currently only explains '2*x + 3 = 7'. Extend this for more coverage."