smartem_backend.agent_data_cleanup#

Data retention and cleanup utilities for agent communication system.

Provides functions to manage data lifecycle for scientific data compliance: - Cleanup old agent connections and stale data - Archive completed sessions with configurable retention policies - Maintain audit trails while managing storage growth - Support regulatory compliance for scientific research data

Members

AgentDataCleanupService

Service for managing agent communication data lifecycle and cleanup.

AgentDataRetentionPolicy

Configuration for agent data retention policies.

main

CLI entry point for agent data cleanup operations.

class smartem_backend.agent_data_cleanup.AgentDataRetentionPolicy(connection_cleanup_hours: int = 24, instruction_retention_days: int = 30, completed_session_retention_days: int = 90, acknowledgement_retention_days: int = 365, batch_size: int = 1000)[source]#

Configuration for agent data retention policies.

Initialize retention policy configuration.

Parameters:
  • connection_cleanup_hours – Hours to keep stale connections before cleanup

  • instruction_retention_days – Days to retain instruction history

  • completed_session_retention_days – Days to retain completed session data

  • acknowledgement_retention_days – Days to retain acknowledgement audit trail

  • batch_size – Number of records to process in each cleanup batch

classmethod scientific_compliance() AgentDataRetentionPolicy[source]#

Return a conservative retention policy suitable for scientific research compliance.

Scientific research often requires longer retention periods for reproducibility and audit requirements.

classmethod development() AgentDataRetentionPolicy[source]#

Return a shorter retention policy suitable for development environments.

class smartem_backend.agent_data_cleanup.AgentDataCleanupService(session: Session, policy: AgentDataRetentionPolicy | None = None)[source]#

Service for managing agent communication data lifecycle and cleanup.

Initialize cleanup service.

Parameters:
  • session – Database session for cleanup operations

  • policy – Retention policy configuration (defaults to scientific compliance)

cleanup_stale_connections() dict[str, int][source]#

Clean up stale agent connections that haven’t had heartbeats recently.

Returns:

Dictionary with cleanup statistics

cleanup_old_instructions() dict[str, int][source]#

Clean up old instruction records beyond retention period.

Maintains acknowledgement audit trail while removing instruction payload data.

cleanup_completed_sessions() dict[str, int][source]#

Clean up old completed sessions beyond retention period.

Maintains session metadata but removes detailed experimental parameters.

cleanup_old_acknowledgements() dict[str, int][source]#

Clean up very old acknowledgement records beyond regulatory retention period.

This should be used carefully as it affects audit trail completeness.

run_full_cleanup() dict[str, any][source]#

Run complete cleanup process across all agent communication data.

Returns:

Dictionary with comprehensive cleanup statistics

get_data_usage_statistics() dict[str, any][source]#

Get current data usage statistics for agent communication tables.

Returns:

Dictionary with storage and record count statistics

smartem_backend.agent_data_cleanup.main()[source]#

CLI entry point for agent data cleanup operations.