Return AskUserDeferred() from a tools_interactive() handler when your app
shows the questions without waiting for the answers, as a chat interface
does. The tool result tells the model that the questions are on screen and
that it should end its turn; the person's answers arrive as their next
message.
A handler that must wait within the run can instead return a
promises::promise() for the answers. Deferring keeps runs short, and the
answers arrive as an ordinary user message. Subagents can't defer; their
handler must return the answers or a promise.
Arguments
- instructions
One string telling the model what happens next. The default asks it to end its turn without answering for the person.
- extra
Optional named list stored in the tool result's
extrafield (seeellmer::ContentToolResult()), for example data your app uses to display the questions.
Examples
handler <- function(questions, context) {
# Show `questions` in your app, then return without waiting.
AskUserDeferred()
}
tools <- tools_interactive(callback = handler)