|
6 | 6 | """ |
7 | 7 |
|
8 | 8 | import logging |
9 | | -from typing import Any, Dict, List |
10 | | - |
11 | | -from ..common.config import configure_logging, get_environment_config |
| 9 | +from typing import Any, Dict |
12 | 10 |
|
13 | 11 | logger = logging.getLogger(__name__) |
14 | 12 |
|
15 | 13 |
|
16 | | -def get_error_analyzer_config(pattern_config: Dict[str, Any] = None) -> Dict[str, Any]: |
17 | | - """ |
18 | | - Builds complete error analyzer configuration from environment and patterns. |
19 | | - Get error analyzer configuration with defaults and overrides. |
20 | | -
|
21 | | - Returns: |
22 | | - Dict containing complete error analyzer configuration |
23 | | - """ |
24 | | - from ... import get_config |
25 | | - |
26 | | - # Start with base environment and context limits |
27 | | - config = get_environment_config(["CLOUDWATCH_LOG_GROUP_PREFIX", "AWS_STACK_NAME"]) |
28 | | - config.update(get_context_limits()) |
29 | | - |
30 | | - # Load and apply agent configuration |
31 | | - full_config = get_config() |
32 | | - agent_config = full_config.get("agents", {}).get("error_analyzer", {}) |
33 | | - |
34 | | - if not agent_config: |
35 | | - raise ValueError("error_analyzer configuration not found") |
36 | | - |
37 | | - # Apply agent settings with defaults |
38 | | - config.update( |
39 | | - { |
40 | | - "model_id": agent_config.get( |
41 | | - "model_id", "anthropic.claude-3-sonnet-20240229-v1:0" |
42 | | - ), |
43 | | - "system_prompt": agent_config.get("system_prompt"), |
44 | | - "error_patterns": get_default_error_patterns(), |
45 | | - "aws_capabilities": get_aws_service_capabilities(), |
46 | | - } |
47 | | - ) |
48 | | - |
49 | | - # Apply parameters with type conversion |
50 | | - params = agent_config.get("parameters", {}) |
51 | | - config["max_log_events"] = safe_int_conversion(params.get("max_log_events"), 5) |
52 | | - config["time_range_hours_default"] = safe_int_conversion( |
53 | | - params.get("time_range_hours_default"), 24 |
54 | | - ) |
55 | | - |
56 | | - # Apply UI overrides for context limits - UI config takes precedence |
57 | | - if pattern_config and "max_log_events" in pattern_config: |
58 | | - config["max_log_events"] = safe_int_conversion( |
59 | | - pattern_config["max_log_events"], config["max_log_events"] |
60 | | - ) |
61 | | - |
62 | | - # Validate required fields |
63 | | - if not config.get("system_prompt"): |
64 | | - raise ValueError("system_prompt is required") |
65 | | - |
66 | | - configure_logging( |
67 | | - log_level=config.get("log_level"), |
68 | | - strands_log_level=config.get("strands_log_level"), |
69 | | - ) |
70 | | - |
71 | | - return config |
72 | | - |
73 | | - |
74 | | -def get_default_error_patterns() -> List[str]: |
75 | | - """Returns standard error patterns for CloudWatch log filtering.""" |
76 | | - return [ |
77 | | - "ERROR", |
78 | | - "CRITICAL", |
79 | | - "FATAL", |
80 | | - "Exception", |
81 | | - "Traceback", |
82 | | - "Failed", |
83 | | - "Timeout", |
84 | | - "AccessDenied", |
85 | | - "ThrottlingException", |
86 | | - ] |
87 | | - |
88 | | - |
89 | | -def get_context_limits() -> Dict[str, int]: |
90 | | - """Returns default resource and context size constraints.""" |
91 | | - return { |
92 | | - "max_log_events": 5, |
93 | | - "max_log_message_length": 400, |
94 | | - "max_events_per_log_group": 5, |
95 | | - "max_log_groups": 20, |
96 | | - "max_stepfunction_timeline_events": 3, |
97 | | - "max_stepfunction_error_length": 400, |
98 | | - "time_range_hours_default": 24, |
99 | | - } |
100 | | - |
101 | | - |
102 | 14 | def get_aws_service_capabilities() -> Dict[str, Any]: |
103 | 15 | """Returns AWS service integration metadata and descriptions.""" |
104 | 16 | return { |
@@ -161,12 +73,3 @@ def truncate_message(message: str, max_length: int = 200) -> str: |
161 | 73 | if len(message) <= max_length: |
162 | 74 | return message |
163 | 75 | return message[:max_length] + "... [truncated]" |
164 | | - |
165 | | - |
166 | | -def get_config_with_fallback() -> Dict[str, Any]: |
167 | | - """Gets error analyzer config with graceful fallback to defaults.""" |
168 | | - try: |
169 | | - return get_error_analyzer_config() |
170 | | - except Exception as e: |
171 | | - logger.warning(f"Failed to load config, using defaults: {e}") |
172 | | - return get_context_limits() |
0 commit comments