from abc import ABC, abstractmethod
from typing import Dict, Any, Tuple, Callable, Optional

class BaseToolPlugin(ABC):
    """
    Interface for dynamic tools/skills to integrate into the Hub's SubAgent pipeline.
    """
    
    @property
    @abstractmethod
    def name(self) -> str:
        """The exact name of the tool, e.g., 'mesh_terminal_control'"""
        pass
        
    @property
    def retries(self) -> int:
        """Default number of retries for the SubAgent handling this tool."""
        return 2

    @abstractmethod
    def prepare_task(self, args: Dict[str, Any], context: Dict[str, Any]) -> Tuple[Optional[Callable], Dict[str, Any]]:
        """
        Takes tool arguments and the execution context to provide the 
        actual task function and arguments to be run by the SubAgent.
        
        Args:
            args: The kwargs provided by the LLM calling the tool.
            context: System context, generally containing:
                     'db', 'user_id', 'session_id', 'node_id', 'node_ids',
                     'assistant', 'orchestrator', 'services', 'on_event'.
                     
        Returns:
            Tuple containing:
            1. The async task function (or synchronous function if wrapped).
            2. The kwargs dictionary to be passed to the task function.
            If validation fails or access is denied, return (None, {"success": False, "error": "Reason"}).
        """
        pass
