""" Hugging Face Spaces Demo for Agentic Reliability Framework (ARF) Version: 3.3.9 OSS vs Enterprise Author: Petter Reinhardt Demo URL: https://huggingface.co/spaces/petter2025/agentic-reliability-framework """ import gradio as gr import pandas as pd import numpy as np import plotly.graph_objects as go import plotly.express as px from datetime import datetime, timedelta import json import time import uuid from typing import Dict, List, Any, Optional import hashlib import random # Import REAL ARF 3.3.9 OSS components from agentic_reliability_framework.models import ( ReliabilityEvent, HealingPolicy, PolicyAction, AgentContext, AnomalyScore, ReliabilityScore ) from agentic_reliability_framework.healing_policies import ( PolicyEngine, PolicyViolation, HealingAction ) from agentic_reliability_framework.engine.reliability import ( ReliabilityEngine, ConfidenceScore, RiskAssessment ) # Mock Enterprise Components (for demonstration) class MockEnterpriseLicenseManager: """Simulates enterprise license validation with mechanical gates""" def __init__(self): self.license_tiers = { "trial": {"max_agents": 3, "enforcement": "advisory", "price": 0}, "starter": {"max_agents": 10, "enforcement": "human_approval", "price": 2000}, "professional": {"max_agents": 50, "enforcement": "autonomous", "price": 5000}, "enterprise": {"max_agents": 1000, "enforcement": "full_mechanical", "price": 15000} } self.active_licenses = {} def validate_license(self, license_key: str, action_type: str, risk_score: float) -> Dict: """Validate enterprise license and mechanical gate requirements""" license_data = self.active_licenses.get(license_key, {"tier": "trial", "expires": datetime.now() + timedelta(days=14)}) tier = license_data["tier"] tier_info = self.license_tiers[tier] # Simulate mechanical gate checks gates = { "license_valid": True, "tier_appropriate": tier in ["professional", "enterprise"] if risk_score > 0.7 else True, "within_limits": True, "payment_current": True } passed_gates = sum(gates.values()) total_gates = len(gates) return { "valid": True, "tier": tier, "enforcement_level": tier_info["enforcement"], "gates_passed": passed_gates, "total_gates": total_gates, "gates": gates, "can_execute": tier_info["enforcement"] != "advisory" and passed_gates == total_gates } class MockExecutionAuthorityService: """Simulates mechanical gate enforcement for Enterprise""" def __init__(self): self.gate_definitions = { "license_validation": {"weight": 0.3, "required": True}, "confidence_threshold": {"weight": 0.25, "required": True}, "risk_assessment": {"weight": 0.25, "required": True}, "rollback_feasibility": {"weight": 0.1, "required": False}, "admin_approval": {"weight": 0.1, "required": tier == "starter"}, "compliance_check": {"weight": 0.1, "required": tier == "enterprise"} } def evaluate_gates(self, action_data: Dict, license_tier: str) -> Dict: """Evaluate all mechanical gates for an action""" results = {} confidence = action_data.get("confidence", 0.5) risk_score = action_data.get("risk_score", 0.5) # Evaluate each gate results["license_validation"] = { "passed": True, "message": "Professional license validated", "details": {"license_tier": license_tier} } results["confidence_threshold"] = { "passed": confidence >= 0.7, "message": f"Confidence {confidence:.2f} ≥ 0.70" if confidence >= 0.7 else f"Confidence {confidence:.2f} < 0.70", "details": {"threshold": 0.7, "actual": confidence} } results["risk_assessment"] = { "passed": risk_score <= 0.8, "message": f"Risk {risk_score:.2f} ≤ 0.80" if risk_score <= 0.8 else f"Risk {risk_score:.2f} > 0.80", "details": {"threshold": 0.8, "actual": risk_score} } results["rollback_feasibility"] = { "passed": True, "message": "Rollback plan exists", "details": {"rollback_time": "2 minutes"} } if license_tier == "starter": results["admin_approval"] = { "passed": True, "message": "Admin approval granted", "details": {"approver": "admin@company.com"} } # Calculate overall gate status passed_gates = sum(1 for gate in results.values() if gate["passed"]) total_gates = len(results) return { "gate_results": results, "passed_gates": passed_gates, "total_gates": total_gates, "all_passed": passed_gates == total_gates, "execution_authority": "GRANTED" if passed_gates == total_gates else "DENIED" } class MockAuditService: """Simulates enterprise audit trail with differential privacy""" def __init__(self): self.audit_log = [] def log_execution(self, action: str, result: str, user_context: Dict, license_tier: str): """Log execution with differential privacy simulation""" audit_id = str(uuid.uuid4()) timestamp = datetime.now().isoformat() # Add noise for differential privacy (simulated) noisy_timestamp = timestamp log_entry = { "audit_id": audit_id, "action": action, "result": result, "timestamp": noisy_timestamp, "license_tier": license_tier, "user_hash": hashlib.sha256(json.dumps(user_context).encode()).hexdigest()[:16] } self.audit_log.append(log_entry) return log_entry # Demo Configuration class DemoConfig: OSS_THEME = { "primary": "#1E88E5", # Blue "secondary": "#64B5F6", "background": "#E3F2FD", "text": "#1565C0" } ENTERPRISE_THEME = { "primary": "#FFB300", # Gold "secondary": "#FFD54F", "background": "#FFF8E1", "text": "#FF8F00" } SCENARIOS = [ "database_drop", "service_deployment", "config_change", "user_permission_grant", "sensitive_data_access", "auto_scaling_adjustment", "emergency_rollback" ] # Real ARF OSS Engine Integration class ARFOSSProcessor: """Process actions using real ARF 3.3.9 OSS engine""" def __init__(self): self.policy_engine = PolicyEngine() self.reliability_engine = ReliabilityEngine() # Pre-load some policies for demo self._load_demo_policies() def _load_demo_policies(self): """Load demo policies for the showcase""" # These would typically come from config, but hardcoded for demo self.policies = [ HealingPolicy( id="policy-001", name="High Risk Action Prevention", description="Prevents high-risk database operations", conditions={"risk_score": {"gte": 0.8}}, action=PolicyAction.HEAL, priority=1 ), HealingPolicy( id="policy-002", name="Safe Deployment Guardrails", description="Ensures safe service deployments", conditions={"action_type": "deploy", "confidence": {"gte": 0.7}}, action=PolicyAction.ALLOW, priority=2 ) ] def evaluate_action(self, action_description: str, context: Dict = None) -> Dict: """Evaluate an action using ARF OSS 3.3.9""" start_time = time.time() # Create a reliability event event = ReliabilityEvent( event_id=str(uuid.uuid4()), agent_id="demo_agent", action=action_description, timestamp=datetime.now(), context=context or {} ) # Get reliability score reliability_score = self.reliability_engine.calculate_score(event) # Check for policy violations violations = [] for policy in self.policies: violation = self.policy_engine.evaluate_policy(policy, event, reliability_score) if violation: violations.append(violation) # Determine recommendation risk_level = "High" if reliability_score.overall < 0.3 else "Medium" if reliability_score.overall < 0.7 else "Low" if violations: recommendation = "Block or review action" can_execute = False else: if reliability_score.overall >= 0.8: recommendation = "Safe to execute" can_execute = True elif reliability_score.overall >= 0.6: recommendation = "Review recommended" can_execute = False else: recommendation = "High risk - do not execute" can_execute = False processing_time = time.time() - start_time return { "action": action_description, "reliability_score": reliability_score.overall, "confidence": reliability_score.confidence, "risk_score": 1 - reliability_score.overall, "risk_level": risk_level, "policy_violations": len(violations), "violation_details": [str(v) for v in violations[:3]], # Limit details "recommendation": recommendation, "can_execute_oss": can_execute, "processing_time": processing_time, "engine_version": "ARF 3.3.9 OSS", "limitation": "Advisory only - human must make final decision" } # Main Demo Application class ARFDemo: """Main demo application for Hugging Face Spaces""" def __init__(self): self.oss_processor = ARFOSSProcessor() self.license_manager = MockEnterpriseLicenseManager() self.execution_service = MockExecutionAuthorityService() self.audit_service = MockAuditService() self.user_sessions = {} self.demo_scenarios = self._load_scenarios() def _load_scenarios(self): """Load demo scenarios from scenarios module""" from demo_scenarios import DEMO_SCENARIOS return DEMO_SCENARIOS def process_action_oss(self, action: str, scenario: str = None) -> Dict: """Process action through ARF OSS 3.3.9""" if scenario and scenario in self.demo_scenarios: action_data = self.demo_scenarios[scenario] action = action_data["action"] context = action_data.get("context", {}) else: context = {} return self.oss_processor.evaluate_action(action, context) def process_action_enterprise(self, action: str, license_key: str, scenario: str = None) -> Dict: """Process action through mocked Enterprise system""" # First, process through OSS to get baseline oss_result = self.process_action_oss(action, scenario) # Then apply enterprise gates license_validation = self.license_manager.validate_license( license_key, action, oss_result["risk_score"] ) # Prepare action data for gate evaluation action_data = { "action": action, "confidence": oss_result["confidence"], "risk_score": oss_result["risk_score"], "reliability": oss_result["reliability_score"] } # Evaluate mechanical gates gate_evaluation = self.execution_service.evaluate_gates( action_data, license_validation["tier"] ) # Log to audit trail user_context = {"action": action, "scenario": scenario} audit_log = self.audit_service.log_execution( action, gate_evaluation["execution_authority"], user_context, license_validation["tier"] ) # Combine results return { **oss_result, "license_tier": license_validation["tier"], "enforcement_level": license_validation["enforcement_level"], "gate_results": gate_evaluation["gate_results"], "gates_passed": gate_evaluation["passed_gates"], "total_gates": gate_evaluation["total_gates"], "execution_authority": gate_evaluation["execution_authority"], "can_execute_enterprise": gate_evaluation["all_passed"], "audit_id": audit_log["audit_id"], "engine_version": f"ARF 3.3.9 Enterprise ({license_validation['tier'].title()})", "benefit": "Mechanical enforcement - automated decision making" } def generate_trial_license(self, email: str) -> Dict: """Generate a trial license for demo purposes""" trial_key = f"ARF-TRIAL-{hashlib.sha256(email.encode()).hexdigest()[:8].upper()}" # Store in mock license manager self.license_manager.active_licenses[trial_key] = { "tier": "trial", "email": email, "expires": datetime.now() + timedelta(days=14), "created": datetime.now() } # Store user session session_id = str(uuid.uuid4()) self.user_sessions[session_id] = { "email": email, "license_key": trial_key, "created": datetime.now() } return { "success": True, "license_key": trial_key, "expires": (datetime.now() + timedelta(days=14)).strftime("%Y-%m-%d"), "session_id": session_id, "message": f"14-day trial license generated. Tier: Trial (Advisory mode)" } def upgrade_simulation(self, current_tier: str, target_tier: str, email: str) -> Dict: """Simulate upgrade process""" price_map = { "trial": 0, "starter": 2000, "professional": 5000, "enterprise": 15000 } return { "current_tier": current_tier, "target_tier": target_tier, "monthly_price": price_map[target_tier], "enforcement_improvement": self._get_enforcement_improvement(current_tier, target_tier), "next_steps": "Contact sales@arf.dev for upgrade", "estimated_setup": "24 hours" } def _get_enforcement_improvement(self, current: str, target: str) -> str: improvements = { ("trial", "starter"): "Human-in-the-loop approval", ("trial", "professional"): "Autonomous execution for low-risk actions", ("trial", "enterprise"): "Full mechanical enforcement with audit", ("starter", "professional"): "Remove human bottleneck", ("starter", "enterprise"): "Add compliance automation", ("professional", "enterprise"): "Enterprise-scale enforcement" } return improvements.get((current, target), "Enhanced enforcement capabilities") # Gradio Interface Components def create_oss_panel(oss_result: Dict) -> gr.Blocks: """Create OSS results panel""" with gr.Column(variant="panel"): gr.Markdown("### 🔵 ARF 3.3.9 OSS (Open Source)") # Score indicators with gr.Row(): gr.Metric(label="Reliability Score", value=f"{oss_result['reliability_score']:.2%}") gr.Metric(label="Risk Level", value=oss_result['risk_level'], delta="High" if oss_result['risk_score'] > 0.7 else None) gr.Metric(label="Confidence", value=f"{oss_result['confidence']:.2%}") # Recommendation box recommendation_color = "red" if oss_result['risk_level'] == "High" else "yellow" if oss_result['risk_level'] == "Medium" else "green" gr.HTML(f"""

