Spaces:
Sleeping
Sleeping
| from schemas.models import ConsensusRequest, ConsensusResult | |
| class ConsensusEngine: | |
| """Calculates weighted composite consensus EV across 7 key intelligence vectors.""" | |
| def calculate_consensus(req: ConsensusRequest) -> ConsensusResult: | |
| weights = { | |
| "evidence": 0.25, | |
| "agreement": 0.20, | |
| "source_quality": 0.15, | |
| "historical_accuracy": 0.15, | |
| "memory_similarity": 0.10, | |
| "model_confidence": 0.10, | |
| "risk_penalty": 0.05, | |
| } | |
| weighted_score = ( | |
| (req.evidence_confidence * weights["evidence"]) | |
| + (req.agreement_score * weights["agreement"]) | |
| + (req.source_quality * weights["source_quality"]) | |
| + (req.historical_accuracy * weights["historical_accuracy"]) | |
| + (req.memory_similarity * weights["memory_similarity"]) | |
| + (req.model_confidence * weights["model_confidence"]) | |
| - (req.mission_risk * weights["risk_penalty"]) | |
| ) | |
| composite = round(max(0.0, min(100.0, weighted_score)), 2) | |
| if composite >= 85.0: | |
| rec = "HIGH_CONFIDENCE_EXECUTE" | |
| tier = "TIER_1_OPTIMAL" | |
| risk_desc = "Low operational risk; verified across independent evidence channels." | |
| elif composite >= 65.0: | |
| rec = "PROCEED_WITH_VERIFICATION" | |
| tier = "TIER_2_MODERATE" | |
| risk_desc = "Moderate confidence; minor conflicts or unverified secondary claims." | |
| else: | |
| rec = "REQUIRES_HUMAN_REVIEW_OR_DEEPER_SEARCH" | |
| tier = "TIER_3_ELEVATED_RISK" | |
| risk_desc = "Elevated risk; high conflict score or low source authority." | |
| return ConsensusResult( | |
| mission_id=req.mission_id, | |
| topic=req.topic, | |
| composite_consensus_score=composite, | |
| decision_recommendation=rec, | |
| risk_assessment=risk_desc, | |
| confidence_tier=tier, | |
| ) | |