1
This commit is contained in:
40
server-rs/crates/platform-agent/src/error.rs
Normal file
40
server-rs/crates/platform-agent/src/error.rs
Normal file
@@ -0,0 +1,40 @@
|
||||
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<platform_llm::LlmError> for PlatformAgentError {
|
||||
fn from(error: platform_llm::LlmError) -> Self {
|
||||
Self::Llm(error.to_string())
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user