"""Agent 框架自定义异常"""


class AgentFrameworkError(Exception):
    """Agent 框架基础异常"""

    def __init__(self, message: str = "Agent framework error"):
        self.message = message
        super().__init__(self.message)


class AgentNotFoundError(AgentFrameworkError):
    def __init__(self, agent_name: str):
        self.agent_name = agent_name
        super().__init__(f"Agent not found: {agent_name}")


class AgentAlreadyRegisteredError(AgentFrameworkError):
    def __init__(self, agent_name: str):
        self.agent_name = agent_name
        super().__init__(f"Agent already registered: {agent_name}")


class AgentUnavailableError(AgentFrameworkError):
    def __init__(self, agent_name: str, status: str = "offline"):
        self.agent_name = agent_name
        self.status = status
        super().__init__(f"Agent '{agent_name}' is unavailable (status: {status})")


class TaskNotFoundError(AgentFrameworkError):
    def __init__(self, task_id: str):
        self.task_id = task_id
        super().__init__(f"Task not found: {task_id}")


class TaskDispatchError(AgentFrameworkError):
    def __init__(self, task_id: str, reason: str = ""):
        self.task_id = task_id
        super().__init__(f"Task dispatch failed for {task_id}: {reason}")


class TaskExecutionError(AgentFrameworkError):
    def __init__(self, task_id: str, agent_name: str, reason: str = ""):
        self.task_id = task_id
        self.agent_name = agent_name
        super().__init__(f"Task {task_id} execution failed on agent '{agent_name}': {reason}")


class TaskTimeoutError(AgentFrameworkError):
    def __init__(self, task_id: str, timeout_seconds: int):
        self.task_id = task_id
        self.timeout_seconds = timeout_seconds
        super().__init__(f"Task {task_id} timed out after {timeout_seconds}s")


class TaskCancelledError(AgentFrameworkError):
    def __init__(self, task_id: str):
        self.task_id = task_id
        super().__init__(f"Task {task_id} was cancelled")


class NoAvailableAgentError(AgentFrameworkError):
    def __init__(self, task_type: str):
        self.task_type = task_type
        super().__init__(f"No available agent for task type: {task_type}")


class ConfigValidationError(AgentFrameworkError):
    def __init__(self, agent_name: str, key: str, reason: str = ""):
        self.agent_name = agent_name
        self.key = key
        super().__init__(f"Config validation failed for agent '{agent_name}' key '{key}': {reason}")


class AgentNotReadyError(AgentFrameworkError):
    def __init__(self, agent_name: str):
        self.agent_name = agent_name
        super().__init__(f"Agent '{agent_name}' is not ready")


class SkillNotFoundError(AgentFrameworkError):
    def __init__(self, skill_name: str):
        self.skill_name = skill_name
        super().__init__(f"Skill not found: {skill_name}")


class ToolNotFoundError(AgentFrameworkError):
    def __init__(self, tool_name: str):
        self.tool_name = tool_name
        super().__init__(f"Tool not found: {tool_name}")


class ToolExecutionError(AgentFrameworkError):
    def __init__(self, tool_name: str, reason: str = ""):
        self.tool_name = tool_name
        super().__init__(f"Tool '{tool_name}' execution failed: {reason}")


class SchemaValidationError(AgentFrameworkError):
    def __init__(self, agent_name: str, detail: str = ""):
        self.agent_name = agent_name
        super().__init__(f"Schema validation failed for agent '{agent_name}': {detail}")


class HandoffError(AgentFrameworkError):
    def __init__(self, source: str, target: str, reason: str = ""):
        self.source = source
        self.target = target
        super().__init__(f"Handoff from '{source}' to '{target}' failed: {reason}")


class EvolutionError(AgentFrameworkError):
    def __init__(self, agent_name: str, reason: str = ""):
        self.agent_name = agent_name
        super().__init__(f"Evolution failed for agent '{agent_name}': {reason}")


class LLMError(AgentFrameworkError):
    """LLM 基础异常"""

    def __init__(self, message: str = "LLM error"):
        super().__init__(message)


class LLMProviderError(LLMError):
    """LLM Provider 特定异常"""

    def __init__(self, provider: str, reason: str = ""):
        self.provider = provider
        super().__init__(f"LLM provider '{provider}' error: {reason}")


class ModelNotFoundError(LLMError):
    """模型别名未找到异常"""

    def __init__(self, model: str):
        self.model = model
        super().__init__(f"Model not found: {model}")
