implement 2 strategies
This commit is contained in:
33
multi-agent-supervisor/agents/__init__.py
Normal file
33
multi-agent-supervisor/agents/__init__.py
Normal file
@@ -0,0 +1,33 @@
|
||||
"""Agent definitions for the multi-agent sysadmin system."""
|
||||
|
||||
from .system_agents import (
|
||||
create_system_info_worker,
|
||||
create_service_inventory_worker,
|
||||
)
|
||||
from .service_agents import (
|
||||
create_mariadb_worker,
|
||||
create_nginx_worker,
|
||||
create_phpfpm_worker,
|
||||
)
|
||||
from .network_agents import (
|
||||
create_network_worker,
|
||||
create_cert_worker,
|
||||
)
|
||||
from .analysis_agents import (
|
||||
create_risk_worker,
|
||||
create_remediation_worker,
|
||||
create_harmonizer_worker,
|
||||
)
|
||||
|
||||
__all__ = [
|
||||
"create_system_info_worker",
|
||||
"create_service_inventory_worker",
|
||||
"create_mariadb_worker",
|
||||
"create_nginx_worker",
|
||||
"create_phpfpm_worker",
|
||||
"create_network_worker",
|
||||
"create_cert_worker",
|
||||
"create_risk_worker",
|
||||
"create_remediation_worker",
|
||||
"create_harmonizer_worker",
|
||||
]
|
42
multi-agent-supervisor/agents/analysis_agents.py
Normal file
42
multi-agent-supervisor/agents/analysis_agents.py
Normal file
@@ -0,0 +1,42 @@
|
||||
"""Analysis and remediation agents."""
|
||||
|
||||
from langgraph.prebuilt import create_react_agent
|
||||
from custom_tools import get_shell_tool
|
||||
|
||||
|
||||
def create_risk_worker():
|
||||
"""Create risk assessment agent."""
|
||||
return create_react_agent(
|
||||
model="openai:gpt-4o-mini",
|
||||
tools=[], # pure‑LLM reasoning
|
||||
prompt="""
|
||||
Aggregate the findings from other agents and assign a severity: Critical, High, Medium, or Low.
|
||||
Output a short report.
|
||||
""",
|
||||
name="risk_scorer"
|
||||
)
|
||||
|
||||
|
||||
def create_remediation_worker():
|
||||
"""Create remediation agent."""
|
||||
return create_react_agent(
|
||||
model="openai:gpt-4o-mini",
|
||||
tools=[get_shell_tool()],
|
||||
prompt="""
|
||||
Propose safe bash commands or configuration edits to fix detected issues.
|
||||
NEVER run destructive commands automatically; always request confirmation.
|
||||
""",
|
||||
name="remediation_worker"
|
||||
)
|
||||
|
||||
|
||||
def create_harmonizer_worker():
|
||||
"""Create system hardening agent."""
|
||||
return create_react_agent(
|
||||
model="openai:gpt-4o-mini",
|
||||
tools=[get_shell_tool()],
|
||||
prompt="""
|
||||
Apply best‑practice hardening (`ulimit`, `sysctl`, journald rotation) in dry‑run mode unless severity is High.
|
||||
""",
|
||||
name="harmonizer_worker"
|
||||
)
|
29
multi-agent-supervisor/agents/network_agents.py
Normal file
29
multi-agent-supervisor/agents/network_agents.py
Normal file
@@ -0,0 +1,29 @@
|
||||
"""Network and security monitoring agents."""
|
||||
|
||||
from langgraph.prebuilt import create_react_agent
|
||||
from custom_tools import get_shell_tool
|
||||
|
||||
|
||||
def create_network_worker():
|
||||
"""Create network diagnostics agent."""
|
||||
return create_react_agent(
|
||||
model="openai:gpt-4o-mini",
|
||||
tools=[get_shell_tool()],
|
||||
prompt="""
|
||||
Diagnose network issues using `ping`, `traceroute`, and `dig`.
|
||||
""",
|
||||
name="network_diag"
|
||||
)
|
||||
|
||||
|
||||
def create_cert_worker():
|
||||
"""Create certificate checking agent."""
|
||||
return create_react_agent(
|
||||
model="openai:gpt-4o-mini",
|
||||
tools=[get_shell_tool()],
|
||||
prompt="""
|
||||
Check TLS certificates on disk with `openssl x509 -noout -enddate -in <cert>`.
|
||||
Raise an alert when a certificate expires in fewer than 30 days.
|
||||
""",
|
||||
name="cert_checker"
|
||||
)
|
42
multi-agent-supervisor/agents/service_agents.py
Normal file
42
multi-agent-supervisor/agents/service_agents.py
Normal file
@@ -0,0 +1,42 @@
|
||||
"""Service-specific monitoring agents."""
|
||||
|
||||
from langgraph.prebuilt import create_react_agent
|
||||
from custom_tools import get_shell_tool, LogTailTool
|
||||
|
||||
|
||||
def create_mariadb_worker():
|
||||
"""Create MariaDB analysis agent."""
|
||||
return create_react_agent(
|
||||
model="openai:gpt-4o-mini",
|
||||
tools=[get_shell_tool(), LogTailTool()],
|
||||
prompt="""
|
||||
You are a MariaDB expert. Check config files in /etc/mysql and inspect `/var/log/mysql/*.log` for errors.
|
||||
Use `mysqladmin status` and other read‑only commands. Use the `tail_log` tool for logs.
|
||||
""",
|
||||
name="mariadb_analyzer"
|
||||
)
|
||||
|
||||
|
||||
def create_nginx_worker():
|
||||
"""Create Nginx analysis agent."""
|
||||
return create_react_agent(
|
||||
model="openai:gpt-4o-mini",
|
||||
tools=[get_shell_tool(), LogTailTool()],
|
||||
prompt="""
|
||||
You are an Nginx expert. Validate configuration with `nginx -t` and inspect access/error logs.
|
||||
Use the `tail_log` tool for `/var/log/nginx/error.log`.
|
||||
""",
|
||||
name="nginx_analyzer"
|
||||
)
|
||||
|
||||
|
||||
def create_phpfpm_worker():
|
||||
"""Create PHP-FPM analysis agent."""
|
||||
return create_react_agent(
|
||||
model="openai:gpt-4o-mini",
|
||||
tools=[get_shell_tool(), LogTailTool()],
|
||||
prompt="""
|
||||
You are a PHP‑FPM expert. Check `systemctl status php*-fpm` and look for memory leaks or timeouts in the logs.
|
||||
""",
|
||||
name="phpfpm_analyzer"
|
||||
)
|
30
multi-agent-supervisor/agents/system_agents.py
Normal file
30
multi-agent-supervisor/agents/system_agents.py
Normal file
@@ -0,0 +1,30 @@
|
||||
"""System monitoring agents."""
|
||||
|
||||
from langgraph.prebuilt import create_react_agent
|
||||
from custom_tools import get_shell_tool
|
||||
|
||||
|
||||
def create_system_info_worker():
|
||||
"""Create system information gathering agent."""
|
||||
return create_react_agent(
|
||||
model="openai:gpt-4o-mini",
|
||||
tools=[get_shell_tool()],
|
||||
prompt="""
|
||||
You are a Linux sysadmin. Use shell commands like `lscpu`, `free -h`, and `df -h` to gather CPU, RAM, and disk usage.
|
||||
Return a concise plain‑text summary. Only run safe, read‑only commands.
|
||||
""",
|
||||
name="system_info_worker"
|
||||
)
|
||||
|
||||
|
||||
def create_service_inventory_worker():
|
||||
"""Create service inventory agent."""
|
||||
return create_react_agent(
|
||||
model="openai:gpt-4o-mini",
|
||||
tools=[get_shell_tool()],
|
||||
prompt="""
|
||||
List all running services using `systemctl list-units --type=service --state=running`.
|
||||
Return a JSON array of service names.
|
||||
""",
|
||||
name="service_inventory_worker"
|
||||
)
|
Reference in New Issue
Block a user