pub struct AgentContext {
pub execution_id: String,
pub session_id: Option<String>,
/* private fields */
}Expand description
Fields§
§execution_id: String执行 ID (唯一标识本次执行)
session_id: Option<String>会话 ID (用于多轮对话)
Implementations§
Source§impl AgentContext
impl AgentContext
Sourcepub fn with_session(
execution_id: impl Into<String>,
session_id: impl Into<String>,
) -> Self
pub fn with_session( execution_id: impl Into<String>, session_id: impl Into<String>, ) -> Self
创建带会话 ID 的上下文
Sourcepub fn with_config(self, config: ContextConfig) -> Self
pub fn with_config(self, config: ContextConfig) -> Self
设置配置
Sourcepub async fn get<T: DeserializeOwned>(&self, key: &str) -> Option<T>
pub async fn get<T: DeserializeOwned>(&self, key: &str) -> Option<T>
获取值
Sourcepub fn is_interrupted(&self) -> bool
pub fn is_interrupted(&self) -> bool
检查是否被中断
Sourcepub fn trigger_interrupt(&self)
pub fn trigger_interrupt(&self)
触发中断
Sourcepub fn clear_interrupt(&self)
pub fn clear_interrupt(&self)
清除中断状态
Sourcepub fn config(&self) -> &ContextConfig
pub fn config(&self) -> &ContextConfig
获取配置
Sourcepub fn parent(&self) -> Option<&Arc<AgentContext>>
pub fn parent(&self) -> Option<&Arc<AgentContext>>
获取父上下文
Sourcepub async fn emit_event(&self, event: AgentEvent)
pub async fn emit_event(&self, event: AgentEvent)
发送事件
Sourcepub async fn subscribe(&self, event_type: &str) -> EventReceiver
pub async fn subscribe(&self, event_type: &str) -> EventReceiver
订阅事件
Sourcepub async fn find<T: DeserializeOwned>(&self, key: &str) -> Option<T>
pub async fn find<T: DeserializeOwned>(&self, key: &str) -> Option<T>
从父上下文查找值 (递归向上查找)
Trait Implementations§
Source§impl Clone for AgentContext
impl Clone for AgentContext
Source§fn clone(&self) -> AgentContext
fn clone(&self) -> AgentContext
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for AgentContext
impl !RefUnwindSafe for AgentContext
impl Send for AgentContext
impl Sync for AgentContext
impl Unpin for AgentContext
impl UnsafeUnpin for AgentContext
impl !UnwindSafe for AgentContext
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