| |
|
| | """Test the execute_code tool functionality."""
|
| |
|
| | import asyncio
|
| | import sys
|
| | from pathlib import Path
|
| |
|
| |
|
| | sys.path.insert(0, str(Path(__file__).parent))
|
| |
|
| | from agent.tools.execute_code_tool import execute_code_handler
|
| |
|
| |
|
| | async def test_execute_code():
|
| | """Test the execute_code tool."""
|
| | print("=" * 60)
|
| | print("Testing execute_code Tool")
|
| | print("=" * 60)
|
| |
|
| |
|
| | print("\nTest 1: Simple echo command")
|
| | result, success = await execute_code_handler({"command": "echo 'Hello from execute_code!'"})
|
| | print(f"Success: {success}")
|
| | print(f"Result: {result}")
|
| |
|
| |
|
| | print("\nTest 2: Write and read a file")
|
| | result, success = await execute_code_handler({
|
| | "command": "cat > /tmp/test_file.txt << 'EOF'\nThis is a test file\nCreated by execute_code\nEOF"
|
| | })
|
| | print(f"Write success: {success}")
|
| |
|
| | result, success = await execute_code_handler({
|
| | "command": "cat /tmp/test_file.txt"
|
| | })
|
| | print(f"Read success: {success}")
|
| | print(f"Content: {result}")
|
| |
|
| |
|
| | print("\nTest 3: Run Python code")
|
| | result, success = await execute_code_handler({
|
| | "command": "python3 -c \"print(2+2); print('Python works!')\""
|
| | })
|
| | print(f"Success: {success}")
|
| | print(f"Result: {result}")
|
| |
|
| |
|
| | print("\nTest 4: Install package and use it")
|
| | result, success = await execute_code_handler({
|
| | "command": "pip install --quiet sympy && python3 -c \"from sympy import symbols, diff; x=symbols('x'); print(diff(x**2, x))\""
|
| | })
|
| | print(f"Success: {success}")
|
| | print(f"Result: {result}")
|
| |
|
| | print("\n" + "=" * 60)
|
| | print("execute_code tool test complete!")
|
| | print("=" * 60)
|
| |
|
| |
|
| | if __name__ == "__main__":
|
| | asyncio.run(test_execute_code())
|
| |
|