pub struct HttpStreamingTool { /* private fields */ }Expand description
HTTP tool with first-class streaming surface (v1.29.0).
stream() drives a reqwest::Client::post(url) async request +
drains response.bytes_stream() chunk-by-chunk. Content-Type
header decides framing:
text/event-stream→ SSE per W3C spec. Eachdata:field from a complete SSE event emits as aToolChunk::intermediate.event:/id:/retry:fields are dropped (the adopter sees only the data payload — the framing was for HTTP transport).application/x-ndjson/application/jsonl→ oneToolChunk::intermediateper LF-delimited line. Empty lines are skipped.- Other (
application/json,text/plain, raw bytes) → singleToolChunk::intermediatewith the full body accumulated, then a terminator. This is the D9 backwards-compat path for non-streaming HTTP endpoints — the same response shapedispatch_httpreturns synchronously, projected onto the single-chunk streaming surface.
§Cancel discipline (D5)
ctx.cancel is polled between every bytes_stream().next().await
boundary. When fired, the stream drops the reqwest::Response
(closing the connection) + emits a single
ToolFinishReason::Cancelled terminator chunk. Wall-clock budget
is bounded by the network roundtrip latency to the next chunk
arrival (typically ≤100ms for SSE streams with regular keepalive).
§Error discipline
Every failure surface (URL invalid / client build / connect /
timeout / non-2xx status / mid-stream byte error / I/O error)
is captured as a ToolFinishReason::Error { message } terminator
chunk — the consumer never sees a panic or a silently-truncated
stream.
Implementations§
Source§impl HttpStreamingTool
impl HttpStreamingTool
Trait Implementations§
Source§impl Tool for HttpStreamingTool
impl Tool for HttpStreamingTool
Source§fn execute<'life0, 'async_trait>(
&'life0 self,
args: String,
_ctx: ToolContext,
) -> Pin<Box<dyn Future<Output = ToolResult> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn execute<'life0, 'async_trait>(
&'life0 self,
args: String,
_ctx: ToolContext,
) -> Pin<Box<dyn Future<Output = ToolResult> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
ToolResult. EVERY tool MUST implement this method
(no default — there’s no sensible default execute).Source§fn stream<'life0, 'async_trait>(
&'life0 self,
args: String,
ctx: ToolContext,
) -> Pin<Box<dyn Future<Output = ToolStream> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn stream<'life0, 'async_trait>(
&'life0 self,
args: String,
ctx: ToolContext,
) -> Pin<Box<dyn Future<Output = ToolStream> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Source§fn is_streaming(&self) -> bool
fn is_streaming(&self) -> bool
false. Read more