Anshini commited on
Commit
122377f
·
verified ·
1 Parent(s): 30a9380

Update tools.py

Browse files
Files changed (1) hide show
  1. tools.py +11 -0
tools.py CHANGED
@@ -152,3 +152,14 @@ def web_search(query: str) -> str:
152
  return tavily.search(query=query)['results'][0]['content']
153
  except Exception as e:
154
  return f"Error from Tavily: {e}"
 
 
 
 
 
 
 
 
 
 
 
 
152
  return tavily.search(query=query)['results'][0]['content']
153
  except Exception as e:
154
  return f"Error from Tavily: {e}"
155
+
156
+ # --- Execute Code ---
157
+ @tool
158
+ def execute_code(code: str) -> str:
159
+ """ Execute a code snippet and return the resulting local variable or ant error."""
160
+ exec_locals = {}
161
+ try:
162
+ exec(code, {}, exec_locals)
163
+ return str(exec_locals)
164
+ except Exception as e:
165
+ return str(e)