-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Expand file tree
/
Copy pathapp.py
More file actions
67 lines (58 loc) · 2.49 KB
/
app.py
File metadata and controls
67 lines (58 loc) · 2.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
from praisonaiagents import Agent, Task, PraisonAIAgents
import subprocess
import os
def run_terminal_command(command: str):
"""
Run a terminal command and return its output.
"""
try:
result = subprocess.run(command, shell=True, check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
print(f"Command output: {result}")
return {"stdout": result.stdout, "stderr": result.stderr}
except subprocess.CalledProcessError as e:
return {"error": str(e), "stdout": e.stdout, "stderr": e.stderr}
def save_to_file(file_path: str, content: str):
"""
Save the given content to the specified file path. Create the folder/file if it doesn't exist.
"""
# Ensure the directory exists
os.makedirs(os.path.dirname(file_path), exist_ok=True)
# Write the content to the file
with open(file_path, 'w') as file:
file.write(content)
return file_path
# Create System Operations Agent
system_ops_agent = Agent(
name="SystemOps",
role="System Operations Specialist",
goal="Execute and manage complex system operations and commands",
backstory="""You are an expert system administrator with deep knowledge of Unix/Linux systems.
You excel at running complex system commands, managing processes, and handling system operations.
You always validate commands before execution and ensure they are safe to run.""",
min_reflect=6,
max_reflect=10,
tools=[run_terminal_command, save_to_file],
llm="gpt-4o-mini"
)
# Create a complex task that tests various system operations
task = Task(
name="system_analysis_task",
description="""Perform a comprehensive system analysis by executing the following operations in sequence:
1. Get system information (OS, kernel version)
2. List 5 running processes and sort them by CPU usage
3. Check disk space usage and list directories over 1GB
4. Display current system load and memory usage
5. List 5 network connections
6. Create a summary report with all findings in a text file called system_report.txt
Do it step by step. One task at a time.
Save only the Summary report in the file.
Use appropriate commands for each step and ensure proper error handling.""",
expected_output="A comprehensive system report containing all requested information saved in system_report.txt",
agent=system_ops_agent,
)
agents = PraisonAIAgents(
agents=[system_ops_agent],
tasks=[task],
process="sequential"
)
result = agents.start()