MCPcopy Create free account
hub / github.com/Darwin-lfl/langmanus / python_repl_tool

Function python_repl_tool

src/tools/python_repl.py:14–30  ·  view source on GitHub ↗

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."
    ],
)

Source from the content-addressed store, hash-verified

12@tool
13@log_io
14def 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

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected