Skip to main content

MiddlewareEvent

Trait MiddlewareEvent 

Source
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_loopprocess_token_streamhandle_turn_finish 后 将聚合结果转换为 MiddlewareEvent,经过 middleware chain 过滤后:

  • 发出到上层(event_tx + callbacks)
  • 转换为 FuneraMessage 存入 session 历史

AgentEventfunera-orchestrate)实现此 trait。

Required Associated Types§

Source

type Error: Display + Send + Sync + 'static + From<String>

工具错误类型。

Required Methods§

Source

fn assistant_text(content: String, reasoning: Option<String>) -> Self

Factory:assistant 聚合文本回复。

Source

fn tool_call_request(call_id: Arc<str>, name: String, args: JsonValue) -> Self

Factory:单个工具调用请求。

Source

fn tool_response( call_id: Arc<str>, name: String, result: Result<String, Self::Error>, ) -> Self

Factory:单个工具执行结果。

Source

fn turn_start() -> Self

Factory:turn 开始。

Source

fn turn_end(finish_reason: Option<String>) -> Self

Factory:turn 结束,携带 finish_reason。

Source

fn done() -> Self

Factory:会话结束。

Source

fn into_session_message(self) -> Option<(Role, MsgVariant)>

转换为 session 历史消息。

返回 Some((role, variant)) 用于构造 FuneraMessage。 不可转换的事件(如 TurnStartTurnEndDone)返回 None

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§