collect_ai_context: Collect Context for 'ask_ai()'

View source: R/ask_ai.R

collect_ai_contextR Documentation

Collect Context for ask_ai()

Description

Collect recent error details, traceback output, warnings, active script context, session information, and lightweight workspace object summaries.

Usage

collect_ai_context(
  script = NULL,
  error = NULL,
  traceback = NULL,
  warnings = NULL,
  include = c("error", "traceback", "warnings", "script", "session", "objects",
    "history"),
  max_context_chars = Inf,
  max_error_age_secs = 300,
  include_history = TRUE,
  max_history_lines = 10
)

Arguments

script

Optional script text or path. If NULL, RStudio active document context is used when available.

error

Optional error message. Defaults to geterrmessage().

traceback

Optional traceback text. Defaults to traceback() output.

warnings

Optional warning text or warning object. Defaults to R's last.warning context when present.

include

Character vector of sections to include.

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.

include_history

Whether to include recent command history. Defaults to TRUE.

max_history_lines

Maximum number of recent command history lines to include. Defaults to 10.

Value

A structured context list with class aisdk_ai_context.


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