1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
//! 统一 Agent 框架
//!
//! 提供模块化、可组合、可扩展的 Agent 架构
//!
//! # 架构概述
//!
//! ```text
//! ┌─────────────────────────────────────────────────────────────────────┐
//! │ 统一 Agent 框架 │
//! ├─────────────────────────────────────────────────────────────────────┤
//! │ ┌─────────────────────────────────────────────────────────────┐ │
//! │ │ MoFAAgent Trait │ │
//! │ │ (统一 Agent 接口:id, capabilities, execute, interrupt) │ │
//! │ └───────────────────────────┬─────────────────────────────────┘ │
//! │ │ │
//! │ ┌───────────────────────────┼───────────────────────────────────┐ │
//! │ │ Modular Components (组件化设计) │ │
//! │ │ ┌──────────┐ ┌──────────┐ ┌────────┐ ┌──────────────┐ │ │
//! │ │ │ Reasoner │ │ Tool │ │ Memory │ │ Coordinator │ │ │
//! │ │ │ 推理器 │ │ 工具 │ │ 记忆 │ │ 协调器 │ │ │
//! │ │ └──────────┘ └──────────┘ └────────┘ └──────────────┘ │ │
//! │ └───────────────────────────────────────────────────────────────┘ │
//! │ │
//! │ ┌─────────────────────────────────────────────────────────────┐ │
//! │ │ AgentRegistry (runtime 注册中心实现) │ │
//! │ └─────────────────────────────────────────────────────────────┘ │
//! │ │
//! │ ┌─────────────────────────────────────────────────────────────┐ │
//! │ │ CoreAgentContext (统一上下文) │ │
//! │ └─────────────────────────────────────────────────────────────┘ │
//! └─────────────────────────────────────────────────────────────────────┘
//! ```
//!
//! # 核心概念
//!
//! ## MoFAAgent Trait
//!
//! 所有 Agent 实现的统一接口:
//!
//! ```rust,ignore
//! use mofa_kernel::agent::prelude::*;
//!
//! #[async_trait]
//! impl MoFAAgent for MyAgent {
//! fn id(&self) -> &str { "my-agent" }
//! fn name(&self) -> &str { "My Agent" }
//! fn capabilities(&self) -> &AgentCapabilities { &self.caps }
//!
//! async fn initialize(&mut self, ctx: &CoreAgentContext) -> AgentResult<()> {
//! Ok(())
//! }
//!
//! async fn execute(&mut self, input: AgentInput, ctx: &CoreAgentContext) -> AgentResult<AgentOutput> {
//! Ok(AgentOutput::text("Hello!"))
//! }
//!
//! async fn interrupt(&mut self) -> AgentResult<InterruptResult> {
//! Ok(InterruptResult::Acknowledged)
//! }
//!
//! async fn shutdown(&mut self) -> AgentResult<()> {
//! Ok(())
//! }
//!
//! fn state(&self) -> AgentState {
//! AgentState::Ready
//! }
//! }
//! ```
//!
//! ## AgentCapabilities
//!
//! 描述 Agent 的能力,用于发现和路由:
//!
//! ```rust,ignore
//! let caps = AgentCapabilities::builder()
//! .tag("llm")
//! .tag("coding")
//! .input_type(InputType::Text)
//! .output_type(OutputType::Text)
//! .supports_streaming(true)
//! .supports_tools(true)
//! .build();
//! ```
//!
//! ## CoreAgentContext
//!
//! 执行上下文,在 Agent 执行过程中传递状态:
//!
//! ```rust,ignore
//! let ctx = CoreAgentContext::new("execution-123");
//! ctx.set("user_id", "user-456").await;
//! ctx.emit_event(AgentEvent::new("task_started", json!({}))).await;
//! ```
//!
//! # 模块结构
//!
//! - `core` - AgentCore 微内核接口(最小化核心)
//! - `traits` - MoFAAgent trait 定义
//! - `types` - AgentInput, AgentOutput, AgentState 等类型
//! - `capabilities` - AgentCapabilities 能力描述
//! - `context` - CoreAgentContext 执行上下文
//! - `error` - 错误类型定义
//! - `components` - 组件 trait (Reasoner, Tool, Memory, Coordinator)
//! - `config` - 配置系统
//! - `registry` - Agent 注册中心
//! - `tools` - 统一工具系统
// 核心模块
// 组件模块
// 配置模块
// 注册中心
// 工具系统
// 执行引擎与运行器已迁移到 mofa-runtime
// 秘书Agent抽象
// AgentPlugin 统一到 plugin 模块
pub use crateAgentPlugin;
// 重新导出核心类型
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use execution as execution_events;
// Event type constants are available via types::event::lifecycle, types::event::execution, etc.
// Note: Aliased to avoid conflict with existing modules (plugins, etc.)
pub use lifecycle;
pub use message as message_events;
pub use plugin as plugin_events;
pub use state as state_events;
pub use ;
// 重新导出组件
pub use ;
// 重新导出工厂接口
pub use AgentFactory;
// 重新导出配置
pub use ;
pub use ;
/// Prelude 模块 - 常用类型导入