use std::{error::Error, fmt}; #[derive(Debug, PartialEq, Eq)] pub enum PlatformAgentError { InvalidInput(String), ToolNotFound(String), ToolExecution(String), ToolBudgetExceeded { max_tool_calls: usize }, Timeout { timeout_ms: u64 }, Llm(String), LangChain(String), OutputParse(String), } impl fmt::Display for PlatformAgentError { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { Self::InvalidInput(message) | Self::ToolExecution(message) | Self::Llm(message) | Self::LangChain(message) | Self::OutputParse(message) => write!(f, "{message}"), Self::ToolNotFound(name) => write!(f, "Agent 工具未注册:{name}"), Self::ToolBudgetExceeded { max_tool_calls } => { write!(f, "Agent 工具调用次数超过限制:{max_tool_calls}") } Self::Timeout { timeout_ms } => { write!(f, "Agent 执行超时:{timeout_ms}ms") } } } } impl Error for PlatformAgentError {} impl From for PlatformAgentError { fn from(error: platform_llm::LlmError) -> Self { Self::Llm(error.to_string()) } }