pub struct ToolCallStream<'a, P: EventProducer<StateT>, StateT: AgentState = JsonValue> { /* private fields */ }Expand description
Helper for streaming a tool call with arguments.
This struct manages the lifecycle of a streaming tool call, automatically generating tool call IDs and emitting the appropriate events.
§Example
ⓘ
let call = ToolCallStream::start(&producer, "get_weather").await?;
call.args(r#"{"location": "#).await?;
call.args(r#""New York"}"#).await?;
let tool_call_id = call.end().await?;Implementations§
Source§impl<'a, P: EventProducer<StateT>, StateT: AgentState> ToolCallStream<'a, P, StateT>
impl<'a, P: EventProducer<StateT>, StateT: AgentState> ToolCallStream<'a, P, StateT>
Sourcepub async fn start(
producer: &'a P,
name: impl Into<String>,
) -> Result<Self, ServerError>
pub async fn start( producer: &'a P, name: impl Into<String>, ) -> Result<Self, ServerError>
Start a new tool call stream.
Emits a ToolCallStart event with the given tool name and a randomly
generated tool call ID.
Sourcepub async fn start_with_id(
producer: &'a P,
tool_call_id: ToolCallId,
name: impl Into<String>,
) -> Result<Self, ServerError>
pub async fn start_with_id( producer: &'a P, tool_call_id: ToolCallId, name: impl Into<String>, ) -> Result<Self, ServerError>
Start a new tool call stream with a specific tool call ID.
Sourcepub async fn args(&self, delta: impl Into<String>) -> Result<(), ServerError>
pub async fn args(&self, delta: impl Into<String>) -> Result<(), ServerError>
Stream an argument chunk.
Emits a ToolCallArgs event with the given delta.
Sourcepub async fn end(self) -> Result<ToolCallId, ServerError>
pub async fn end(self) -> Result<ToolCallId, ServerError>
End the tool call stream.
Emits a ToolCallEnd event and returns the tool call ID.
Consumes the stream to prevent further args being added.
Sourcepub fn tool_call_id(&self) -> &ToolCallId
pub fn tool_call_id(&self) -> &ToolCallId
Get the tool call ID for this stream.
Auto Trait Implementations§
impl<'a, P, StateT> Freeze for ToolCallStream<'a, P, StateT>
impl<'a, P, StateT> RefUnwindSafe for ToolCallStream<'a, P, StateT>where
P: RefUnwindSafe,
StateT: RefUnwindSafe,
impl<'a, P, StateT> Send for ToolCallStream<'a, P, StateT>
impl<'a, P, StateT> Sync for ToolCallStream<'a, P, StateT>
impl<'a, P, StateT> Unpin for ToolCallStream<'a, P, StateT>where
StateT: Unpin,
impl<'a, P, StateT> UnsafeUnpin for ToolCallStream<'a, P, StateT>
impl<'a, P, StateT> UnwindSafe for ToolCallStream<'a, P, StateT>where
P: RefUnwindSafe,
StateT: UnwindSafe,
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