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().
Usage
run_async(module, ..., .llm = NULL, .trace_context = list())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().- .trace_context
A named, JSON-compatible list, as in
run(). The promise carries it in itsdsprrr_trace_contextattribute.
Value
A promise that resolves to the module's output, the same value
that run() returns by default.
Details
Prediction modules call ellmer's chat_structured_async() directly: the
call does not use the response cache and records no trace or prompt
history. Code-running modules run their whole workflow in a separate mirai
process with a fresh interpreter; modules bound to a caller-owned runner
are rejected, because one runner cannot serve concurrent calls. Other
modules, such as react() or pipelines, are rejected; use run().
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))
})
} # }