pub struct AgentRunner<T: MoFAAgent> { /* private fields */ }Expand description
统一 Agent 运行器
可以运行任何实现了 MoFAAgent 的 Agent。
Implementations§
Source§impl<T: MoFAAgent> AgentRunner<T>
impl<T: MoFAAgent> AgentRunner<T>
Sourcepub async fn new(agent: T) -> AgentResult<Self>
pub async fn new(agent: T) -> AgentResult<Self>
创建新的运行器
此方法会初始化 Agent。
Sourcepub async fn with_context(agent: T, context: AgentContext) -> AgentResult<Self>
pub async fn with_context(agent: T, context: AgentContext) -> AgentResult<Self>
使用自定义上下文创建运行器
Sourcepub fn context(&self) -> &AgentContext
pub fn context(&self) -> &AgentContext
获取执行上下文
Sourcepub async fn state(&self) -> RunnerState
pub async fn state(&self) -> RunnerState
获取运行器状态
Sourcepub async fn stats(&self) -> RunnerStats
pub async fn stats(&self) -> RunnerStats
获取统计信息
Sourcepub async fn is_running(&self) -> bool
pub async fn is_running(&self) -> bool
检查是否正在运行
Sourcepub async fn execute(&mut self, input: AgentInput) -> AgentResult<AgentOutput>
pub async fn execute(&mut self, input: AgentInput) -> AgentResult<AgentOutput>
Sourcepub async fn execute_batch(
&mut self,
inputs: Vec<AgentInput>,
) -> Vec<AgentResult<AgentOutput>> ⓘ
pub async fn execute_batch( &mut self, inputs: Vec<AgentInput>, ) -> Vec<AgentResult<AgentOutput>> ⓘ
Sourcepub async fn pause(&mut self) -> AgentResult<()>where
T: AgentLifecycle,
pub async fn pause(&mut self) -> AgentResult<()>where
T: AgentLifecycle,
暂停运行器
仅支持实现了 AgentLifecycle 的 Agent。
Sourcepub async fn resume(&mut self) -> AgentResult<()>where
T: AgentLifecycle,
pub async fn resume(&mut self) -> AgentResult<()>where
T: AgentLifecycle,
恢复运行器
仅支持实现了 AgentLifecycle 的 Agent。
Sourcepub async fn shutdown(self) -> AgentResult<()>
pub async fn shutdown(self) -> AgentResult<()>
关闭运行器
优雅关闭,释放资源。
Sourcepub async fn interrupt(&mut self) -> AgentResult<InterruptResult>
pub async fn interrupt(&mut self) -> AgentResult<InterruptResult>
中断当前执行
Sourcepub fn into_inner(self) -> T
pub fn into_inner(self) -> T
消耗运行器,返回内部 Agent
Sourcepub fn capabilities(&self) -> &AgentCapabilities
pub fn capabilities(&self) -> &AgentCapabilities
获取 Agent 能力
Sourcepub fn agent_state(&self) -> AgentState
pub fn agent_state(&self) -> AgentState
获取 Agent 状态
Source§impl<T: MoFAAgent + AgentMessaging> AgentRunner<T>
为支持消息处理的 Agent 提供的扩展方法
impl<T: MoFAAgent + AgentMessaging> AgentRunner<T>
为支持消息处理的 Agent 提供的扩展方法
Sourcepub async fn handle_event(&mut self, event: AgentEvent) -> AgentResult<()>
pub async fn handle_event(&mut self, event: AgentEvent) -> AgentResult<()>
处理单个事件
Sourcepub async fn send_message(
&mut self,
msg: AgentMessage,
) -> AgentResult<AgentMessage>
pub async fn send_message( &mut self, msg: AgentMessage, ) -> AgentResult<AgentMessage>
发送消息给 Agent
Auto Trait Implementations§
impl<T> Freeze for AgentRunner<T>where
T: Freeze,
impl<T> !RefUnwindSafe for AgentRunner<T>
impl<T> Send for AgentRunner<T>
impl<T> Sync for AgentRunner<T>
impl<T> Unpin for AgentRunner<T>where
T: Unpin,
impl<T> UnsafeUnpin for AgentRunner<T>where
T: UnsafeUnpin,
impl<T> !UnwindSafe for AgentRunner<T>
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> 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 more