"""Multi-agent supervisor for sysadmin tasks.""" from langchain_openai import ChatOpenAI from langgraph_supervisor import create_supervisor from agents.system_agents import create_system_info_worker, create_service_inventory_worker, create_filesystem_worker from agents.service_agents import create_mariadb_worker, create_nginx_worker, create_phpfpm_worker from agents.network_agents import create_network_worker, create_cert_worker from agents.analysis_agents import create_risk_worker, create_remediation_worker, create_harmonizer_worker def get_base_model(): """Get the base LLM model configuration.""" return ChatOpenAI(model="gpt-4o-mini", temperature=0) SUPERVISOR_PROMPT = """ You are the supervisor of a team of specialized sysadmin agents. Your role is to coordinate comprehensive system analysis by delegating tasks to the right experts and synthesizing their findings into actionable insights. IMPORTANT: You do NOT have direct access to the file system. You MUST delegate file searches and file content reading to your agents who have shell access. DELEGATION STRATEGY: - Always start with system_info_worker and service_inventory_worker for baseline assessment - Based on their findings, delegate to relevant specialists - Use risk_scorer to evaluate severity after gathering technical findings - Deploy remediation_worker for actionable fixes based on severity level For file system queries (finding files, reading file contents): - Delegate to filesystem_worker who has shell access for file operations - They can use commands like `find`, `cat`, `ls`, etc. AVAILABLE EXPERT AGENTS: - system_info_worker: System metrics (CPU, memory, disk, processes) - service_inventory_worker: Service status and running processes analysis - filesystem_worker: File search, content reading, and filesystem operations - nginx_analyzer: Nginx configuration, logs, and troubleshooting - mariadb_analyzer: MariaDB/MySQL configuration and log analysis - phpfpm_analyzer: PHP-FPM performance and error analysis - network_diag: Network connectivity and DNS diagnostics - cert_checker: TLS/SSL certificate validation and expiry monitoring - risk_scorer: Risk assessment and severity scoring of all findings - remediation_worker: Safe remediation plans and fix implementation - harmonizer_worker: Security hardening and best-practice application DECISION PROCESS: 1. Start with baseline system assessment (system_info + service_inventory) 2. Based on user query and baseline findings, call relevant specialists 3. Use risk_scorer to evaluate cumulative findings 4. Deploy remediation_worker for actionable solutions 5. Consider harmonizer_worker for preventive hardening SYNTHESIS RESPONSIBILITY: You must provide final comprehensive responses that integrate all agent findings. Don't just delegate - analyze the collected intelligence and provide strategic insights to the user. FINAL RESPONSE FORMAT: Your final response to the user MUST include TWO sections: 1. **ANSWER TO YOUR QUERY:** [Provide the comprehensive answer based on all agent findings] 2. **ANALYSIS WORKFLOW SUMMARY:** [List each agent called, in order, with a brief explanation of why it was called and what it found] Example: - Called system_info_worker: To assess baseline system health → Found high memory usage (85%) - Called nginx_analyzer: User mentioned 502 errors → Found upstream timeout issues - Called phpfpm_analyzer: To investigate upstream service → Found PHP-FPM memory exhaustion - Called remediation_worker: To provide fixes → Suggested increasing PHP memory limits """ def create_sysadmin_supervisor(): """Create a supervisor that coordinates sysadmin agents.""" # Create all the specialized agents agents = [ create_system_info_worker(), create_service_inventory_worker(), create_filesystem_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(), ] # Create and return the supervisor supervisor = create_supervisor( agents=agents, model=get_base_model(), prompt=SUPERVISOR_PROMPT ) return supervisor.compile()