pub trait MiddlewareEvent:
Clone
+ Send
+ 'static {
type Error: Display + Send + Sync + 'static + From<String>;
// Required methods
fn assistant_text(content: String, reasoning: Option<String>) -> Self;
fn tool_call_request(
call_id: Arc<str>,
name: String,
args: JsonValue,
) -> Self;
fn tool_response(
call_id: Arc<str>,
name: String,
result: Result<String, Self::Error>,
) -> Self;
fn turn_start() -> Self;
fn turn_end(finish_reason: Option<String>) -> Self;
fn done() -> Self;
fn into_session_message(self) -> Option<(Role, MsgVariant)>;
}Expand description
ReAct 循环每轮产出的中间件事件。
react_loop 在 process_token_stream 和 handle_turn_finish 后
将聚合结果转换为 MiddlewareEvent,经过 middleware chain 过滤后:
- 发出到上层(
event_tx+ callbacks) - 转换为
FuneraMessage存入 session 历史
由 AgentEvent(funera-orchestrate)实现此 trait。
Required Associated Types§
Required Methods§
Sourcefn assistant_text(content: String, reasoning: Option<String>) -> Self
fn assistant_text(content: String, reasoning: Option<String>) -> Self
Factory:assistant 聚合文本回复。
Sourcefn tool_call_request(call_id: Arc<str>, name: String, args: JsonValue) -> Self
fn tool_call_request(call_id: Arc<str>, name: String, args: JsonValue) -> Self
Factory:单个工具调用请求。
Sourcefn tool_response(
call_id: Arc<str>,
name: String,
result: Result<String, Self::Error>,
) -> Self
fn tool_response( call_id: Arc<str>, name: String, result: Result<String, Self::Error>, ) -> Self
Factory:单个工具执行结果。
Sourcefn turn_start() -> Self
fn turn_start() -> Self
Factory:turn 开始。
Sourcefn into_session_message(self) -> Option<(Role, MsgVariant)>
fn into_session_message(self) -> Option<(Role, MsgVariant)>
转换为 session 历史消息。
返回 Some((role, variant)) 用于构造 FuneraMessage。
不可转换的事件(如 TurnStart、TurnEnd、Done)返回 None。
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".