|
|
""" |
|
|
License Compliance Agent for SPARKNET |
|
|
|
|
|
AI-powered license agreement monitoring and compliance verification. |
|
|
Part of Scenario 3: License Compliance Monitoring. |
|
|
|
|
|
PRIVACY & SECURITY NOTES: |
|
|
------------------------- |
|
|
This agent handles sensitive financial and contractual data. For production deployments: |
|
|
|
|
|
1. DATA ISOLATION: |
|
|
- License data should be stored in isolated database schemas |
|
|
- Implement row-level security for multi-tenant deployments |
|
|
- Consider geographic data residency requirements |
|
|
|
|
|
2. GDPR COMPLIANCE: |
|
|
- Implement right-to-erasure for terminated agreements |
|
|
- Maintain data processing records |
|
|
- Enable data portability exports |
|
|
|
|
|
3. AUDIT REQUIREMENTS: |
|
|
- All compliance checks should be logged |
|
|
- Maintain immutable audit trail |
|
|
- Enable compliance report generation |
|
|
|
|
|
4. PRIVATE DEPLOYMENT: |
|
|
- Use Ollama for local LLM inference (no data leaves network) |
|
|
- Configure local vector store for document embeddings |
|
|
- Implement on-premise authentication |
|
|
|
|
|
Author: SPARKNET Team |
|
|
Project: VISTA/Horizon EU |
|
|
Status: Placeholder - In Development |
|
|
""" |
|
|
|
|
|
from typing import Optional, Dict, Any, List |
|
|
from dataclasses import dataclass |
|
|
from datetime import datetime, date |
|
|
from enum import Enum |
|
|
from loguru import logger |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ComplianceStatus(str, Enum): |
|
|
"""License compliance status.""" |
|
|
COMPLIANT = "compliant" |
|
|
NON_COMPLIANT = "non_compliant" |
|
|
AT_RISK = "at_risk" |
|
|
PENDING_REVIEW = "pending_review" |
|
|
EXPIRED = "expired" |
|
|
|
|
|
|
|
|
class PaymentStatus(str, Enum): |
|
|
"""Payment tracking status.""" |
|
|
PAID = "paid" |
|
|
PENDING = "pending" |
|
|
OVERDUE = "overdue" |
|
|
DISPUTED = "disputed" |
|
|
WAIVED = "waived" |
|
|
|
|
|
|
|
|
@dataclass |
|
|
class LicenseAgreement: |
|
|
""" |
|
|
License agreement data model. |
|
|
|
|
|
GDPR Note: Contains potentially sensitive business information. |
|
|
Implement appropriate access controls and retention policies. |
|
|
""" |
|
|
license_id: str |
|
|
agreement_name: str |
|
|
licensee_name: str |
|
|
licensor_name: str |
|
|
technology_name: str |
|
|
effective_date: date |
|
|
expiration_date: Optional[date] |
|
|
status: ComplianceStatus |
|
|
total_value: Optional[float] |
|
|
currency: str = "EUR" |
|
|
payment_schedule: Optional[List[Dict[str, Any]]] = None |
|
|
milestones: Optional[List[Dict[str, Any]]] = None |
|
|
metadata: Optional[Dict[str, Any]] = None |
|
|
|
|
|
|
|
|
@dataclass |
|
|
class PaymentRecord: |
|
|
""" |
|
|
Payment tracking record. |
|
|
|
|
|
GDPR Note: Financial data - ensure encryption and access logging. |
|
|
""" |
|
|
payment_id: str |
|
|
license_id: str |
|
|
amount: float |
|
|
currency: str |
|
|
due_date: date |
|
|
paid_date: Optional[date] |
|
|
status: PaymentStatus |
|
|
payment_type: str |
|
|
notes: Optional[str] = None |
|
|
|
|
|
|
|
|
@dataclass |
|
|
class ComplianceAlert: |
|
|
""" |
|
|
Compliance monitoring alert. |
|
|
|
|
|
Used for notifying TTO staff of compliance issues. |
|
|
""" |
|
|
alert_id: str |
|
|
license_id: str |
|
|
alert_type: str |
|
|
severity: str |
|
|
message: str |
|
|
created_at: datetime |
|
|
resolved: bool = False |
|
|
resolved_at: Optional[datetime] = None |
|
|
|
|
|
|
|
|
class LicenseComplianceAgent: |
|
|
""" |
|
|
Agent for monitoring license agreement compliance. |
|
|
|
|
|
This agent tracks: |
|
|
- Payment schedules and overdue payments |
|
|
- Milestone completion and deadlines |
|
|
- Agreement expiration dates |
|
|
- Compliance violations and alerts |
|
|
|
|
|
DEPLOYMENT CONSIDERATIONS: |
|
|
-------------------------- |
|
|
For private/on-premise deployment: |
|
|
1. Configure local Ollama instance for LLM inference |
|
|
2. Use PostgreSQL with encryption for data storage |
|
|
3. Implement SSO integration for authentication |
|
|
4. Enable audit logging for all operations |
|
|
|
|
|
For cloud deployment (Streamlit Cloud): |
|
|
1. Use secrets management for API keys |
|
|
2. Configure secure database connection |
|
|
3. Enable HTTPS for all communications |
|
|
4. Implement rate limiting for API calls |
|
|
""" |
|
|
|
|
|
def __init__( |
|
|
self, |
|
|
llm_client: Optional[Any] = None, |
|
|
database_url: Optional[str] = None, |
|
|
): |
|
|
""" |
|
|
Initialize License Compliance Agent. |
|
|
|
|
|
Args: |
|
|
llm_client: LangChain LLM client for AI analysis |
|
|
database_url: Database connection URL (use secrets management) |
|
|
""" |
|
|
self.llm_client = llm_client |
|
|
self.database_url = database_url |
|
|
self.name = "LicenseComplianceAgent" |
|
|
self.description = "License agreement monitoring and compliance tracking" |
|
|
|
|
|
logger.info(f"Initialized {self.name} (placeholder)") |
|
|
|
|
|
async def check_payment_compliance( |
|
|
self, |
|
|
license_id: str, |
|
|
) -> Dict[str, Any]: |
|
|
""" |
|
|
Check payment compliance for a license agreement. |
|
|
|
|
|
Args: |
|
|
license_id: License agreement identifier |
|
|
|
|
|
Returns: |
|
|
Compliance status with payment details |
|
|
|
|
|
TODO: Implement actual payment tracking logic |
|
|
""" |
|
|
logger.info(f"Checking payment compliance for license: {license_id}") |
|
|
|
|
|
|
|
|
return { |
|
|
"license_id": license_id, |
|
|
"status": ComplianceStatus.PENDING_REVIEW.value, |
|
|
"message": "Payment compliance check not yet implemented", |
|
|
"payments_due": [], |
|
|
"payments_overdue": [], |
|
|
"next_payment_date": None, |
|
|
"total_outstanding": 0.0, |
|
|
} |
|
|
|
|
|
async def verify_milestone( |
|
|
self, |
|
|
license_id: str, |
|
|
milestone_id: str, |
|
|
) -> Dict[str, Any]: |
|
|
""" |
|
|
Verify milestone completion for a license agreement. |
|
|
|
|
|
Args: |
|
|
license_id: License agreement identifier |
|
|
milestone_id: Milestone identifier |
|
|
|
|
|
Returns: |
|
|
Milestone verification result |
|
|
|
|
|
TODO: Implement actual milestone verification logic |
|
|
""" |
|
|
logger.info(f"Verifying milestone {milestone_id} for license: {license_id}") |
|
|
|
|
|
|
|
|
return { |
|
|
"license_id": license_id, |
|
|
"milestone_id": milestone_id, |
|
|
"status": "pending_verification", |
|
|
"message": "Milestone verification not yet implemented", |
|
|
"evidence_required": True, |
|
|
"verification_deadline": None, |
|
|
} |
|
|
|
|
|
async def generate_compliance_report( |
|
|
self, |
|
|
license_ids: Optional[List[str]] = None, |
|
|
date_range: Optional[tuple] = None, |
|
|
) -> Dict[str, Any]: |
|
|
""" |
|
|
Generate compliance report for license agreements. |
|
|
|
|
|
Args: |
|
|
license_ids: Optional list of specific licenses to report on |
|
|
date_range: Optional (start_date, end_date) tuple |
|
|
|
|
|
Returns: |
|
|
Compliance report with summary and details |
|
|
|
|
|
TODO: Implement actual report generation logic |
|
|
""" |
|
|
logger.info("Generating compliance report") |
|
|
|
|
|
|
|
|
return { |
|
|
"report_id": f"report_{datetime.now().strftime('%Y%m%d_%H%M%S')}", |
|
|
"generated_at": datetime.now().isoformat(), |
|
|
"status": "placeholder", |
|
|
"message": "Compliance report generation not yet implemented", |
|
|
"summary": { |
|
|
"total_licenses": 0, |
|
|
"compliant": 0, |
|
|
"non_compliant": 0, |
|
|
"at_risk": 0, |
|
|
}, |
|
|
"details": [], |
|
|
} |
|
|
|
|
|
async def create_alert( |
|
|
self, |
|
|
license_id: str, |
|
|
alert_type: str, |
|
|
severity: str, |
|
|
message: str, |
|
|
) -> ComplianceAlert: |
|
|
""" |
|
|
Create a compliance alert for TTO staff notification. |
|
|
|
|
|
Args: |
|
|
license_id: License agreement identifier |
|
|
alert_type: Type of alert (payment_overdue, milestone_missed, etc.) |
|
|
severity: Alert severity (low, medium, high, critical) |
|
|
message: Alert message |
|
|
|
|
|
Returns: |
|
|
Created compliance alert |
|
|
|
|
|
TODO: Implement actual alert creation and notification logic |
|
|
""" |
|
|
logger.info(f"Creating {severity} alert for license: {license_id}") |
|
|
|
|
|
alert = ComplianceAlert( |
|
|
alert_id=f"alert_{datetime.now().strftime('%Y%m%d_%H%M%S')}", |
|
|
license_id=license_id, |
|
|
alert_type=alert_type, |
|
|
severity=severity, |
|
|
message=message, |
|
|
created_at=datetime.now(), |
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
return alert |
|
|
|
|
|
def get_vista_quality_criteria(self) -> Dict[str, Any]: |
|
|
""" |
|
|
Get VISTA quality criteria for compliance monitoring. |
|
|
|
|
|
Returns quality thresholds aligned with VISTA project objectives. |
|
|
""" |
|
|
return { |
|
|
"payment_tracking": { |
|
|
"weight": 0.30, |
|
|
"threshold": 0.95, |
|
|
"description": "Payment records must be accurate and complete", |
|
|
}, |
|
|
"milestone_verification": { |
|
|
"weight": 0.25, |
|
|
"threshold": 0.90, |
|
|
"description": "Milestone verification must include evidence", |
|
|
}, |
|
|
"alert_timeliness": { |
|
|
"weight": 0.25, |
|
|
"threshold": 0.95, |
|
|
"description": "Alerts must be generated within 24 hours of trigger", |
|
|
}, |
|
|
"report_accuracy": { |
|
|
"weight": 0.20, |
|
|
"threshold": 0.98, |
|
|
"description": "Reports must accurately reflect current state", |
|
|
}, |
|
|
} |
|
|
|