Skip to contents

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 questions and context that returns a named list mapping each question's text to the chosen label or labels, a promise for that list, or AskUserDeferred() when the answers will come in the person's next message. Shiny apps can't wait for input, so they return a promise or AskUserDeferred(). If NULL, the tool uses the set_ask_user_callback() callback if one is set, and otherwise readline() in an interactive session.

context

A named list passed to callback, such as agent_id and session_id values 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.

Value

A list of tools.

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
)
} # }