Skip to main content

Overview

Python tool allows you to execute Python code from your AI agents.

Installation

pip install "praisonai[tools]"

Quick Start

from praisonai_tools import PythonTool

# Initialize
python = PythonTool()

# Execute code
result = python.execute("print(2 + 2)")
print(result)

Usage with Agent

from praisonaiagents import Agent
from praisonai_tools import PythonTool

agent = Agent(
    name="CodeRunner",
    instructions="You help execute Python code.",
    tools=[PythonTool()]
)

response = agent.chat("Calculate the factorial of 10")
print(response)

Available Methods

execute(code)

Execute Python code.
from praisonai_tools import PythonTool

python = PythonTool()
result = python.execute('''
import math
print(math.factorial(10))
''')

Security Warning

⚠️ Use with caution! Executing arbitrary code can be dangerous.