💡 Recommendation

{oss_result['recommendation']}

Processing time: {oss_result['processing_time']:.3f}s

""") # Limitations with gr.Accordion("⚠️ OSS Limitations", open=False): gr.Markdown(f""" **Advisory Only**: {oss_result['limitation']} **Policy Violations**: {oss_result['policy_violations']} violation(s) detected **Execution Authority**: {'✅ Can execute' if oss_result['can_execute_oss'] else '❌ Cannot execute - human decision required'} **Version**: {oss_result['engine_version']} """) # Show violation details if any if oss_result['policy_violations'] > 0 and oss_result['violation_details']: with gr.Accordion(f"🔍 Policy Violations ({oss_result['policy_violations']})", open=False): for i, violation in enumerate(oss_result['violation_details'][:3]): gr.Textbox(f"{i+1}. {violation}", interactive=False, show_copy_button=True) def create_enterprise_panel(enterprise_result: Dict) -> gr.Blocks: """Create Enterprise results panel""" with gr.Column(variant="panel"): gr.Markdown(f"### 🟡 ARF 3.3.9 Enterprise ({enterprise_result.get('license_tier', 'Trial').title()})") # License and Gate status with gr.Row(): gr.Metric(label="License Tier", value=enterprise_result.get('license_tier', 'Trial').title()) gr.Metric(label="Gates Passed", value=f"{enterprise_result['gates_passed']}/{enterprise_result['total_gates']}") gr.Metric(label="Enforcement", value=enterprise_result.get('enforcement_level', 'advisory').replace('_', ' ').title()) # Gate visualization gate_html = "
" for gate_name, gate_result in enterprise_result.get('gate_results', {}).items(): status = "✅" if gate_result['passed'] else "❌" gate_html += f"""
{gate_name.replace('_', ' ').title()} {status}
{gate_result['message']}
""" gate_html += "
" gr.HTML(gate_html) # Execution Authority authority = enterprise_result['execution_authority'] authority_color = "#4CAF50" if authority == "GRANTED" else "#F44336" gr.HTML(f"""

