22Intelligent Acknowledgment Agent for evaluating violation acknowledgment requests.
33"""
44
5- import logging
65from typing import Any
76
7+ import structlog
88from langchain_core .messages import HumanMessage , SystemMessage
99from langgraph .graph import StateGraph
1010
1313from src .agents .base import AgentResult , BaseAgent
1414from src .integrations .providers import get_chat_model
1515
16- logger = logging . getLogger ( __name__ )
16+ logger = structlog . get_logger ( )
1717
1818
1919class AcknowledgmentAgent (BaseAgent ):
@@ -31,7 +31,7 @@ def __init__(self, max_retries: int = 3, timeout: float = 30.0):
3131 # Call super class __init__ first
3232 super ().__init__ (max_retries = max_retries , agent_name = "acknowledgment_agent" )
3333 self .timeout = timeout
34- logger .info (f"🧠 Acknowledgment agent initialized with timeout: { timeout } s" )
34+ logger .info ("acknowledgment_agent_initialized_with_timeout_s" , timeout = timeout )
3535
3636 def _build_graph (self ) -> Any :
3737 """
@@ -63,7 +63,7 @@ async def _evaluate_node(self, state: Any) -> AgentResult:
6363 )
6464 return result
6565 except Exception as e :
66- logger .error (f"🧠 Error in evaluation node: { e } " )
66+ logger .error ("error_in_evaluation_node" , e = e )
6767 return AgentResult (success = False , message = f"Evaluation failed: { str (e )} " , data = {"error" : str (e )})
6868
6969 @staticmethod
@@ -86,8 +86,8 @@ async def evaluate_acknowledgment(
8686 Intelligently evaluate an acknowledgment request based on rule descriptions and context.
8787 """
8888 try :
89- logger .info (f"🧠 Evaluating acknowledgment request from { commenter } " )
90- logger .info (f"🧠 Reason: { acknowledgment_reason } " )
89+ logger .info ("evaluating_acknowledgment_request_from" , commenter = commenter )
90+ logger .info ("reason" , acknowledgment_reason = acknowledgment_reason )
9191 logger .info (f"🧠 Violations to evaluate: { len (violations )} " )
9292
9393 # Validate inputs
@@ -102,7 +102,7 @@ async def evaluate_acknowledgment(
102102 evaluation_prompt = create_evaluation_prompt (acknowledgment_reason , violations , pr_data , commenter , rules )
103103
104104 # Get LLM evaluation with structured output
105- logger .info ("🧠 Requesting LLM evaluation with structured output... " )
105+ logger .info ("requesting_llm_evaluation_with_structured_output " )
106106
107107 # Use the same pattern as other agents: direct get_chat_model call
108108 llm = get_chat_model (agent = "acknowledgment_agent" )
@@ -112,12 +112,12 @@ async def evaluate_acknowledgment(
112112 structured_result = await self ._execute_with_timeout (structured_llm .ainvoke (messages ), timeout = self .timeout )
113113
114114 if not structured_result :
115- logger .error ("🧠 Empty LLM response received " )
115+ logger .error ("empty_llm_response_received " )
116116 return AgentResult (
117117 success = False , message = "Empty response from LLM" , data = {"error" : "LLM returned empty response" }
118118 )
119119
120- logger .info ("🧠 Successfully received structured LLM evaluation result " )
120+ logger .info ("successfully_received_structured_llm_evaluation_result " )
121121
122122 # Map LLM decisions back to original violations using rule_description
123123 acknowledgable_violations = []
@@ -138,11 +138,9 @@ async def evaluate_acknowledgment(
138138 # Fallback: try to find by rule_description
139139 original_violation = self ._find_violation_by_rule_description (rule_description , violations )
140140 if original_violation :
141- logger .info (f"🧠 Found violation by rule description: ' { rule_description } '" )
141+ logger .info ("found_violation_by_rule_description" , rule_description = rule_description )
142142 else :
143- logger .warning (
144- f"🧠 LLM returned rule_description '{ rule_description } ' not found in original violations"
145- )
143+ logger .warning ("llm_returned_ruledescription_not_found_in" , rule_description = rule_description )
146144
147145 if original_violation :
148146 violation_copy = original_violation .copy ()
@@ -168,24 +166,22 @@ async def evaluate_acknowledgment(
168166 # Fallback: try to find by rule_description
169167 original_violation = self ._find_violation_by_rule_description (rule_description , violations )
170168 if original_violation :
171- logger .info (f"🧠 Found violation by rule description: ' { rule_description } '" )
169+ logger .info ("found_violation_by_rule_description" , rule_description = rule_description )
172170 else :
173- logger .warning (
174- f"🧠 LLM returned rule_description '{ rule_description } ' not found in original violations"
175- )
171+ logger .warning ("llm_returned_ruledescription_not_found_in" , rule_description = rule_description )
176172
177173 if original_violation :
178174 violation_copy = original_violation .copy ()
179175 # Add fix-specific fields
180176 violation_copy .update ({"fix_reason" : llm_violation .reason , "priority" : llm_violation .priority })
181177 require_fixes .append (violation_copy )
182178
183- logger .info ("🧠 Intelligent evaluation completed: " )
184- logger .info (f" Valid: { structured_result .is_valid } " )
185- logger .info (f" Reasoning: { structured_result .reasoning } " )
179+ logger .info ("intelligent_evaluation_completed " )
180+ logger .info ("valid" , is_valid = structured_result .is_valid )
181+ logger .info ("reasoning" , reasoning = structured_result .reasoning )
186182 logger .info (f" Acknowledged violations: { len (acknowledgable_violations )} " )
187183 logger .info (f" Require fixes: { len (require_fixes )} " )
188- logger .info (f" Confidence: { structured_result .confidence } " )
184+ logger .info ("confidence" , confidence = structured_result .confidence )
189185
190186 return AgentResult (
191187 success = True ,
@@ -201,7 +197,7 @@ async def evaluate_acknowledgment(
201197 )
202198
203199 except Exception as e :
204- logger .error (f"🧠 Error in acknowledgment evaluation: { e } " )
200+ logger .error ("error_in_acknowledgment_evaluation" , e = e )
205201 import traceback
206202
207203 logger .error (f"🧠 Traceback: { traceback .format_exc ()} " )
@@ -228,7 +224,7 @@ async def execute(self, **kwargs: Any) -> AgentResult:
228224 rules = rules ,
229225 )
230226
231- logger .warning ("🧠 execute() method called on AcknowledgmentAgent with missing arguments " )
227+ logger .warning ("execute_method_called_on_acknowledgmentagent_with " )
232228 return AgentResult (
233229 success = False , message = "AcknowledgmentAgent requires specific arguments for execute()" , data = {}
234230 )
0 commit comments