Files changed (1) hide show
  1. app.py +16 -1
app.py CHANGED
@@ -33,6 +33,21 @@ def get_current_time_in_timezone(timezone: str) -> str:
33
  except Exception as e:
34
  return f"Error fetching time for timezone '{timezone}': {str(e)}"
35
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
36
 
37
  final_answer = FinalAnswerTool()
38
 
@@ -55,7 +70,7 @@ with open("prompts.yaml", 'r') as stream:
55
 
56
  agent = CodeAgent(
57
  model=model,
58
- tools=[final_answer], ## add your tools here (don't remove final answer)
59
  max_steps=6,
60
  verbosity_level=1,
61
  grammar=None,
 
33
  except Exception as e:
34
  return f"Error fetching time for timezone '{timezone}': {str(e)}"
35
 
36
+ # this is my first Agent!
37
+ @tool
38
+ def calculator(expression: str) -> str:
39
+ """A tool that evaluates mathematical expressions.
40
+ Args:
41
+ expression: A string containing a mathematical expression (e.g., '2 + 2', '5 * 10', 'sqrt(16)').
42
+ """
43
+ try:
44
+ # Use Python's built-in eval function for simple calculations
45
+ # This is safe as long as the agent is using it internally
46
+ result = eval(expression, {"__builtins__": {}}, {"sqrt": lambda x: x**0.5})
47
+ return f"Result of {expression} = {result}"
48
+ except Exception as e:
49
+ return f"Error calculating '{expression}': {str(e)}"
50
+
51
 
52
  final_answer = FinalAnswerTool()
53
 
 
70
 
71
  agent = CodeAgent(
72
  model=model,
73
+ tools=[final_answer, calculator], ## add your tools here (don't remove final answer)
74
  max_steps=6,
75
  verbosity_level=1,
76
  grammar=None,