102 lines
2.9 KiB
Python
102 lines
2.9 KiB
Python
"""Agent 框架自定义异常"""
|
|
|
|
|
|
class AgentFrameworkError(Exception):
|
|
"""Agent 框架基础异常"""
|
|
|
|
def __init__(self, message: str = "Agent framework error"):
|
|
self.message = message
|
|
super().__init__(self.message)
|
|
|
|
|
|
class AgentNotFoundError(AgentFrameworkError):
|
|
"""Agent 未找到"""
|
|
|
|
def __init__(self, agent_name: str):
|
|
self.agent_name = agent_name
|
|
super().__init__(f"Agent not found: {agent_name}")
|
|
|
|
|
|
class AgentAlreadyRegisteredError(AgentFrameworkError):
|
|
"""Agent 已注册"""
|
|
|
|
def __init__(self, agent_name: str):
|
|
self.agent_name = agent_name
|
|
super().__init__(f"Agent already registered: {agent_name}")
|
|
|
|
|
|
class AgentUnavailableError(AgentFrameworkError):
|
|
"""Agent 不可用"""
|
|
|
|
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):
|
|
"""没有可用的 Agent"""
|
|
|
|
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):
|
|
"""Agent 尚未就绪"""
|
|
|
|
def __init__(self, agent_name: str):
|
|
self.agent_name = agent_name
|
|
super().__init__(f"Agent '{agent_name}' is not ready")
|