pub struct FuneraSession { /* private fields */ }Expand description
Session 薄壳——通过 session_tx 与后端 Actor 通信。
所有权始终由 AgentRuntime 持有(通过 spawn_session_actor 创建)。
FuneraSession 仅提供便利方法,不直接持有消息数据。
Implementations§
Source§impl FuneraSession
impl FuneraSession
pub fn new(session_tx: UnboundedSender<SessionCmd>) -> Self
pub fn id(&self) -> Uuid
pub fn session_tx(&self) -> UnboundedSender<SessionCmd>
Sourcepub fn push_message(&self, msg: FuneraMessage)
pub fn push_message(&self, msg: FuneraMessage)
向 session 追加一条消息。
Sourcepub async fn session_context(&self) -> Vec<JsonValue>
pub async fn session_context(&self) -> Vec<JsonValue>
异步获取 session 上下文(JSON 格式)。
Sourcepub async fn get_messages(&self) -> Vec<FuneraMessage>
pub async fn get_messages(&self) -> Vec<FuneraMessage>
异步获取消息列表(不可变引用)。
Sourcepub async fn react_loop<P: ChatProvider, E: MiddlewareEvent>(
&self,
init_msg: FuneraMessage,
config: ReActLoopConfig,
env_state_tx: Sender<EnvStateEvent>,
middleware: Option<Arc<MiddlewareChain<E, ErrorsEnabled>>>,
event_sender: Option<EventSenderFn<E>>,
) -> Result<()>
pub async fn react_loop<P: ChatProvider, E: MiddlewareEvent>( &self, init_msg: FuneraMessage, config: ReActLoopConfig, env_state_tx: Sender<EnvStateEvent>, middleware: Option<Arc<MiddlewareChain<E, ErrorsEnabled>>>, event_sender: Option<EventSenderFn<E>>, ) -> Result<()>
运行 ReAct 循环。
init_msg 会通过 session_tx 推送到 session actor。
通过 session_tx.clone() 传递给 ReActLoop,使其可在循环期间
读写 session 而不移出所有权。
完成后返回 ()。session 数据保留在 actor 中(外部通过 session_context() 查询)。
Auto Trait Implementations§
impl Freeze for FuneraSession
impl RefUnwindSafe for FuneraSession
impl Send for FuneraSession
impl Sync for FuneraSession
impl Unpin for FuneraSession
impl UnsafeUnpin for FuneraSession
impl UnwindSafe for FuneraSession
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more