Use this to execute python code and do data analysis or calculation. 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 do further analysis or calculation."
],
)
| 12 | @tool |
| 13 | @log_io |
| 14 | def python_repl_tool( |
| 15 | code: Annotated[ |
| 16 | str, "The python code to execute to do further analysis or calculation." |
| 17 | ], |
| 18 | ): |
| 19 | """Use this to execute python code and do data analysis or calculation. If you want to see the output of a value, |
| 20 | you should print it out with `print(...)`. This is visible to the user.""" |
| 21 | logger.info("Executing Python code") |
| 22 | try: |
| 23 | result = repl.run(code) |
| 24 | logger.info("Code execution successful") |
| 25 | except BaseException as e: |
| 26 | error_msg = f"Failed to execute. Error: {repr(e)}" |
| 27 | logger.error(error_msg) |
| 28 | return error_msg |
| 29 | result_str = f"Successfully executed:\n```python\n{code}\n```\nStdout: {result}" |
| 30 | return result_str |
nothing calls this directly
no outgoing calls
no test coverage detected