ask_ai: Ask aisdk About Recent R Context

View source: R/ask_ai.R

ask_aiR Documentation

Ask aisdk About Recent R Context

Description

Collect recent R error context, active script context, session information, and workspace object summaries, then open console_chat() with that context as the initial prompt.

Collects the recent R error/session context and opens console_chat() with that context as the first user message. In RStudio, this function also reads the active source document when available, making it suitable as an Addin binding.

Usage

ask_ai(
  prompt = NULL,
  model = NULL,
  skills = "auto",
  skill = NULL,
  context = NULL,
  startup_dir = getwd(),
  working_dir = tempdir(),
  sandbox_mode = "permissive",
  stream = TRUE,
  verbose = FALSE,
  show_context = FALSE,
  max_context_chars = Inf,
  max_error_age_secs = 300,
  confirm_stale_errors = TRUE,
  ...
)

Arguments

prompt

Optional user instruction to add above the collected context.

model

Optional model string, LanguageModelV1, or ChatSession.

skills

Skill paths, "auto", or a SkillRegistry passed to console_chat().

skill

Optional skill name to force for the initial turn.

context

Optional additional context text, or an aisdk_ai_context object to reuse.

startup_dir

R session startup directory for project-aware context.

working_dir

Working directory for sandboxed console tools.

sandbox_mode

Sandbox mode for the console agent.

stream

Whether to stream model output.

verbose

Whether to show debug console output.

show_context

If TRUE, print and return the initial prompt without launching console_chat().

max_context_chars

Maximum formatted context characters. Defaults to Inf, meaning no explicit truncation.

max_error_age_secs

Maximum age in seconds for errors/warnings to be included. Defaults to 300 (5 minutes). Set to Inf to include all errors regardless of age.

confirm_stale_errors

If TRUE (default), show a warning and prompt for confirmation when errors/warnings are detected but appear stale.

...

Additional arguments passed to collect_ai_context().

Value

Invisibly returns the ChatSession from console_chat(), or a preview list when show_context = TRUE.


aisdk documentation built on May 29, 2026, 9:07 a.m.