pub struct ExecutionEngine { /* private fields */ }Expand description
执行引擎
提供 Agent 执行、工作流编排等功能
§示例
ⓘ
use mofa_runtime::agent::execution::{ExecutionEngine, ExecutionOptions};
let registry = AgentRegistry::new();
// ... 注册 Agent ...
let engine = ExecutionEngine::new(registry);
let result = engine.execute(
"my-agent",
AgentInput::text("Hello"),
ExecutionOptions::default(),
).await?;
if result.is_success() {
info!("Output: {:?}", result.output);
}Implementations§
Source§impl ExecutionEngine
impl ExecutionEngine
Sourcepub fn new(registry: Arc<AgentRegistry>) -> Self
pub fn new(registry: Arc<AgentRegistry>) -> Self
创建新的执行引擎
Sourcepub fn with_plugin_registry(
registry: Arc<AgentRegistry>,
plugin_registry: Arc<dyn PluginRegistry>,
) -> Self
pub fn with_plugin_registry( registry: Arc<AgentRegistry>, plugin_registry: Arc<dyn PluginRegistry>, ) -> Self
创建带有自定义插件注册中心的执行引擎
Sourcepub async fn execute(
&self,
agent_id: &str,
input: AgentInput,
options: ExecutionOptions,
) -> AgentResult<ExecutionResult>
pub async fn execute( &self, agent_id: &str, input: AgentInput, options: ExecutionOptions, ) -> AgentResult<ExecutionResult>
执行 Agent
Sourcepub async fn execute_batch(
&self,
executions: Vec<(String, AgentInput)>,
options: ExecutionOptions,
) -> Vec<AgentResult<ExecutionResult>> ⓘ
pub async fn execute_batch( &self, executions: Vec<(String, AgentInput)>, options: ExecutionOptions, ) -> Vec<AgentResult<ExecutionResult>> ⓘ
批量执行
Sourcepub async fn execute_parallel(
&self,
executions: Vec<(String, AgentInput)>,
options: ExecutionOptions,
) -> Vec<AgentResult<ExecutionResult>> ⓘ
pub async fn execute_parallel( &self, executions: Vec<(String, AgentInput)>, options: ExecutionOptions, ) -> Vec<AgentResult<ExecutionResult>> ⓘ
并行执行多个 Agent
Sourcepub async fn interrupt(&self, agent_id: &str) -> AgentResult<()>
pub async fn interrupt(&self, agent_id: &str) -> AgentResult<()>
中断执行
Sourcepub async fn interrupt_all(&self) -> AgentResult<Vec<String>>
pub async fn interrupt_all(&self) -> AgentResult<Vec<String>>
中断所有执行中的 Agent
Sourcepub fn register_plugin(&self, plugin: Arc<dyn Plugin>) -> AgentResult<()>
pub fn register_plugin(&self, plugin: Arc<dyn Plugin>) -> AgentResult<()>
注册插件
Sourcepub fn unregister_plugin(&self, name: &str) -> AgentResult<bool>
pub fn unregister_plugin(&self, name: &str) -> AgentResult<bool>
移除插件
Sourcepub fn list_plugins(&self) -> Vec<Arc<dyn Plugin>>
pub fn list_plugins(&self) -> Vec<Arc<dyn Plugin>>
列出所有插件
Sourcepub fn plugin_count(&self) -> usize
pub fn plugin_count(&self) -> usize
插件数量
Source§impl ExecutionEngine
impl ExecutionEngine
Sourcepub async fn execute_workflow(
&self,
workflow: &Workflow,
initial_input: AgentInput,
options: ExecutionOptions,
) -> AgentResult<HashMap<String, ExecutionResult>>
pub async fn execute_workflow( &self, workflow: &Workflow, initial_input: AgentInput, options: ExecutionOptions, ) -> AgentResult<HashMap<String, ExecutionResult>>
执行工作流
Auto Trait Implementations§
impl Freeze for ExecutionEngine
impl !RefUnwindSafe for ExecutionEngine
impl Send for ExecutionEngine
impl Sync for ExecutionEngine
impl Unpin for ExecutionEngine
impl UnsafeUnpin for ExecutionEngine
impl !UnwindSafe for ExecutionEngine
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