pub struct BaseAgent {
pub id: String,
pub name: String,
pub description: Option<String>,
pub version: Option<String>,
pub capabilities: AgentCapabilities,
pub state: AgentState,
/* private fields */
}Expand description
基础 Agent 实现
提供 Agent 的基础功能,可以被继承或组合
Fields§
§id: StringAgent ID
name: StringAgent 名称
description: Option<String>Agent 描述
version: Option<String>Agent 版本
capabilities: AgentCapabilitiesAgent 能力
state: AgentState当前状态
Implementations§
Source§impl BaseAgent
impl BaseAgent
Sourcepub fn with_description(self, description: impl Into<String>) -> BaseAgent
pub fn with_description(self, description: impl Into<String>) -> BaseAgent
设置描述
Sourcepub fn with_version(self, version: impl Into<String>) -> BaseAgent
pub fn with_version(self, version: impl Into<String>) -> BaseAgent
设置版本
Sourcepub fn with_capabilities(self, capabilities: AgentCapabilities) -> BaseAgent
pub fn with_capabilities(self, capabilities: AgentCapabilities) -> BaseAgent
设置能力
Sourcepub fn transition_to(&mut self, new_state: AgentState) -> Result<(), AgentError>
pub fn transition_to(&mut self, new_state: AgentState) -> Result<(), AgentError>
转换状态
Sourcepub fn record_success(&mut self, duration_ms: u64, tokens: u64, tool_calls: u64)
pub fn record_success(&mut self, duration_ms: u64, tokens: u64, tool_calls: u64)
记录成功执行
Sourcepub fn record_failure(&mut self)
pub fn record_failure(&mut self)
记录失败执行
Sourcepub fn stats(&self) -> &AgentStats
pub fn stats(&self) -> &AgentStats
获取统计信息
Sourcepub fn capabilities(&self) -> &AgentCapabilities
pub fn capabilities(&self) -> &AgentCapabilities
获取能力
Sourcepub fn state(&self) -> AgentState
pub fn state(&self) -> AgentState
获取状态
Sourcepub async fn initialize(
&mut self,
_ctx: &AgentContext,
) -> Result<(), AgentError>
pub async fn initialize( &mut self, _ctx: &AgentContext, ) -> Result<(), AgentError>
初始化
Sourcepub async fn interrupt(&mut self) -> Result<InterruptResult, AgentError>
pub async fn interrupt(&mut self) -> Result<InterruptResult, AgentError>
中断
Sourcepub async fn shutdown(&mut self) -> Result<(), AgentError>
pub async fn shutdown(&mut self) -> Result<(), AgentError>
关闭
Trait Implementations§
Source§impl MoFAAgent for BaseAgent
impl MoFAAgent for BaseAgent
Source§fn capabilities(&self) -> &AgentCapabilities
fn capabilities(&self) -> &AgentCapabilities
获取能力描述 Read more
Source§fn initialize<'life0, 'life1, 'async_trait>(
&'life0 mut self,
_ctx: &'life1 AgentContext,
) -> Pin<Box<dyn Future<Output = Result<(), AgentError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
BaseAgent: 'async_trait,
fn initialize<'life0, 'life1, 'async_trait>(
&'life0 mut self,
_ctx: &'life1 AgentContext,
) -> Pin<Box<dyn Future<Output = Result<(), AgentError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
BaseAgent: 'async_trait,
初始化 Agent Read more
Source§fn execute<'life0, 'life1, 'async_trait>(
&'life0 mut self,
_input: AgentInput,
_ctx: &'life1 AgentContext,
) -> Pin<Box<dyn Future<Output = Result<AgentOutput, AgentError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
BaseAgent: 'async_trait,
fn execute<'life0, 'life1, 'async_trait>(
&'life0 mut self,
_input: AgentInput,
_ctx: &'life1 AgentContext,
) -> Pin<Box<dyn Future<Output = Result<AgentOutput, AgentError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
BaseAgent: 'async_trait,
执行任务 - 核心方法 Read more
Source§fn shutdown<'life0, 'async_trait>(
&'life0 mut self,
) -> Pin<Box<dyn Future<Output = Result<(), AgentError>> + Send + 'async_trait>>where
'life0: 'async_trait,
BaseAgent: 'async_trait,
fn shutdown<'life0, 'async_trait>(
&'life0 mut self,
) -> Pin<Box<dyn Future<Output = Result<(), AgentError>> + Send + 'async_trait>>where
'life0: 'async_trait,
BaseAgent: 'async_trait,
关闭 Agent Read more
Source§fn state(&self) -> AgentState
fn state(&self) -> AgentState
获取当前状态 Read more
Auto Trait Implementations§
impl Freeze for BaseAgent
impl RefUnwindSafe for BaseAgent
impl Send for BaseAgent
impl Sync for BaseAgent
impl Unpin for BaseAgent
impl UnsafeUnpin for BaseAgent
impl UnwindSafe for BaseAgent
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 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