setumodi/devops-logs-analysis
0
1"""Shared state object that flows through the LangGraph workflow.2 3Each agent reads from and writes to this typed dictionary. Using a single4state object keeps the orchestration declarative and makes every step's5contribution traceable in the UI.6"""7 8from __future__ import annotations9 10from typing import Any, Dict, List, Optional, TypedDict11 12 13class IncidentState(TypedDict, total=False):14 # --- Raw input ---15 raw_log: str16 17 # --- Run configuration ---18 llm_model: Optional[str] # user-selected model for this analysis19 20 # --- Agent 1: Log Reader ---21 parsed: Dict[str, Any] # structured fields extracted via regex22 23 # --- Agent 2: Classifier ---24 classification: Dict[str, Any] # severity, root_cause, confidence, summary25 26 # --- Agent 3: Remediation (RAG) ---27 runbook_matches: List[Dict[str, Any]] # top-k retrieved runbook chunks28 remediation: Dict[str, Any] # synthesized fix + rationale29 30 # --- Agent 4: Cookbook ---31 cookbook: str # markdown recovery checklist32 33 # --- Agent 5: Jira ---34 jira: Dict[str, Any] # {created, key, url, dry_run, message}35 36 # --- Agent 6: Slack ---37 slack: Dict[str, Any] # {sent, channel, dry_run, message}38 39 # --- Routing / bookkeeping ---40 is_critical: bool41 trace: List[str] # human-readable step log for the UI42 errors: List[str]43 44 45def new_state(raw_log: str, llm_model: Optional[str] = None) -> IncidentState:46 return IncidentState(47 raw_log=raw_log,48 llm_model=llm_model,49 parsed={},50 classification={},51 runbook_matches=[],52 remediation={},53 cookbook="",54 jira={},55 slack={},56 is_critical=False,57 trace=[],58 errors=[],59 )60 