ask() takes named requests and returns the answers of the client, by
name. When the client has not answered one of them yet, it stops the
call: the server sends the client the requests it has not answered, and
runs the function again from the start once it has. A 2026-07-28 client
gets them in an input_required result, with the answers so far in a
signed requestState, and calls again; for a 2025-11-25 client, the
server sends each request to the client, waits for the answers, then runs
the function again. The code before ask() therefore runs once per
round: it must not change anything.
Usage
ask(...)
input_form(message, ...)
input_sample(message, max_tokens = 1000)
input_roots()
can_ask(request)Arguments
- ...
For
ask(), named requests. Forinput_form(), the fields of the form, named, made by thetype_*()functions that forms take: strings, numbers, integers, booleans and choices.- message
The text shown to the user, or sent to the model.
- max_tokens
The most tokens the model may write.
- request
A request made by
input_form(),input_sample()orinput_roots().
Value
ask(): the answers, a named list of the results the client
sent: action and content for a form, role, content and model
for a text of the model, roots for the roots. It stops when the
answer to a form has no such action, or when the content of an
accepted form does not fit the form. can_ask(): TRUE or FALSE.
The others: a request.
Details
input_form() asks the user to fill a form, input_sample() asks the
model of the client for a text, input_roots() asks for the roots of
the client. can_ask() tells whether the client declared the capability
a request needs: the server must not send it otherwise.
Examples
input_form(
"Which year?",
year = type_integer(
min = 2015
)
)
#> $method
#> [1] "elicitation/create"
#>
#> $params
#> $params$mode
#> [1] "form"
#>
#> $params$message
#> [1] "Which year?"
#>
#> $params$requestedSchema
#> $params$requestedSchema$type
#> [1] "object"
#>
#> $params$requestedSchema$properties
#> $params$requestedSchema$properties$year
#> $params$requestedSchema$properties$year$type
#> [1] "integer"
#>
#> $params$requestedSchema$properties$year$minimum
#> [1] 2015
#>
#>
#>
#> $params$requestedSchema$required
#> $params$requestedSchema$required[[1]]
#> [1] "year"
#>
#>
#>
#>
#> attr(,"class")
#> [1] "mordew_input"
input_sample(
"Write one sentence about a long run."
)
#> $method
#> [1] "sampling/createMessage"
#>
#> $params
#> $params$messages
#> $params$messages[[1]]
#> $params$messages[[1]]$role
#> [1] "user"
#>
#> $params$messages[[1]]$content
#> $params$messages[[1]]$content$type
#> [1] "text"
#>
#> $params$messages[[1]]$content$text
#> [1] "Write one sentence about a long run."
#>
#>
#>
#>
#> $params$maxTokens
#> [1] 1000
#>
#>
#> attr(,"class")
#> [1] "mordew_input"
input_roots()
#> $method
#> [1] "roots/list"
#>
#> $params
#> named list()
#>
#> attr(,"class")
#> [1] "mordew_input"
# In a tool: the call stops until the client has answered.
year_asked <- function() {
answers <- ask(
year = input_form(
"Which year?",
year = type_integer(
min = 2015
)
)
)
answers$year$content$year
}