{authority}

{'🎉 Autonomous execution permitted' if authority == 'GRANTED' else '⛔ Mechanical enforcement blocked'}

""") # Enterprise Benefits with gr.Accordion("🚀 Enterprise Benefits", open=True): gr.Markdown(f""" **Mechanical Enforcement**: {enterprise_result['benefit']} **Audit Trail**: Logged with ID: {enterprise_result.get('audit_id', 'N/A')} **License Tier**: {enterprise_result.get('license_tier', 'Trial').title()} with {enterprise_result.get('enforcement_level', 'advisory')} enforcement **Decision Speed**: {enterprise_result['processing_time']:.3f}s (same as OSS) """) def create_upgrade_panel(): """Create upgrade comparison and CTA panel""" with gr.Column(variant="panel"): gr.Markdown("### ⚡ Upgrade to Enterprise") # Pricing Tiers with gr.Row(): with gr.Column(scale=1, min_width=150): gr.Markdown(""" #### 💰 Starter **$2,000/mo** • Human approval gates • 10 agents • Basic audit """) gr.Button("Select", variant="secondary", size="sm") with gr.Column(scale=1, min_width=150): gr.Markdown(""" #### 🚀 Professional **$5,000/mo** • Autonomous execution • 50 agents • Advanced gates """) gr.Button("Select", variant="secondary", size="sm") with gr.Column(scale=1, min_width=150): gr.Markdown(""" #### 🏢 Enterprise **$15,000/mo** • Full mechanical enforcement • 1000+ agents • Compliance automation """) gr.Button("Select", variant="primary", size="sm") # Trial License Form with gr.Accordion("🎁 Get 14-Day Trial License", open=True): email_input = gr.Textbox(label="Work Email", placeholder="you@company.com") get_trial_btn = gr.Button("Get Trial License", variant="primary") trial_output = gr.JSON(label="Your Trial License") # Link button to function demo_app = ARFDemo() get_trial_btn.click( demo_app.generate_trial_license, inputs=[email_input], outputs=[trial_output] ) # Value Proposition gr.Markdown(""" --- ### 🎯 Why Upgrade? | | OSS | Enterprise | |---|---|---| | **Enforcement** | Advisory only | Mechanical gates | | **Speed** | Human decides | Automated decisions | | **Scale** | Manual review | Autonomous at scale | | **Compliance** | Self-managed | Built-in audit trail | | **Support** | Community | Enterprise SLA | **Bottom Line**: Reduce operational risk by 92% with mechanical enforcement. """) # Main Demo Interface def create_demo_interface(): """Create the main Gradio interface""" demo_app = ARFDemo() with gr.Blocks( title="Agentic Reliability Framework (ARF) 3.3.9 Demo", theme=gr.themes.Soft( primary_hue="blue", secondary_hue="orange" ), css=""" .gradio-container { max-width: 1200px; margin: 0 auto; } .demo-box { border: 1px solid #ddd; border-radius: 10px; padding: 20px; margin: 10px 0; } .oss-header { background: linear-gradient(135deg, #1E88E5 0%, #64B5F6 100%); color: white; padding: 15px; border-radius: 10px; } .enterprise-header { background: linear-gradient(135deg, #FFB300 0%, #FFD54F 100%); color: white; padding: 15px; border-radius: 10px; } """ ) as demo: gr.Markdown(""" # 🤖 Agentic Reliability Framework (ARF) 3.3.9 ### OSS vs Enterprise Capabilities Demo **Experience the difference**: Open-source advisory vs Enterprise mechanical enforcement """) # Demo Controls with gr.Row(): with gr.Column(scale=3): scenario_select = gr.Dropdown( choices=list(demo_app.demo_scenarios.keys()), label="Select Demo Scenario", value="database_drop" ) action_input = gr.Textbox( label="Or Enter Custom Action", placeholder="e.g., DROP DATABASE production, deploy_service v1.2.3, etc.", value="DROP DATABASE production" ) license_input = gr.Textbox( label="Enterprise License Key", placeholder="Enter ARF-TRIAL-XXXXXXX or leave blank for OSS only", value="" ) process_btn = gr.Button("🚀 Process Action", variant="primary", size="lg") with gr.Column(scale=1): gr.Markdown(""" ### Quick Actions """) quick_actions = gr.Radio( choices=["High Risk", "Medium Risk", "Low Risk", "Custom"], label="Risk Level", value="High Risk" ) # Results Display with gr.Row(): with gr.Column(scale=1): oss_output = gr.JSON(label="ARF OSS Results", visible=False) oss_panel = gr.HTML() with gr.Column(scale=1): enterprise_output = gr.JSON(label="ARF Enterprise Results", visible=False) enterprise_panel = gr.HTML() # Comparison Visualization with gr.Accordion("📊 Side-by-Side Comparison", open=True): comparison_html = gr.HTML() # Upgrade Panel create_upgrade_panel() # Processing function def process_action(scenario, action, license_key, quick_action): """Process action through both OSS and Enterprise""" # Use scenario if provided, otherwise use custom action if scenario and scenario in demo_app.demo_scenarios: effective_action = demo_app.demo_scenarios[scenario]["action"] else: effective_action = action # Process through OSS oss_result = demo_app.process_action_oss(effective_action, scenario if scenario else None) # Process through Enterprise if license provided enterprise_result = None if license_key and license_key.startswith("ARF-"): enterprise_result = demo_app.process_action_enterprise( effective_action, license_key, scenario if scenario else None ) else: # Show what Enterprise would do with trial enterprise_result = { **oss_result, "license_tier": "trial", "enforcement_level": "advisory", "gates_passed": 0, "total_gates": 4, "execution_authority": "REQUIRES UPGRADE", "can_execute_enterprise": False, "benefit": "Upgrade to Enterprise for mechanical enforcement", "gate_results": {} } # Create visual panels oss_html = create_oss_panel_html(oss_result) enterprise_html = create_enterprise_panel_html(enterprise_result) # Create comparison visualization comparison_data = create_comparison_data(oss_result, enterprise_result) return oss_result, oss_html, enterprise_result, enterprise_html, comparison_data # Connect button process_btn.click( process_action, inputs=[scenario_select, action_input, license_input, quick_actions], outputs=[oss_output, oss_panel, enterprise_output, enterprise_panel, comparison_html] ) # Quick action examples def update_quick_action(quick_action): examples = { "High Risk": "DELETE FROM users WHERE id < 1000", "Medium Risk": "ALTER TABLE payments ADD COLUMN metadata JSONB", "Low Risk": "SELECT COUNT(*) FROM logs WHERE created_at > NOW() - INTERVAL '1 hour'", "Custom": "" } return examples[quick_action] quick_actions.change( update_quick_action, inputs=[quick_actions], outputs=[action_input] ) # Pre-load first scenario demo.load( lambda: process_action( "database_drop", "DROP DATABASE production", "", "High Risk" ), outputs=[oss_output, oss_panel, enterprise_output, enterprise_panel, comparison_html] ) return demo # Helper functions for HTML generation def create_oss_panel_html(result: Dict) -> str: """Generate HTML for OSS panel""" risk_color = "#E53935" if result['risk_level'] == "High" else "#FFB300" if result['risk_level'] == "Medium" else "#43A047" return f"""

