pub struct ToolUseLoop { /* private fields */ }Expand description
管理 LLM 与工具调用闭环
Implementations§
Source§impl ToolUseLoop
impl ToolUseLoop
pub fn new(model: ResolvedModel, executor: ToolExecutor) -> Self
pub fn set_max_iterations(self, max: usize) -> Self
Sourcepub async fn execute(
self,
messages: Vec<Message>,
) -> Result<ToolUseResult, LlmError>
pub async fn execute( self, messages: Vec<Message>, ) -> Result<ToolUseResult, LlmError>
非流式执行
语义:
Ok(ToolUseResult)— Agent 层完成(含 MaxIterationsReached)Err(LlmError)— Provider 调用失败
Sourcepub fn execute_stream(self, messages: Vec<Message>) -> AgentStream
pub fn execute_stream(self, messages: Vec<Message>) -> AgentStream
流式执行,返回事件接收器
终态契约:
- 正常结束:
LoopEnd恰好一次,然后 channel 关闭 - 异常结束:
LoopError恰好一次,然后 channel 关闭 - 终态事件后不再发送任何事件
- 绝不会发送伪造的
ToolEnd { tool_call_id: "", .. }
Auto Trait Implementations§
impl Freeze for ToolUseLoop
impl !RefUnwindSafe for ToolUseLoop
impl Send for ToolUseLoop
impl Sync for ToolUseLoop
impl Unpin for ToolUseLoop
impl UnsafeUnpin for ToolUseLoop
impl !UnwindSafe for ToolUseLoop
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