pub struct AgentExecutor { /* private fields */ }Expand description
Standard LLM-based agent executor
This executor handles the complete agent loop:
- Build context with system prompt, history, and current message
- Call LLM with tool definitions
- Execute tools if called
- Repeat until no more tool calls or max iterations reached
Uses composition with BaseAgent to avoid reimplementing MoFAAgent.
§Architecture
AgentExecutor
├── BaseAgent (provides MoFAAgent implementation)
└── LLM-specific fields (llm, context, tools, sessions, config)§Example
ⓘ
use mofa_foundation::agent::executor::{AgentExecutor, AgentExecutorConfig};
use std::sync::Arc;
let llm = Arc::new(MyLLMProvider::new());
let executor = AgentExecutor::new(llm, "/path/to/workspace").await?;
let response = executor.process_message("session", "Hello").await?;Implementations§
Source§impl AgentExecutor
impl AgentExecutor
Sourcepub async fn new(
llm: Arc<dyn LLMProvider>,
workspace: impl AsRef<Path>,
) -> Result<AgentExecutor, AgentError>
pub async fn new( llm: Arc<dyn LLMProvider>, workspace: impl AsRef<Path>, ) -> Result<AgentExecutor, AgentError>
Create a new agent executor
Sourcepub async fn with_config(
llm: Arc<dyn LLMProvider>,
workspace: impl AsRef<Path>,
config: AgentExecutorConfig,
) -> Result<AgentExecutor, AgentError>
pub async fn with_config( llm: Arc<dyn LLMProvider>, workspace: impl AsRef<Path>, config: AgentExecutorConfig, ) -> Result<AgentExecutor, AgentError>
Create with custom configuration
Sourcepub async fn register_tool(&self, tool: Arc<dyn Tool>) -> Result<(), AgentError>
pub async fn register_tool(&self, tool: Arc<dyn Tool>) -> Result<(), AgentError>
Register a tool
Sourcepub async fn process_message(
&mut self,
session_key: &str,
message: &str,
) -> Result<String, AgentError>
pub async fn process_message( &mut self, session_key: &str, message: &str, ) -> Result<String, AgentError>
Process a user message
Sourcepub fn sessions(&self) -> &Arc<SessionManager>
pub fn sessions(&self) -> &Arc<SessionManager>
Get the session manager
Sourcepub fn tools(&self) -> &Arc<RwLock<SimpleToolRegistry>>
pub fn tools(&self) -> &Arc<RwLock<SimpleToolRegistry>>
Get the tool registry
Sourcepub fn context(&self) -> &Arc<RwLock<PromptContext>>
pub fn context(&self) -> &Arc<RwLock<PromptContext>>
Get the prompt context
Sourcepub fn llm(&self) -> &Arc<dyn LLMProvider>
pub fn llm(&self) -> &Arc<dyn LLMProvider>
Get the LLM provider
Sourcepub fn config(&self) -> &AgentExecutorConfig
pub fn config(&self) -> &AgentExecutorConfig
Get the configuration
Trait Implementations§
Source§impl MoFAAgent for AgentExecutor
impl MoFAAgent for AgentExecutor
Source§fn capabilities(&self) -> &AgentCapabilities
fn capabilities(&self) -> &AgentCapabilities
获取能力描述 Read more
Source§fn state(&self) -> AgentState
fn state(&self) -> AgentState
获取当前状态 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,
AgentExecutor: '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,
AgentExecutor: '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,
AgentExecutor: '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,
AgentExecutor: 'async_trait,
执行任务 - 核心方法 Read more
Auto Trait Implementations§
impl Freeze for AgentExecutor
impl !RefUnwindSafe for AgentExecutor
impl Send for AgentExecutor
impl Sync for AgentExecutor
impl Unpin for AgentExecutor
impl UnsafeUnpin for AgentExecutor
impl !UnwindSafe for AgentExecutor
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