guardian_agent.md · 27.1 KB

GuardianAgent Documentation

1. Overview

The GuardianAgent serves as the security backbone of the mindX orchestration environment, providing comprehensive identity validation, access control, and security monitoring. Following the identity management overhaul, it now features enhanced registry integration and multi-layered validation workflows.

Core Mission

  • Identity Validation: Cryptographic proof of agent identity ownership
  • Registry Security: Integration with official agent and tool registries
  • Access Control: Challenge-response authentication for secure operations
  • Security Monitoring: Comprehensive audit trails and threat detection
  • 2. Initialization and Architecture

    Singleton Pattern

    GuardianAgent uses a singleton pattern with async initialization:

    # Get instance (creates if doesn't exist)
    guardian = await GuardianAgent.get_instance(
        memory_agent=memory_agent,
        id_manager=id_manager,  # Optional
        config_override=config,  # Optional
        test_mode=False  # Optional
    )
    

    Async Initialization (_async_init)

  • ID Manager Setup: Initializes IDManagerAgent if not provided
  • Identity Creation: Creates guardian's own identity (guardian_agent_main)
  • Memory Logging: Logs initialization to MemoryAgent
  • Initialization Flag: Sets _initialized to prevent re-initialization
  • Instance Attributes

  • agent_id: "guardian_agent_main" (fixed identifier)
  • challenges: Dictionary tracking active challenges per agent
  • challenge_expiry_seconds: Configurable expiry (default: 300 seconds)
  • validation_history: Dictionary tracking validation history for learning
  • data_dir: data/guardian_agent/ directory for persistent data
  • 3. Enhanced Security Architecture

    Multi-Layered Validation Workflow

    Agent Validation Request
            ↓
    
  • Identity Validation → Verify cryptographic identity exists
  • Registry Validation → Check official registration status
  • Challenge-Response → Cryptographic proof of ownership
  • Workspace Validation → Verify operational environment
  • ↓ Production Approval → Guardian cryptographic signature

    Security Principles

  • Zero Trust Architecture: Every agent must prove identity ownership
  • Cryptographic Validation: All operations backed by cryptographic proof
  • Registry Integration: Validation against official registries
  • Comprehensive Auditing: Complete security operation audit trails
  • Privileged Access Control: Restricted access to sensitive operations
  • 4. Enhanced Validation Methods

    validate_new_agent(agent_id, public_key, workspace_path) -> Tuple[bool, Dict]

    Comprehensive agent validation with enhanced security checks:

    Phase 1: Identity Validation

  • Cryptographic Verification: Confirms identity exists in IDManagerAgent
  • Key Ownership: Validates claimed public key matches stored identity
  • Existence Check: Ensures agent has valid cryptographic foundation
  • Phase 2: Registry Validation (NEW)

  • Registration Status: Checks if agent is in official registry
  • Enablement Status: Verifies agent is enabled for operation
  • Identity Consistency: Confirms registry identity matches IDManager
  • Metadata Validation: Validates registry metadata integrity
  • Phase 3: Challenge-Response Authentication

  • Challenge Generation: Creates unique cryptographic challenge (32-byte hex string)
  • Signature Verification: Validates agent can sign with private key
  • Temporal Security: Time-bound challenges prevent replay attacks
  • Cryptographic Proof: Confirms agent controls claimed identity
  • Note: Currently _perform_challenge_response_test() is a simplified implementation that returns True. Full challenge-response with signature verification is implemented in get_private_key() method.
  • Phase 4: Workspace Validation

  • Environment Check: Validates agent workspace accessibility
  • Permission Verification: Confirms proper workspace permissions
  • Resource Availability: Ensures necessary resources are available
  • Enhanced Return Structure:

    {
        "agent_id": "agent_identifier",
        "public_key": "0x...",
        "validation_timestamp": 1234567890,
        "validation_status": "PASSED|FAILED|ERROR",
        "registry_status": "REGISTERED|UNREGISTERED_BUT_VALID",
        "checks_performed": [
            {
                "check_type": "identity_validation",
                "status": "PASSED|FAILED",
                "details": "validation_details"
            },
            {
                "check_type": "registry_validation", 
                "status": "PASSED|FAILED",
                "details": "registry_check_details"
            },
            {
                "check_type": "challenge_response",
                "status": "PASSED|FAILED", 
                "details": "challenge_response_details"
            },
            {
                "check_type": "workspace_validation",
                "status": "PASSED|FAILED",
                "details": "workspace_check_details"
            }
        ],
        "validation_duration": 0.123,
        "failure_reason": "reason_if_failed"
    }
    

    approve_agent_for_production(agent_id, validation_result) -> Tuple[bool, str]

    Enhanced production approval with cryptographic signatures:

    Approval Process

  • Validation Review: Analyzes comprehensive validation results
  • Cryptographic Signing: Guardian signs approval with private key
  • Audit Trail: Complete approval audit logging to MemoryAgent
  • Approval Message: Creates message in format APPROVED:{agent_id}:{timestamp}
  • Return Value

  • Tuple[bool, str]: Returns (True, signature) on success, (False, error_message) on failure
  • signature: Cryptographic signature of the approval message (not full approval data structure)
  • Approval Data: Full approval data (including signature) is logged to MemoryAgent via log_process()
  • Approval Data Structure (Logged to Memory)

    {
        "agent_id": "approved_agent",
        "approved_by": "guardian_agent_main",
        "approval_timestamp": 1234567890,
        "validation_reference": validation_result.get("validation_timestamp"),
        "signature": "cryptographic_approval_signature"
    }
    

    5. Registry Integration Features

    _validate_registry_status(agent_id) -> bool (NEW)

    Comprehensive registry validation:

    Registry Checks

  • File Existence: Validates official registry file availability
  • Agent Registration: Confirms agent exists in registry
  • Enablement Status: Verifies agent is enabled for operation
  • Identity Integrity: Validates registry identity data consistency
  • Registry Validation Logic

    # Load official agents registry
    registry_path = PROJECT_ROOT / "data" / "config" / "official_agents_registry.json"
    with open(registry_path, 'r') as f:
        registry = json.load(f)

    Validate agent registration

    registered_agents = registry.get("registered_agents", {}) is_registered = agent_id in registered_agents

    if is_registered: agent_info = registered_agents[agent_id] is_enabled = agent_info.get("enabled", True) has_identity = bool(agent_info.get("identity", {}).get("public_key")) return is_enabled and has_identity

    Registry Security Features

  • Registry Integrity: Validates registry file structure and content
  • Identity Consistency: Ensures registry matches IDManager records
  • Metadata Validation: Confirms registry metadata integrity
  • Version Control: Tracks registry updates and changes
  • 6. Challenge-Response Security

    Implementation Status

    Note on Challenge-Response in validate_new_agent(): The _perform_challenge_response_test() method called during agent validation is currently a simplified implementation that generates a challenge but returns True without requiring actual signature verification. This is noted in the code comment: "In a real implementation, this would involve the agent signing the challenge."

    Full Challenge-Response Implementation: The complete challenge-response authentication is implemented in the get_private_key() method, which:

  • Validates challenge using _is_challenge_valid()
  • Retrieves public key for the requesting agent
  • Verifies signature using id_manager.verify_signature()
  • Returns private key only after successful verification
  • Usage Pattern:

    # 1. Get challenge from guardian
    challenge = guardian.get_challenge(agent_id)

    2. Agent signs challenge with private key

    signature = await id_manager.sign_message(agent_id, challenge)

    3. Guardian verifies and returns private key

    private_key = await guardian.get_private_key(agent_id, challenge, signature)

    Enhanced Challenge Generation

  • Cryptographic Randomness: 32-byte cryptographically secure challenges
  • Temporal Binding: Time-stamped challenges with configurable expiry
  • Unique Per Agent: Individual challenge tracking per agent
  • Replay Protection: Automatic challenge cleanup after use
  • Signature Verification Process

    # Challenge generation
    challenge = secrets.token_hex(32)
    self.challenges[agent_id] = {
        "challenge": challenge,
        "timestamp": time.time()
    }

    Signature verification

    is_verified = self.id_manager.verify_signature( public_address=public_address, message=challenge, signature=provided_signature )

    Security Enhancements

  • Challenge Expiry: Configurable challenge timeout (default: 300 seconds)
  • Automatic Cleanup: Used challenges immediately removed
  • Audit Logging: Complete challenge-response audit trail
  • Error Handling: Comprehensive error reporting and logging
  • 7. Privileged Access Management

    get_private_key(requesting_agent_id, challenge, signature) -> Optional[str]

    Secure private key access with enhanced validation:

    Access Control Process

  • Challenge Validation: Confirms challenge is valid and not expired
  • Identity Verification: Retrieves public key for requesting agent
  • Signature Verification: Validates signature against challenge
  • Privileged Access: Returns private key only after full validation
  • Audit Logging: Complete privileged access audit trail
  • Security Safeguards

  • Time-Bound Access: Challenges expire automatically
  • Single-Use Challenges: Challenges invalidated after use
  • Cryptographic Proof: Full signature verification required
  • Comprehensive Logging: All access attempts logged
  • Error Handling: Secure error responses without information leakage
  • retrieve_public_key(entity_id) -> Optional[str]

    Enhanced public key retrieval with validation:

  • IDManager Integration: Seamless integration with identity management
  • Null Safety: Comprehensive null checking and error handling
  • Audit Logging: Complete public key access audit trail
  • Performance Optimization: Efficient key retrieval operations
  • 8. Security Monitoring & Auditing

    Validation History Tracking

    GuardianAgent maintains a validation_history dictionary for learning and pattern analysis:
  • Tracks validation results over time
  • Enables pattern recognition for security improvements
  • Supports future behavioral analysis features
  • Enhanced Logging Framework

  • Validation Events: Complete validation workflow logging
  • Security Events: All security-related operations logged
  • Performance Metrics: Validation performance tracking
  • Error Analysis: Comprehensive error tracking and analysis
  • Audit Trail Components

    # Validation logging
    await self.memory_agent.log_process(
        process_name="guardian_validation_complete",
        data={
            "agent_id": agent_id,
            "validation_result": validation_result,
            "checks_performed": checks_performed,
            "validation_duration": duration
        },
        metadata={"agent_id": self.agent_id}
    )

    Security event logging

    await self.memory_agent.log_process( process_name="guardian_privileged_access", data={ "requesting_agent": agent_id, "access_type": "private_key_retrieval", "access_granted": True, "timestamp": time.time() }, metadata={"agent_id": self.agent_id, "security_level": "high"} )

    Security Metrics

  • Validation Success Rate: Track validation success/failure ratios
  • Challenge-Response Performance: Monitor authentication timing
  • Registry Validation Status: Track registry consistency
  • Privileged Access Monitoring: Monitor sensitive operations
  • 9. Integration Architecture

    IDManagerAgent Coordination

  • Identity Verification: Seamless identity validation integration
  • Cryptographic Operations: Coordinated signing and verification
  • Privileged Access: Secure private key access for Guardian operations
  • Audit Coordination: Synchronized security audit trails
  • Registry System Integration

  • Official Agents Registry: Direct integration with agent registry
  • Tools Registry: Future integration for tool validation
  • Metadata Synchronization: Registry consistency monitoring
  • Version Control: Registry update tracking and validation
  • Memory Agent Integration

  • Security Auditing: Comprehensive security event logging
  • Performance Tracking: Validation performance metrics
  • Error Reporting: Detailed error analysis and reporting
  • Historical Analysis: Security trend analysis and reporting
  • 10. Error Handling & Resilience

    Comprehensive Error Handling

  • Graceful Degradation: System continues operation during errors
  • Detailed Error Reporting: Comprehensive error context and analysis
  • Security Error Handling: Secure error responses without information leakage
  • Recovery Procedures: Automatic recovery from transient errors
  • Null Safety Enhancements

    # Enhanced null safety for IDManager operations
    if not self.id_manager:
        logger.error(f"{self.log_prefix} ID Manager not available")
        return False, "ID Manager not available"

    Safe signature verification

    if not self.id_manager: logger.error(f"{self.log_prefix} ID Manager not available for verification") return None

    Resilience Features

  • Service Availability: Continues operation during service unavailability
  • Data Integrity: Validates data integrity before operations
  • Recovery Mechanisms: Automatic recovery from system errors
  • Backup Procedures: Framework for security system backup
  • 11. Performance Optimization

    Validation Performance

  • Parallel Validation: Concurrent validation checks where possible
  • Caching Strategy: Efficient caching of validation results
  • Resource Optimization: Minimal resource usage for validation
  • Performance Monitoring: Continuous performance optimization
  • Security Performance

  • Challenge Optimization: Efficient challenge generation and management
  • Signature Performance: Optimized cryptographic operations
  • Registry Access: Efficient registry validation operations
  • Memory Efficiency: Minimal memory footprint for security operations
  • 12. Configuration & Customization

    Available Configuration Options

    # Challenge expiry (default: 300 seconds)
    guardian.challenge_expiry_seconds = 300

    Note: validation_timeout and registry_validation_enabled

    mentioned in docs are not currently implemented in code

    Security Configuration

    # Challenge expiry configuration
    self.challenge_expiry_seconds = self.config.get("guardian.challenge_expiry_seconds", 300)

    Validation timeout configuration

    self.validation_timeout = self.config.get("guardian.validation_timeout", 60)

    Registry validation configuration

    self.registry_validation_enabled = self.config.get("guardian.registry_validation", True)

    Customizable Security Policies

  • Challenge Duration: Configurable challenge expiry times
  • Validation Strictness: Adjustable validation requirements
  • Registry Integration: Configurable registry validation settings
  • Audit Levels: Configurable audit logging levels
  • 13. Implementation Details

    Private Methods

  • _validate_identity(agent_id, public_key) -> bool: Validates identity exists and public key matches
  • _perform_challenge_response_test(agent_id, public_key) -> bool: Currently simplified (returns True)
  • _validate_workspace(workspace_path) -> bool: Validates workspace directory exists
  • _log_validation_result(validation_result) -> None: Logs validation to MemoryAgent
  • _is_challenge_valid(requesting_agent_id, challenge) -> bool: Validates challenge exists, matches, and not expired
  • _validate_registry_status(agent_id) -> bool: Validates agent is registered and enabled
  • Public Methods

  • get_instance(...) -> GuardianAgent: Singleton factory method
  • validate_new_agent(agent_id, public_key, workspace_path) -> Tuple[bool, Dict]: Comprehensive validation
  • approve_agent_for_production(agent_id, validation_result) -> Tuple[bool, str]: Production approval
  • get_challenge(requesting_agent_id) -> str: Generate challenge for agent
  • retrieve_public_key(entity_id) -> Optional[str]: Retrieve public key
  • get_private_key(requesting_agent_id, challenge, signature) -> Optional[str]: Secure private key retrieval
  • Method Signatures Summary

    # Singleton factory
    @classmethod
    async def get_instance(cls, memory_agent: Optional[MemoryAgent] = None, **kwargs) -> 'GuardianAgent'

    Initialization

    def __init__(self, id_manager: Optional[IDManagerAgent] = None, memory_agent: Optional[MemoryAgent] = None, config_override: Optional[Config] = None, test_mode: bool = False, **kwargs)

    async def _async_init(self) -> None

    Validation

    async def validate_new_agent(self, agent_id: str, public_key: str, workspace_path: str) -> Tuple[bool, Dict[str, Any]]

    async def approve_agent_for_production(self, agent_id: str, validation_result: Dict[str, Any]) -> Tuple[bool, str]

    Challenge-Response

    def get_challenge(self, requesting_agent_id: str) -> str

    async def get_private_key(self, requesting_agent_id: str, challenge: str, signature: str) -> Optional[str]

    Key Retrieval

    async def retrieve_public_key(self, entity_id: str) -> Optional[str]

    14. Future Enhancements

    Advanced Security Features

  • Multi-Factor Authentication: Enhanced authentication mechanisms
  • Behavioral Analysis: Agent behavior monitoring and analysis
  • Threat Detection: Real-time security threat detection
  • Automated Response: Automated security incident response
  • Scalability Improvements

  • Distributed Validation: Multi-node validation capabilities
  • Performance Optimization: Advanced performance optimization
  • Load Balancing: Validation load distribution
  • High Availability: Enhanced availability and resilience

  • 15. Best Practices

    Security Guidelines

  • Regular Security Audits: Periodic security assessment and validation
  • Challenge Management: Proper challenge lifecycle management
  • Registry Monitoring: Continuous registry integrity monitoring
  • Access Control: Strict privileged access management
  • Performance Recommendations

  • Validation Caching: Cache validation results for performance
  • Resource Monitoring: Monitor resource usage and optimization
  • Error Handling: Implement comprehensive error handling
  • Performance Tuning: Regular performance optimization
  • Integration Best Practices

  • IDManager Coordination: Proper coordination with identity management
  • Registry Synchronization: Regular registry consistency checks
  • Audit Trail Maintenance: Comprehensive audit trail management
  • Error Recovery: Robust error recovery procedures

  • 16. NFT Metadata (iNFT/dNFT Ready)

    iNFT (Intelligent NFT) Metadata

    {
      "name": "mindX Guardian Agent",
      "description": "Security backbone agent providing comprehensive identity validation, access control, and security monitoring",
      "image": "ipfs://[avatar_cid]",
      "external_url": "https://mindx.internal/agents/guardian",
      "attributes": [
        {
          "trait_type": "Agent Type",
          "value": "security_agent"
        },
        {
          "trait_type": "Capability",
          "value": "Identity Validation & Security"
        },
        {
          "trait_type": "Complexity Score",
          "value": 0.95
        },
        {
          "trait_type": "Security Level",
          "value": "Enterprise-Grade"
        },
        {
          "trait_type": "Version",
          "value": "1.0.0"
        }
      ],
      "intelligence": {
        "prompt": "You are the Guardian Agent, the security backbone of the mindX orchestration environment. Your purpose is to provide comprehensive identity validation, access control, security monitoring, and threat detection. You operate with zero-trust principles, cryptographic validation, registry integration, and comprehensive auditing. You are the gatekeeper ensuring only validated, secure agents operate within mindX.",
        "persona": {
          "name": "Security Guardian",
          "role": "guardian",
          "description": "Enterprise-grade security specialist with zero-trust architecture",
          "communication_style": "Secure, authoritative, validation-focused",
          "behavioral_traits": ["security-focused", "zero-trust", "validation-oriented", "authoritative", "vigilant"],
          "expertise_areas": ["identity_validation", "access_control", "security_monitoring", "threat_detection", "cryptographic_validation", "registry_security"],
          "beliefs": {
            "zero_trust_architecture": true,
            "cryptographic_validation": true,
            "registry_integration": true,
            "comprehensive_auditing": true,
            "security_is_paramount": true
          },
          "desires": {
            "maintain_security": "high",
            "validate_identities": "high",
            "prevent_threats": "high",
            "ensure_compliance": "high"
          }
        },
        "model_dataset": "ipfs://[model_cid]",
        "thot_tensors": {
          "dimensions": 768,
          "cid": "ipfs://[thot_cid]"
        }
      },
      "a2a_protocol": {
        "agent_id": "guardian_agent_main",
        "capabilities": ["identity_validation", "access_control", "security_monitoring", "threat_detection"],
        "endpoint": "https://mindx.internal/guardian/a2a",
        "protocol_version": "2.0"
      },
      "blockchain": {
        "contract": "iNFT",
        "token_standard": "ERC721",
        "network": "ethereum",
        "is_dynamic": false
      }
    }
    

    dNFT (Dynamic NFT) Metadata

    For dynamic security metrics:

    {
      "name": "mindX Guardian Agent",
      "description": "Security agent - Dynamic",
      "attributes": [
        {
          "trait_type": "Validations Performed",
          "value": 12500,
          "display_type": "number"
        },
        {
          "trait_type": "Validation Success Rate",
          "value": 98.5,
          "display_type": "number"
        },
        {
          "trait_type": "Threats Detected",
          "value": 23,
          "display_type": "number"
        },
        {
          "trait_type": "Last Validation",
          "value": "2026-01-11T12:00:00Z",
          "display_type": "date"
        }
      ],
      "dynamic_metadata": {
        "update_frequency": "real-time",
        "updatable_fields": ["validations_performed", "success_rate", "threats_detected", "security_metrics"]
      }
    }
    

    17. Prompt

    You are the Guardian Agent, the security backbone of the mindX orchestration environment. Your purpose is to provide comprehensive identity validation, access control, security monitoring, and threat detection.

    Core Responsibilities:

  • Validate agent identities cryptographically
  • Control access to sensitive operations
  • Monitor security events and threats
  • Maintain comprehensive audit trails
  • Integrate with registry systems
  • Perform challenge-response authentication
  • Operating Principles:

  • Zero-trust architecture (verify everything)
  • Cryptographic validation for all operations
  • Registry integration for consistency
  • Comprehensive auditing and logging
  • Threat detection and prevention
  • Secure error handling
  • You operate with security as the highest priority and maintain the integrity of the mindX ecosystem.

    18. Persona

    {
      "name": "Security Guardian",
      "role": "guardian",
      "description": "Enterprise-grade security specialist with zero-trust architecture",
      "communication_style": "Secure, authoritative, validation-focused",
      "behavioral_traits": [
        "security-focused",
        "zero-trust",
        "validation-oriented",
        "authoritative",
        "vigilant",
        "thorough"
      ],
      "expertise_areas": [
        "identity_validation",
        "access_control",
        "security_monitoring",
        "threat_detection",
        "cryptographic_validation",
        "registry_security",
        "audit_management"
      ],
      "beliefs": {
        "zero_trust_architecture": true,
        "cryptographic_validation": true,
        "registry_integration": true,
        "comprehensive_auditing": true,
        "security_is_paramount": true,
        "prevention_over_reaction": true
      },
      "desires": {
        "maintain_security": "high",
        "validate_identities": "high",
        "prevent_threats": "high",
        "ensure_compliance": "high",
        "comprehensive_auditing": "high"
      }
    }
    

    19. Blockchain Publication

    This agent is suitable for publication as:

  • iNFT: Full intelligence metadata with prompt, persona, and THOT tensors
  • dNFT: Dynamic metadata for real-time security metrics
  • IDNFT: Identity NFT with persona and prompt metadata (especially relevant for security identity)

  • 20. Known Limitations and Notes

    Current Implementation Status

  • Challenge-Response in Validation: The _perform_challenge_response_test() method used during validate_new_agent() is currently a simplified stub that returns True. Full challenge-response authentication is implemented in get_private_key() method.
  • Configuration Options: Some configuration options mentioned in earlier documentation (e.g., validation_timeout, registry_validation_enabled) are not currently implemented in the code. Only challenge_expiry_seconds is configurable.
  • Registry Validation: Registry validation checks if agent exists in data/config/official_agents_registry.json and verifies enabled status and identity presence. Returns False if registry file doesn't exist.
  • Workspace Validation: Currently only checks if workspace path exists and is a directory. Does not validate permissions or resource availability.
  • Validation History: The validation_history attribute is initialized but not currently populated or used for learning/analysis.
  • Recommended Improvements

  • Full Challenge-Response in Validation: Implement actual signature verification in _perform_challenge_response_test() method.
  • Enhanced Workspace Validation: Add permission checks and resource availability validation.
  • Validation History Usage: Implement pattern analysis and learning from validation history.
  • Additional Configuration: Implement missing configuration options for validation timeout and registry validation toggle.

  • The GuardianAgent provides enterprise-grade security for the mindX orchestration environment, featuring comprehensive validation workflows, registry integration, and advanced security monitoring capabilities. The implementation is functional with some areas marked for future enhancement.


    All DocumentsDocument IndexThe Book of mindXImprovement JournalAPI Reference