run_async() starts one call of a module and returns a promise instead of
waiting for the result, so a Shiny app or other event loop stays
responsive and several calls can be in flight at once. Handle the result
with the promises package, for example promises::then().
Arguments
- module
A prediction module from
module()orchain_of_thought(), or aprogram_of_thought(),code_act()orrlm_module()module configured withinterpreter_factory.- ...
Inputs named after the signature's input fields (single values).
- .llm
An ellmer Chat; see
run()for how it is chosen when omitted. Give concurrent calls separate chats, for example withllm$clone().- .return_format
Either
"simple"(the default), which resolves to the output value, or"structured", which resolves to adsprrr_resultwithoutput,chat, andmetadatafields.- .trace_context
A named, JSON-compatible list, as in
run(). The promise carries it in itsdsprrr_trace_contextattribute. Direct Predict calls also record it in the module's traces.- .history
Explicit conversation history is not supported by async execution; use synchronous
run()for scalar root ReAct continuation.- .control
An optional
react_async_control()for cooperative cancellation and progress reporting. Supported only forreact()modules.
Value
A promise that resolves to the module's output, matching
run()'s default result, or to a dsprrr_result when
.return_format = "structured". Provider, decoding, and completion
failures reject the promise.
Details
Prediction modules call ellmer's chat_structured_async() directly. These
calls bypass the response cache and record one trace on either success or
failure. Structured results include canonical usage, decisions, and any
provider-supplied native reasoning blocks recorded for the current call;
unavailable usage remains NA and absent native reasoning remains NULL.
ReAct failures and cancellations preserve the partial native Chat history,
observed tool results, and requested-versus-result status in the trace. That
partial history is not a portable continuation or an instruction to replay
tools.
Factory-backed code-running modules keep their simple result behavior;
structured results are rejected because that worker path does not yet
preserve the same trace contract. Modules bound to a caller-owned runner
are rejected, because one runner cannot serve concurrent calls. Other
specialized modules, such as pipelines, are rejected; use run().
Each direct provider call reserves its resolved Chat until the promise settles. A concurrent call using that same Chat is rejected before provider work; use separate Chats for overlapping calls.
ReAct modules use ellmer's sequential async tool loop and await their
structured follow-up when configured. Their optional .control reports
progress and supports cooperative cancellation between requests and tools;
it does not interrupt a request or tool already in progress.
See also
Other execution:
concurrency_control(),
evaluate(),
predict.Module(),
run(),
run_dataset(),
run_stream(),
stream_async(),
stream_listener()
Examples
if (FALSE) { # \dontrun{
llm <- ellmer::chat_openai(model = "gpt-6-luna")
summarize <- module(signature("text -> summary"))
first <- run_async(summarize, text = "First article ...", .llm = llm$clone())
second <- run_async(summarize, text = "Second article ...", .llm = llm$clone())
promises::promise_all(first, second) |>
promises::then(function(results) {
vapply(results, function(r) r$summary, character(1))
})
} # }