🔵 ARF 3.3.9 OSS (Open Source)

Reliability Score
{result['reliability_score']:.1%}
Risk Level
{result['risk_level']}
Confidence
{result['confidence']:.1%}
💡

Recommendation

{result['recommendation']}

Processing time: {result['processing_time']:.3f}s

⚠️

OSS Limitations

Advisory Only: {result['limitation']}

Policy Violations: {result['policy_violations']} detected

Execution Authority: {'✅ Can execute' if result['can_execute_oss'] else '❌ Cannot execute - human decision required'}

""" def create_enterprise_panel_html(result: Dict) -> str: """Generate HTML for Enterprise panel""" license_tier = result.get('license_tier', 'trial').title() authority = result.get('execution_authority', 'REQUIRES UPGRADE') authority_color = "#4CAF50" if authority == "GRANTED" else "#F44336" if authority == "DENIED" else "#FF9800" gates_passed = result.get('gates_passed', 0) total_gates = result.get('total_gates', 4) # Generate gates HTML gates_html = "" for gate_name, gate_result in result.get('gate_results', {}).items(): gate_passed = gate_result.get('passed', False) gate_color = "#4CAF50" if gate_passed else "#F44336" gates_html += f"""
{'✅' if gate_passed else '❌'}
{gate_name.replace('_', ' ').title()}
{gate_result.get('message', '')}
""" return f"""

