pub struct AgentRuntime { /* private fields */ }Expand description
默认 Agent Runtime 实现
使用 ConcurrentSessionManager 管理会话,ToolRegistry 执行工具。 支持完整的执行生命周期:start -> run/pause/resume/stop。 集成 TaskDecomposer 进行任务分解,ExecutionMonitor 进行执行监控和纠错。 支持真实 LLM API 调用(通过 Layer1 LlmClient)。
Implementations§
Source§impl AgentRuntime
impl AgentRuntime
Sourcepub fn new(
session_manager: Arc<ConcurrentSessionManager>,
tool_registry: Arc<ToolRegistry>,
) -> AgentRuntime
pub fn new( session_manager: Arc<ConcurrentSessionManager>, tool_registry: Arc<ToolRegistry>, ) -> AgentRuntime
创建新的 AgentRuntime
Sourcepub fn with_permissions(
session_manager: Arc<ConcurrentSessionManager>,
tool_registry: Arc<ToolRegistry>,
permission_manager: Arc<PermissionManager>,
) -> AgentRuntime
pub fn with_permissions( session_manager: Arc<ConcurrentSessionManager>, tool_registry: Arc<ToolRegistry>, permission_manager: Arc<PermissionManager>, ) -> AgentRuntime
创建带权限管理的 AgentRuntime
Sourcepub fn with_decomposer(
session_manager: Arc<ConcurrentSessionManager>,
tool_registry: Arc<ToolRegistry>,
strategy: DecompositionStrategy,
) -> AgentRuntime
pub fn with_decomposer( session_manager: Arc<ConcurrentSessionManager>, tool_registry: Arc<ToolRegistry>, strategy: DecompositionStrategy, ) -> AgentRuntime
创建带任务分解器的 AgentRuntime
Sourcepub fn with_defaults() -> AgentRuntime
pub fn with_defaults() -> AgentRuntime
使用默认组件创建(带任务分解器)
Sourcepub fn with_llm_client(
session_manager: Arc<ConcurrentSessionManager>,
tool_registry: Arc<ToolRegistry>,
llm_client: Arc<LlmClient>,
) -> AgentRuntime
pub fn with_llm_client( session_manager: Arc<ConcurrentSessionManager>, tool_registry: Arc<ToolRegistry>, llm_client: Arc<LlmClient>, ) -> AgentRuntime
创建带 LLM 客户端的 AgentRuntime
Sourcepub fn set_permission_manager(&mut self, manager: Arc<PermissionManager>)
pub fn set_permission_manager(&mut self, manager: Arc<PermissionManager>)
设置权限管理器
Sourcepub fn set_decomposition_strategy(&mut self, strategy: DecompositionStrategy)
pub fn set_decomposition_strategy(&mut self, strategy: DecompositionStrategy)
设置任务分解策略
Sourcepub fn set_llm_client(&mut self, client: Arc<LlmClient>)
pub fn set_llm_client(&mut self, client: Arc<LlmClient>)
设置 LLM 客户端
Sourcepub fn permission_manager(&self) -> Option<&Arc<PermissionManager>>
pub fn permission_manager(&self) -> Option<&Arc<PermissionManager>>
获取权限管理器引用
Sourcepub fn task_decomposer(&self) -> Option<&TaskDecomposer>
pub fn task_decomposer(&self) -> Option<&TaskDecomposer>
获取任务分解器引用
Sourcepub fn llm_client(&self) -> Option<&Arc<LlmClient>>
pub fn llm_client(&self) -> Option<&Arc<LlmClient>>
获取 LLM 客户端引用
Sourcepub fn decompose_task(&self, task: &str) -> Result<Option<ExecutionPlan>, Error>
pub fn decompose_task(&self, task: &str) -> Result<Option<ExecutionPlan>, Error>
分解任务为执行计划
如果配置了任务分解器,将复杂任务分解为子任务序列。 返回执行计划,包含子任务列表和执行顺序。
Sourcepub fn create_monitor(&self, plan: ExecutionPlan) -> ExecutionMonitor
pub fn create_monitor(&self, plan: ExecutionPlan) -> ExecutionMonitor
创建执行监控器
为给定的执行计划创建监控器,用于跟踪执行进度和处理错误。
Sourcepub async fn run_with_plan(
&self,
task: &str,
config: AgentConfig,
) -> Result<AgentResult, Error>
pub async fn run_with_plan( &self, task: &str, config: AgentConfig, ) -> Result<AgentResult, Error>
使用执行计划运行 Agent
先分解任务,然后按照执行计划的顺序依次执行子任务。 使用执行监控器跟踪进度和错误。
Sourcepub fn session_manager(&self) -> &Arc<ConcurrentSessionManager>
pub fn session_manager(&self) -> &Arc<ConcurrentSessionManager>
获取会话管理器引用
Sourcepub fn tool_registry(&self) -> &Arc<ToolRegistry>
pub fn tool_registry(&self) -> &Arc<ToolRegistry>
获取工具注册表引用
Trait Implementations§
Source§impl AgentRuntimeTrait for AgentRuntime
impl AgentRuntimeTrait for AgentRuntime
Source§fn run<'life0, 'life1, 'async_trait>(
&'life0 self,
task: &'life1 str,
config: AgentConfig,
) -> Pin<Box<dyn Future<Output = Result<AgentResult, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
AgentRuntime: 'async_trait,
fn run<'life0, 'life1, 'async_trait>(
&'life0 self,
task: &'life1 str,
config: AgentConfig,
) -> Pin<Box<dyn Future<Output = Result<AgentResult, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
AgentRuntime: 'async_trait,
运行 Agent 执行完整循环,直到完成或出错。
这是同步(阻塞式)的执行方式:创建会话、运行循环、返回结果。
Source§fn run_stream<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
task: &'life1 str,
config: AgentConfig,
callback: &'life2 dyn AgentLoopCallback,
) -> Pin<Box<dyn Future<Output = Result<AgentResult, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
AgentRuntime: 'async_trait,
fn run_stream<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
task: &'life1 str,
config: AgentConfig,
callback: &'life2 dyn AgentLoopCallback,
) -> Pin<Box<dyn Future<Output = Result<AgentResult, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
AgentRuntime: 'async_trait,
流式运行 Agent 执行完整循环,通过回调通知每次迭代。
与 run() 类似,但在每次迭代前后通过回调通知外部调用者。
Source§fn run_stream_abortable<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
task: &'life1 str,
config: AgentConfig,
callback: &'life2 dyn AgentLoopCallback,
abort_flag: Arc<Atomic<bool>>,
) -> Pin<Box<dyn Future<Output = Result<AgentResult, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
AgentRuntime: 'async_trait,
fn run_stream_abortable<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
task: &'life1 str,
config: AgentConfig,
callback: &'life2 dyn AgentLoopCallback,
abort_flag: Arc<Atomic<bool>>,
) -> Pin<Box<dyn Future<Output = Result<AgentResult, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
AgentRuntime: 'async_trait,
流式运行 Agent(支持中断)。
与 run_stream 类似,但支持通过 abort_flag 中断执行。
Source§fn start<'life0, 'life1, 'async_trait>(
&'life0 self,
task: &'life1 str,
config: AgentConfig,
) -> Pin<Box<dyn Future<Output = Result<SessionId, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
AgentRuntime: 'async_trait,
fn start<'life0, 'life1, 'async_trait>(
&'life0 self,
task: &'life1 str,
config: AgentConfig,
) -> Pin<Box<dyn Future<Output = Result<SessionId, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
AgentRuntime: 'async_trait,
启动 Agent 并返回会话 ID(用于异步/流式执行)。
创建会话,设置为 Running 状态,但不执行循环。 调用者可以通过 send_message / submit_tool_result 与 Agent 交互。
Source§fn pause<'life0, 'life1, 'async_trait>(
&'life0 self,
session_id: &'life1 SessionId,
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
AgentRuntime: 'async_trait,
fn pause<'life0, 'life1, 'async_trait>(
&'life0 self,
session_id: &'life1 SessionId,
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
AgentRuntime: 'async_trait,
暂停正在执行的 Agent。
将状态从 Running/ToolCalling/WaitingTool 转换为 Stopped(暂停)。 在暂停状态下,Agent 不会继续执行迭代。
Source§fn resume<'life0, 'life1, 'async_trait>(
&'life0 self,
session_id: &'life1 SessionId,
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
AgentRuntime: 'async_trait,
fn resume<'life0, 'life1, 'async_trait>(
&'life0 self,
session_id: &'life1 SessionId,
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
AgentRuntime: 'async_trait,
恢复暂停的 Agent。
将状态从 Stopped 转换回 Running。
Source§fn stop<'life0, 'life1, 'async_trait>(
&'life0 self,
session_id: &'life1 SessionId,
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
AgentRuntime: 'async_trait,
fn stop<'life0, 'life1, 'async_trait>(
&'life0 self,
session_id: &'life1 SessionId,
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
AgentRuntime: 'async_trait,
停止 Agent 执行。
无论当前处于什么状态(除了 Completed/Idle),都转换到 Stopped。 这与 pause 的区别在于 stop 是终止性的,表示用户主动取消。
Source§fn send_message<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
session_id: &'life1 SessionId,
message: &'life2 str,
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
AgentRuntime: 'async_trait,
fn send_message<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
session_id: &'life1 SessionId,
message: &'life2 str,
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
AgentRuntime: 'async_trait,
向 Agent 发送消息。
将消息添加到会话的消息历史中。Agent 在下一次迭代时可以读取。
Source§fn submit_tool_result<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
session_id: &'life1 SessionId,
tool_call_id: &'life2 str,
result: ToolResult,
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
AgentRuntime: 'async_trait,
fn submit_tool_result<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
session_id: &'life1 SessionId,
tool_call_id: &'life2 str,
result: ToolResult,
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
AgentRuntime: 'async_trait,
提交工具调用结果。
当 Agent 处于 WaitingTool 状态时,外部系统可以通过此方法 提交工具执行的结果,使 Agent 能够继续执行。
Source§impl Default for AgentRuntime
impl Default for AgentRuntime
Source§fn default() -> AgentRuntime
fn default() -> AgentRuntime
Auto Trait Implementations§
impl !RefUnwindSafe for AgentRuntime
impl !UnwindSafe for AgentRuntime
impl Freeze for AgentRuntime
impl Send for AgentRuntime
impl Sync for AgentRuntime
impl Unpin for AgentRuntime
impl UnsafeUnpin for AgentRuntime
Blanket Implementations§
Source§impl<T> AlignerFor<1> for T
impl<T> AlignerFor<1> for T
Source§impl<T> AlignerFor<2> for T
impl<T> AlignerFor<2> for T
Source§impl<T> AlignerFor<4> for T
impl<T> AlignerFor<4> for T
Source§impl<T> AlignerFor<8> for T
impl<T> AlignerFor<8> for T
Source§impl<T> AlignerFor<16> for T
impl<T> AlignerFor<16> for T
Source§impl<T> AlignerFor<32> for T
impl<T> AlignerFor<32> for T
Source§impl<T> AlignerFor<64> for T
impl<T> AlignerFor<64> for T
Source§impl<T> AlignerFor<128> for T
impl<T> AlignerFor<128> for T
Source§type Aligner = AlignTo128<T>
type Aligner = AlignTo128<T>
AlignTo* type which aligns Self to ALIGNMENT.Source§impl<T> AlignerFor<256> for T
impl<T> AlignerFor<256> for T
Source§type Aligner = AlignTo256<T>
type Aligner = AlignTo256<T>
AlignTo* type which aligns Self to ALIGNMENT.Source§impl<T> AlignerFor<512> for T
impl<T> AlignerFor<512> for T
Source§type Aligner = AlignTo512<T>
type Aligner = AlignTo512<T>
AlignTo* type which aligns Self to ALIGNMENT.Source§impl<T> AlignerFor<1024> for T
impl<T> AlignerFor<1024> for T
Source§type Aligner = AlignTo1024<T>
type Aligner = AlignTo1024<T>
AlignTo* type which aligns Self to ALIGNMENT.Source§impl<T> AlignerFor<2048> for T
impl<T> AlignerFor<2048> for T
Source§type Aligner = AlignTo2048<T>
type Aligner = AlignTo2048<T>
AlignTo* type which aligns Self to ALIGNMENT.Source§impl<T> AlignerFor<4096> for T
impl<T> AlignerFor<4096> for T
Source§type Aligner = AlignTo4096<T>
type Aligner = AlignTo4096<T>
AlignTo* type which aligns Self to ALIGNMENT.Source§impl<T> AlignerFor<8192> for T
impl<T> AlignerFor<8192> for T
Source§type Aligner = AlignTo8192<T>
type Aligner = AlignTo8192<T>
AlignTo* type which aligns Self to ALIGNMENT.Source§impl<T> AlignerFor<16384> for T
impl<T> AlignerFor<16384> for T
Source§type Aligner = AlignTo16384<T>
type Aligner = AlignTo16384<T>
AlignTo* type which aligns Self to ALIGNMENT.Source§impl<T> AlignerFor<32768> for T
impl<T> AlignerFor<32768> for T
Source§type Aligner = AlignTo32768<T>
type Aligner = AlignTo32768<T>
AlignTo* type which aligns Self to ALIGNMENT.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
Source§impl<T> GetSetFdFlags for T
impl<T> GetSetFdFlags for T
Source§fn get_fd_flags(&self) -> Result<FdFlags, Error>where
T: AsFilelike,
fn get_fd_flags(&self) -> Result<FdFlags, Error>where
T: AsFilelike,
self file descriptor.Source§fn new_set_fd_flags(&self, fd_flags: FdFlags) -> Result<SetFdFlags<T>, Error>where
T: AsFilelike,
fn new_set_fd_flags(&self, fd_flags: FdFlags) -> Result<SetFdFlags<T>, Error>where
T: AsFilelike,
Source§fn set_fd_flags(&mut self, set_fd_flags: SetFdFlags<T>) -> Result<(), Error>where
T: Sized + AsFilelike,
fn set_fd_flags(&mut self, set_fd_flags: SetFdFlags<T>) -> Result<(), Error>where
T: Sized + AsFilelike,
self file descriptor. Read moreSource§impl<T, W> HasTypeWitness<W> for Twhere
W: MakeTypeWitness<Arg = T>,
T: ?Sized,
impl<T, W> HasTypeWitness<W> for Twhere
W: MakeTypeWitness<Arg = T>,
T: ?Sized,
Source§impl<T> Identity for Twhere
T: ?Sized,
impl<T> Identity for Twhere
T: ?Sized,
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>
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>
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> Pointable for T
impl<T> Pointable for T
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<S> ROExtAcc for S
impl<S> ROExtAcc for S
Source§fn f_get<F>(&self, offset: FieldOffset<S, F, Aligned>) -> &F
fn f_get<F>(&self, offset: FieldOffset<S, F, Aligned>) -> &F
offset. Read moreSource§fn f_get_mut<F>(&mut self, offset: FieldOffset<S, F, Aligned>) -> &mut F
fn f_get_mut<F>(&mut self, offset: FieldOffset<S, F, Aligned>) -> &mut F
offset. Read moreSource§fn f_get_ptr<F, A>(&self, offset: FieldOffset<S, F, A>) -> *const F
fn f_get_ptr<F, A>(&self, offset: FieldOffset<S, F, A>) -> *const F
offset. Read moreSource§fn f_get_mut_ptr<F, A>(&mut self, offset: FieldOffset<S, F, A>) -> *mut F
fn f_get_mut_ptr<F, A>(&mut self, offset: FieldOffset<S, F, A>) -> *mut F
offset. Read moreSource§impl<S> ROExtOps<Aligned> for S
impl<S> ROExtOps<Aligned> for S
Source§fn f_replace<F>(&mut self, offset: FieldOffset<S, F, Aligned>, value: F) -> F
fn f_replace<F>(&mut self, offset: FieldOffset<S, F, Aligned>, value: F) -> F
offset) with value,
returning the previous value of the field. Read moreSource§fn f_get_copy<F>(&self, offset: FieldOffset<S, F, Aligned>) -> Fwhere
F: Copy,
fn f_get_copy<F>(&self, offset: FieldOffset<S, F, Aligned>) -> Fwhere
F: Copy,
Source§impl<S> ROExtOps<Unaligned> for S
impl<S> ROExtOps<Unaligned> for S
Source§fn f_replace<F>(&mut self, offset: FieldOffset<S, F, Unaligned>, value: F) -> F
fn f_replace<F>(&mut self, offset: FieldOffset<S, F, Unaligned>, value: F) -> F
offset) with value,
returning the previous value of the field. Read moreSource§fn f_get_copy<F>(&self, offset: FieldOffset<S, F, Unaligned>) -> Fwhere
F: Copy,
fn f_get_copy<F>(&self, offset: FieldOffset<S, F, Unaligned>) -> Fwhere
F: Copy,
Source§impl<T> SelfOps for Twhere
T: ?Sized,
impl<T> SelfOps for Twhere
T: ?Sized,
Source§fn piped<F, U>(self, f: F) -> U
fn piped<F, U>(self, f: F) -> U
Source§fn piped_ref<'a, F, U>(&'a self, f: F) -> Uwhere
F: FnOnce(&'a Self) -> U,
fn piped_ref<'a, F, U>(&'a self, f: F) -> Uwhere
F: FnOnce(&'a Self) -> U,
piped except that the function takes &Self
Useful for functions that take &Self instead of Self. Read moreSource§fn piped_mut<'a, F, U>(&'a mut self, f: F) -> Uwhere
F: FnOnce(&'a mut Self) -> U,
fn piped_mut<'a, F, U>(&'a mut self, f: F) -> Uwhere
F: FnOnce(&'a mut Self) -> U,
piped, except that the function takes &mut Self.
Useful for functions that take &mut Self instead of Self.Source§fn mutated<F>(self, f: F) -> Self
fn mutated<F>(self, f: F) -> Self
Source§fn observe<F>(self, f: F) -> Self
fn observe<F>(self, f: F) -> Self
Source§fn as_ref_<T>(&self) -> &T
fn as_ref_<T>(&self) -> &T
AsRef,
using the turbofish .as_ref_::<_>() syntax. Read more