use serde::{Deserialize, Serialize};
use serde_json::Value;
use std::collections::HashMap;
#[derive(Debug)]
pub struct Handoff {
pub target_agent: String,
pub task: String,
pub context: Option<HandoffContext>,
}
#[derive(Debug)]
pub struct HandoffContext {
pub original_request: String,
pub current_result: Option<String>,
pub conversation_summary: Option<String>,
pub metadata: HashMap<String, Value>,
}
impl HandoffContext {
pub fn new(original_request: impl Into<String>) -> Self {
Self {
original_request: original_request.into(),
current_result: None,
conversation_summary: None,
metadata: HashMap::new(),
}
}
pub fn with_summary(mut self, summary: impl Into<String>) -> Self {
self.conversation_summary = Some(summary.into());
self
}
pub fn with_result(mut self, result: impl Into<String>) -> Self {
self.current_result = Some(result.into());
self
}
}
pub struct HandoffResult {
pub agent_name: String,
pub result: String,
pub next_handoff: Option<Box<Handoff>>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct HandoffRecord {
pub from_agent: String,
pub to_agent: String,
pub task: String,
pub result: String,
pub timestamp: String,
}
#[derive(Debug)]
pub enum HandoffError {
AgentNotFound(String),
ExecutionError(String),
HandoffCycleDetected(String),
MaxHandoffDepthExceeded(usize),
}
impl std::fmt::Display for HandoffError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
HandoffError::AgentNotFound(name) => {
write!(f, "Agent 不存在: {}", name)
}
HandoffError::ExecutionError(msg) => write!(f, "Agent 执行错误: {}", msg),
HandoffError::HandoffCycleDetected(name) => {
write!(f, "检测到交接环: {} 已在交接链中,拒绝循环交接", name)
}
HandoffError::MaxHandoffDepthExceeded(depth) => {
write!(f, "交接深度超过上限: {}", depth)
}
}
}
}
impl std::error::Error for HandoffError {}