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 new(execution_id: impl Into<String>) -> AgentContext
pub fn new(execution_id: impl Into<String>) -> AgentContext
创建新的上下文
Sourcepub fn with_session(
execution_id: impl Into<String>,
session_id: impl Into<String>,
) -> AgentContext
pub fn with_session( execution_id: impl Into<String>, session_id: impl Into<String>, ) -> AgentContext
创建带会话 ID 的上下文
Sourcepub fn child(&self, execution_id: impl Into<String>) -> AgentContext
pub fn child(&self, execution_id: impl Into<String>) -> AgentContext
创建子上下文 (用于子任务执行)
Sourcepub fn with_config(self, config: ContextConfig) -> AgentContext
pub fn with_config(self, config: ContextConfig) -> AgentContext
设置配置
Sourcepub async fn get<T>(&self, key: &str) -> Option<T>where
T: DeserializeOwned,
pub async fn get<T>(&self, key: &str) -> Option<T>where
T: DeserializeOwned,
获取值
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) -> Receiver<AgentEvent>
pub async fn subscribe(&self, event_type: &str) -> Receiver<AgentEvent>
订阅事件
Sourcepub async fn find<T>(&self, key: &str) -> Option<T>where
T: DeserializeOwned,
pub async fn find<T>(&self, key: &str) -> Option<T>where
T: DeserializeOwned,
从父上下文查找值 (递归向上查找)
Trait Implementations§
Source§impl AsRef<AgentContext> for RichAgentContext
impl AsRef<AgentContext> for RichAgentContext
Source§fn as_ref(&self) -> &AgentContext
fn as_ref(&self) -> &AgentContext
Converts this type into a shared reference of the (usually inferred) input type.
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 moreSource§impl ContextExt for AgentContext
Implement ContextExt for CoreAgentContext using extension storage
impl ContextExt for AgentContext
Implement ContextExt for CoreAgentContext using extension storage
Source§async fn set_extension<T>(&self, value: T)
async fn set_extension<T>(&self, value: T)
Set extension data
Source§async fn get_extension<T>(&self) -> Option<T>
async fn get_extension<T>(&self) -> Option<T>
Get extension data
Source§async fn remove_extension<T>(&self) -> Option<T>
async fn remove_extension<T>(&self) -> Option<T>
Remove extension data
Source§impl From<AgentContext> for RichAgentContext
impl From<AgentContext> for RichAgentContext
Source§fn from(inner: AgentContext) -> RichAgentContext
fn from(inner: AgentContext) -> RichAgentContext
Converts to this type from the input type.
Source§impl From<RichAgentContext> for AgentContext
impl From<RichAgentContext> for AgentContext
Source§fn from(rich: RichAgentContext) -> AgentContext
fn from(rich: RichAgentContext) -> AgentContext
Converts to this type from the input type.
Auto 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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Message for T
impl<T> Message for T
Source§fn from_boxed(m: BoxedMessage) -> Result<Self, BoxedDowncastErr>
fn from_boxed(m: BoxedMessage) -> Result<Self, BoxedDowncastErr>
Convert a BoxedMessage to this concrete type
Source§fn box_message(self, pid: &ActorId) -> Result<BoxedMessage, BoxedDowncastErr>
fn box_message(self, pid: &ActorId) -> Result<BoxedMessage, BoxedDowncastErr>
Convert this message to a BoxedMessage