Skip to main content

tool_loop_stream

Function tool_loop_stream 

Source
pub fn tool_loop_stream<Ctx: LoopDepth + Send + Sync + 'static>(
    provider: Arc<dyn DynProvider>,
    registry: Arc<ToolRegistry<Ctx>>,
    params: ChatParams,
    config: ToolLoopConfig,
    ctx: Arc<Ctx>,
) -> LoopStream
Expand description

Streaming variant of tool_loop.

Yields LoopEvents from each iteration. LLM streaming events (text deltas, tool call fragments) are interleaved with loop-level events (iteration start, tool execution start/end). The stream terminates with LoopEvent::Done carrying the final ToolLoopResult.

§Depth Tracking

If Ctx implements LoopDepth, nested calls are tracked automatically. When config.max_depth is set and the context’s depth exceeds the limit, yields Err(LlmError::MaxDepthExceeded) immediately.

Uses Arc for provider, registry, and context since they must outlive the returned stream.