Spaces:
Sleeping
Sleeping
| # services/agentic_integration_logger.py | |
| """ | |
| Agentic Integration Logger - Comprehensive audit trail for all agentic executions. | |
| """ | |
| import json | |
| import logging | |
| from datetime import datetime, timezone | |
| from typing import Dict, Any, Optional | |
| logger = logging.getLogger("agentic.integration") | |
| def log_agentic_attempt( | |
| session_id: str, | |
| pipeline: Dict[str, Any], | |
| decision: str | |
| ): | |
| """Log decision to use/skip agentic orchestration.""" | |
| logger.info(json.dumps({ | |
| "event": "agentic_decision", | |
| "session_id": session_id, | |
| "pipeline_name": pipeline.get("pipeline_name"), | |
| "decision": decision, | |
| "timestamp": datetime.now(timezone.utc).isoformat() | |
| })) | |
| def log_agentic_execution( | |
| session_id: str, | |
| pipeline: Dict[str, Any], | |
| agentic_summary: Dict[str, Any], | |
| result: str, | |
| fallback_reason: Optional[str] = None | |
| ): | |
| """Log complete agentic execution with all metadata.""" | |
| log_entry = { | |
| "event": "agentic_execution", | |
| "session_id": session_id, | |
| "pipeline_id": pipeline.get("pipeline_id"), | |
| "pipeline_name": pipeline.get("pipeline_name"), | |
| "result": result, # "success" | "fallback" | |
| "timestamp": datetime.now(timezone.utc).isoformat(), | |
| "plan_versions": len(agentic_summary.get("plan_versions", [])), | |
| "total_messages": agentic_summary.get("total_messages", 0), | |
| "rejections": len(agentic_summary.get("rejections", [])), | |
| "verification": agentic_summary.get("verification", {}) | |
| } | |
| if fallback_reason: | |
| log_entry["fallback_reason"] = fallback_reason | |
| if result == "success": | |
| logger.info(json.dumps(log_entry)) | |
| else: | |
| logger.warning(json.dumps(log_entry)) | |
| def log_fallback_trigger( | |
| session_id: str, | |
| reason: str, | |
| exception: Optional[Exception] = None | |
| ): | |
| """Log when fallback to legacy is triggered.""" | |
| logger.warning(json.dumps({ | |
| "event": "fallback_triggered", | |
| "session_id": session_id, | |
| "reason": reason, | |
| "exception": str(exception) if exception else None, | |
| "timestamp": datetime.now(timezone.utc).isoformat() | |
| })) | |
| def log_shadow_comparison( | |
| session_id: str, | |
| legacy_result: Dict[str, Any], | |
| agentic_result: Dict[str, Any], | |
| differences: Dict[str, Any] | |
| ): | |
| """Log shadow mode execution comparison.""" | |
| logger.info(json.dumps({ | |
| "event": "shadow_mode_comparison", | |
| "session_id": session_id, | |
| "legacy_status": legacy_result.get("status"), | |
| "agentic_status": agentic_result.get("status"), | |
| "differences": differences, | |
| "timestamp": datetime.now(timezone.utc).isoformat() | |
| })) | |