| import gradio as gr |
| import os |
| from dotenv import load_dotenv |
| from agents import IncidentAgents |
|
|
| |
| load_dotenv() |
|
|
| |
| DEFAULT_LOGS = "" |
|
|
| DEFAULT_TICKET = "" |
|
|
| DEFAULT_RUNBOOK = "" |
|
|
| |
| def run_incident_response(logs_input, ticket_input, runbook_input): |
| """ |
| This function connects the UI inputs to the Agent Logic. |
| """ |
| try: |
| |
| agents = IncidentAgents() |
|
|
| |
| log_analysis = agents.log_analysis_agent(logs_input) |
| yield log_analysis, "...", "...", "...", "..." |
|
|
| |
| correlation = agents.incident_correlator_agent(ticket_input, log_analysis) |
| yield log_analysis, correlation, "...", "...", "..." |
|
|
| |
| rca = agents.root_cause_agent(correlation, runbook_input) |
| yield log_analysis, correlation, rca, "...", "..." |
|
|
| |
| resolution = agents.resolution_agent(rca, runbook_input) |
| yield log_analysis, correlation, rca, resolution, "..." |
|
|
| |
| final_report = agents.report_agent(ticket_input, rca, resolution) |
| yield log_analysis, correlation, rca, resolution, final_report |
|
|
| except Exception as e: |
| error_msg = f"Error: {str(e)}" |
| yield error_msg, error_msg, error_msg, error_msg, error_msg |
|
|
| |
| with gr.Blocks(title="Agentic Incident Response") as demo: |
|
|
| |
| gr.Markdown("# AI Agent Incident Response System") |
| gr.Markdown("Enter system logs, an incident ticket, and a runbook. The Multi-Agent System will analyze, correlate, and fix the issue.") |
|
|
| |
| with gr.Row(): |
| with gr.Column(): |
| logs_box = gr.Textbox(label="1. System Logs", value=DEFAULT_LOGS, lines=8, placeholder="Paste logs here...") |
| with gr.Column(): |
| ticket_box = gr.Textbox(label="2. Incident Ticket (JSON)", value=DEFAULT_TICKET, lines=8, placeholder="Paste ticket JSON here...") |
| with gr.Column(): |
| runbook_box = gr.Textbox(label="3. Runbook (Markdown)", value=DEFAULT_RUNBOOK, lines=8, placeholder="Paste runbook here...") |
|
|
| |
| run_btn = gr.Button("Run Automated Response Workflow", variant="primary") |
|
|
| |
| gr.Markdown("### Agent Reasoning Chain") |
|
|
| with gr.Accordion("Step 1: Log Analysis Agent", open=False): |
| out_logs = gr.Markdown() |
|
|
| with gr.Accordion("Step 2: Incident Correlator Agent", open=False): |
| out_correlation = gr.Markdown() |
|
|
| with gr.Accordion("Step 3: Root Cause Analysis (RCA) Agent", open=False): |
| out_rca = gr.Markdown() |
|
|
| with gr.Accordion("Step 4: Resolution Agent", open=True): |
| out_resolution = gr.Markdown() |
|
|
| |
| gr.Markdown("### Final Post-Incident Report") |
| out_final_report = gr.Markdown() |
|
|
| |
| run_btn.click( |
| fn=run_incident_response, |
| inputs=[logs_box, ticket_box, runbook_box], |
| outputs=[out_logs, out_correlation, out_rca, out_resolution, out_final_report] |
| ) |
|
|
| |
| if __name__ == "__main__": |
| demo.launch(theme=gr.themes.Soft()) |
|
|