Skip to contents

stream_async() sends a module's prompt to the model and returns ellmer's async generator of text chunks, for use inside an asynchronous function (for example with the coro package). The response is plain streamed text: the signature's output types are not applied. For per-field callbacks and structured results, use run_stream().

Usage

stream_async(module, ..., .llm = NULL, .history = NULL)

Arguments

module

A prediction module from module() or chain_of_thought(). Other modules are rejected before any request; use run() for them.

...

Inputs named after the signature's input fields.

.llm

An ellmer Chat; see run() for how it is chosen when omitted.

.history

Explicit conversation history is not supported by async streaming; use synchronous run() for scalar root ReAct or RLM continuation.

Value

An async generator that yields the response text in chunks.

Details

The generator comes from ellmer's Chat$stream_async(). The call does not use the response cache and records no trace. It returns unstructured text, so chain_of_thought(mode = "plan") and mode = "native" are rejected rather than dropping the plan field or native metadata. Use run_async() for a structured plan, or synchronous structured run() for native metadata.

Examples

if (FALSE) { # \dontrun{
storyteller <- module(signature("topic -> story"))
chunks <- stream_async(
  storyteller,
  topic = "a lighthouse keeper",
  .llm = ellmer::chat_openai(model = "gpt-6-luna")
)

print_chunks <- coro::async(function(generator) {
  for (chunk in coro::await_each(generator)) cat(chunk)
})
print_chunks(chunks)
} # }