mofa_kernel/agent/traits.rs
1//! Agent 辅助类型定义
2//!
3//! 提供元数据、统计信息等辅助类型
4
5use super::core::MoFAAgent;
6use super::types::AgentState;
7use std::sync::Arc;
8use tokio::sync::RwLock;
9
10/// 动态分发的 MoFAAgent
11///
12/// # 注意
13///
14/// 之前称为 `DynAgent` 基于 `AgentCore`,现在基于统一的 `MoFAAgent`。
15pub type DynAgent = Arc<RwLock<dyn MoFAAgent>>;
16
17// ============================================================================
18// 辅助类型
19// ============================================================================
20
21/// Agent 健康状态
22#[derive(Debug, Clone, PartialEq, Eq, Default)]
23pub enum HealthStatus {
24 /// 健康
25 #[default]
26 Healthy,
27 /// 降级 (部分功能不可用)
28 Degraded(String),
29 /// 不健康
30 Unhealthy(String),
31}
32
33/// Agent 统计信息
34#[derive(Debug, Clone, Default)]
35pub struct AgentStats {
36 /// 总执行次数
37 pub total_executions: u64,
38 /// 成功次数
39 pub successful_executions: u64,
40 /// 失败次数
41 pub failed_executions: u64,
42 /// 平均执行时间 (毫秒)
43 pub avg_execution_time_ms: f64,
44 /// 总 Token 使用
45 pub total_tokens_used: u64,
46 /// 总工具调用次数
47 pub total_tool_calls: u64,
48}
49
50// ============================================================================
51// Agent 元数据
52// ============================================================================
53
54/// Agent 元数据
55#[derive(Debug, Clone)]
56pub struct AgentMetadata {
57 /// Agent ID
58 pub id: String,
59 /// Agent 名称
60 pub name: String,
61 /// Agent 描述
62 pub description: Option<String>,
63 /// Agent 版本
64 pub version: Option<String>,
65 /// Agent 能力
66 pub capabilities: crate::agent::capabilities::AgentCapabilities,
67 /// Agent 状态
68 pub state: AgentState,
69}
70
71impl AgentMetadata {
72 /// 从 MoFAAgent 创建元数据
73 pub fn from_agent(agent: &dyn MoFAAgent) -> Self {
74 Self {
75 id: agent.id().to_string(),
76 name: agent.name().to_string(),
77 description: None,
78 version: None,
79 capabilities: agent.capabilities().clone(),
80 state: agent.state(),
81 }
82 }
83}
84
85// ============================================================================
86// Note: BaseAgent implementation has been moved to mofa-foundation/src/agent/base.rs
87// This file now only contains trait definitions and helper types
88// Kernel tests use inline mock implementations instead of BaseAgent
89// ============================================================================