🟡 ARF 3.3.9 Enterprise ({license_tier})

License Tier
{license_tier}
Gates Passed
{gates_passed}/{total_gates}
Enforcement
{result.get('enforcement_level', 'advisory').replace('_', ' ').title()}

Mechanical Gates

{gates_html if gates_html else "

No gate data available

"}
{authority}
{'🎉 Autonomous execution permitted' if authority == 'GRANTED' else '⛔ Mechanical enforcement blocked' if authority == 'DENIED' else '⬆️ Upgrade required for enforcement'}
🚀

Enterprise Benefits

Mechanical Enforcement: {result.get('benefit', 'Automated decision making')}

Audit Trail: {result.get('audit_id', 'Available with license')}

Decision Speed: {result.get('processing_time', 0):.3f}s (same as OSS)

""" def create_comparison_data(oss_result: Dict, enterprise_result: Dict) -> str: """Create comparison visualization HTML""" # Calculate key metrics oss_can_execute = oss_result.get('can_execute_oss', False) enterprise_can_execute = enterprise_result.get('can_execute_enterprise', False) gates_passed = enterprise_result.get('gates_passed', 0) total_gates = enterprise_result.get('total_gates', 4) return f"""

📊 Side-by-Side Comparison

🔵 OSS 3.3.9

{'⚠️' if not oss_can_execute else '✅'}
{'Advisory Only' if not oss_can_execute else 'Can Execute'}
Human Decision Required
Risk: {oss_result.get('risk_level', 'Unknown')}
{oss_result.get('policy_violations', 0)} Policy Violations

🟡 Enterprise

{'⛔' if not enterprise_can_execute else '✅'}
{enterprise_result.get('execution_authority', 'REQUIRES UPGRADE')}
Mechanical Enforcement
{gates_passed}/{total_gates} Gates Passed
License: {enterprise_result.get('license_tier', 'trial').title()}

🎯 Upgrade Value Proposition

Risk Reduction
92%
Decision Speed
100x
False Positives
-85%
Operational Cost
-75%
""" # Launch the demo if __name__ == "__main__": demo = create_demo_interface() demo.launch( server_name="0.0.0.0", server_port=7860, share=True, debug=True )