Use this to execute python code. If you want to see the output of a value, you should print it out with `print(...)`. This is visible to the user.
(code: Annotated[str, "The python code to execute to generate your chart."])
| 51 | |
| 52 | @tool |
| 53 | def python_repl(code: Annotated[str, "The python code to execute to generate your chart."]): |
| 54 | """Use this to execute python code. If you want to see the output of a value, |
| 55 | you should print it out with `print(...)`. This is visible to the user.""" |
| 56 | try: |
| 57 | # Warning: This executes code locally, which can be unsafe when not sandboxed |
| 58 | result = repl.run(code) |
| 59 | except BaseException as e: |
| 60 | return f"Failed to execute. Error: {repr(e)}" |
| 61 | return f"Succesfully executed:\n```python\n{code}\n```\nStdout: {result}" |
| 62 | |
| 63 | |
| 64 | tools = [tavily_tool, python_repl] |