- Introduced `TaskConfig` struct to manage task-related configurations. - Implemented `TaskTool` for creating and managing subagents for complex tasks. - Added `TaskSession` and `TaskRepository` for handling task sessions and persistence. - Created `DefaultSubAgentRuntime` to execute tasks with timeout and history support. - Enhanced `ToolContext` to include `subagent_description` for better context tracking. - Implemented error handling for task execution and session management. - Updated `ToolRegistryFactory` to register task tools conditionally based on configuration. - Added prompt builders for subagent tasks to improve interaction clarity.
48 lines
1.3 KiB
Rust
48 lines
1.3 KiB
Rust
use crate::storage::StorageError;
|
|
|
|
/// 任务错误类型
|
|
#[derive(Debug, thiserror::Error)]
|
|
pub enum TaskError {
|
|
#[error("Task session not found: {0}")]
|
|
SessionNotFound(String),
|
|
|
|
#[error("Invalid parent session")]
|
|
InvalidParentSession,
|
|
|
|
#[error("Failed to create subagent: {0}")]
|
|
AgentCreationFailed(String),
|
|
|
|
#[error("Execution failed: {0}")]
|
|
ExecutionFailed(String),
|
|
|
|
#[error("Task execution timed out")]
|
|
Timeout,
|
|
|
|
#[error("Repository error: {0}")]
|
|
RepositoryError(#[from] StorageError),
|
|
|
|
#[error("Serialization error: {0}")]
|
|
SerializationError(#[from] serde_json::Error),
|
|
|
|
#[error("Missing required context: {0}")]
|
|
MissingContext(String),
|
|
|
|
#[error("Invalid arguments: {0}")]
|
|
InvalidArguments(String),
|
|
}
|
|
|
|
impl TaskError {
|
|
pub fn as_status(&self) -> &'static str {
|
|
match self {
|
|
Self::Timeout => "timeout",
|
|
Self::SessionNotFound(_) => "failed",
|
|
Self::InvalidParentSession => "failed",
|
|
Self::AgentCreationFailed(_) => "failed",
|
|
Self::ExecutionFailed(_) => "failed",
|
|
Self::RepositoryError(_) => "failed",
|
|
Self::SerializationError(_) => "failed",
|
|
Self::MissingContext(_) => "failed",
|
|
Self::InvalidArguments(_) => "failed",
|
|
}
|
|
}
|
|
} |