Returns a list holding one ask_user tool (see tool_ask_user) that sends
questions to callback. Give each agent its own tool when several agents or
Shiny sessions share one R process, or when the session isn't interactive.
Usage
tools_interactive(callback = NULL, context = list())Arguments
- callback
A function of
questionsandcontextthat returns a named list mapping each question's text to the chosen label or labels, a promise for that list, orAskUserDeferred()when the answers will come in the person's next message. Shiny apps can't wait for input, so they return a promise orAskUserDeferred(). IfNULL, the tool uses theset_ask_user_callback()callback if one is set, and otherwisereadline()in an interactive session.- context
A named list passed to
callback, such asagent_idandsession_idvalues that tell your app where to show the questions, or a function with no arguments that returns one. A function is called each time the model asks.
Examples
if (FALSE) { # \dontrun{
agent_id <- "agent-review"
session_id <- "session-review"
agent <- Agent$new(
chat = ellmer::chat("openai/gpt-6-luna"),
tools = c(
tools_file(),
tools_interactive(
callback = function(questions, context) {
collect_answers(questions, route = context$session_id)
},
context = list(agent_id = agent_id, session_id = session_id)
)
),
agent_id = agent_id,
session_id = session_id
)
} # }