/ pyod / utils / investigation.py
investigation.py
 1  # pyod/utils/investigation.py
 2  # -*- coding: utf-8 -*-
 3  """Investigation state for ADEngine session workflow."""
 4  
 5  import time
 6  from dataclasses import dataclass, field
 7  
 8  PHASES = ('profiled', 'planned', 'detected', 'analyzed')
 9  
10  ACTION_TYPES = (
11      'plan',
12      'run',
13      'analyze',
14      'report_to_user',
15      'confirm_with_user',
16      'iterate',
17      'done',
18  )
19  
20  
21  @dataclass
22  class InvestigationState:
23      """Typed state object for an ADEngine investigation session.
24  
25      Tracks the full workflow: profiling, planning, detection,
26      analysis, and iteration. Each session method updates the state
27      and sets ``next_action`` to guide the agent.
28  
29      Attributes
30      ----------
31      phase : str
32          One of ``PHASES``: 'profiled', 'planned', 'detected', 'analyzed'.
33      iteration : int
34          Current iteration (0 = first run).
35      history : list
36          List of HistoryEntry dicts.
37      data : object
38          Reference to input data (not copied).
39      profile : dict
40          Output of ``profile_data()``.
41      plans : list
42          List of DetectionPlan dicts (top-N).
43      results : list
44          List of DetectorResult dicts.
45      consensus : dict or None
46          ConsensusResult dict.
47      analysis : dict or None
48          InvestigationAnalysis dict.
49      quality : dict or None
50          QualityAssessment dict.
51      next_action : dict
52          NextAction dict guiding the agent.
53      """
54      phase: str
55      iteration: int = 0
56      history: list = field(default_factory=list)
57      data: object = None
58      profile: dict = field(default_factory=dict)
59      plans: list = field(default_factory=list)
60      results: list = field(default_factory=list)
61      consensus: dict = None
62      analysis: dict = None
63      quality: dict = None
64      next_action: dict = field(default_factory=dict)
65  
66  
67  def _make_history_entry(phase, action, iteration, detail=''):
68      """Create a HistoryEntry dict."""
69      return {
70          'phase': phase,
71          'action': action,
72          'iteration': iteration,
73          'timestamp': time.time(),
74          'detail': detail,
75      }