The default Agentix.Provider — a thin wrapper over ReqLLM.stream_text/3, or
ReqLLM.stream_object/4 when the turn requests structured output.
When opts carry a :schema (a NimbleOptions keyword or JSON Schema map), the
adapter calls ReqLLM.stream_object/4 instead — ReqLLM implements structured output
as a forced structured_output tool call. finalize then extracts the parsed object
with ReqLLM.Response.unwrap_object/1 (from the already-collected chunks — never
re-consuming the stream) and stashes it in the assistant message's metadata["object"],
where Agentix.object/1 reads it.
ReqLLM.stream_text/3 returns {:ok, %ReqLLM.StreamResponse{}} (not a bare
stream). The struct carries a lazy stream of %ReqLLM.StreamChunk{}, a
metadata_handle collected concurrently, and a cancel closure that actually
closes the socket. This adapter maps that onto the normalized
Agentix.Provider.Stream the agent consumes:
chunks— the lazy stream, wrapped so each chunk is accumulated as the agent forwards it as a live delta;cancel—StreamResponse's own closure, passed through unchanged (the agent invokes it on:cancelso the HTTP connection is freed);finalize— awaits the metadata handle and rebuilds the finalized assistant%ReqLLM.Message{}+ usage from the accumulated chunks, reusing ReqLLM's ownResponseBuilderso tool-call ids (assembled by ReqLLM, absent from individualStreamChunks) survive. Call it afterchunksis consumed.
Streaming pools are HTTP/1-only by default (Finch ALPN bug with mixed-protocol large bodies).