| console_chat | R Documentation |
Launch an interactive chat session in the R console. Supports streaming output, slash commands, and colorful display using the cli package.
The console UI has three presentation modes:
clean: compact default output with a stable status bar
inspect: keeps the compact transcript but adds a per-turn tool timeline
and an overlay-backed inspector
debug: shows detailed tool logs and thinking output for troubleshooting
In agent mode, console_chat() can execute shell and R tools, summarize tool
progress inline, and open an inspector overlay for the latest turn or a
specific tool. The current implementation uses a shared frame builder for the
status bar, tool timeline, and overlay surfaces, while preserving an
append-only terminal fallback.
By default, the console operates in minimal agent mode with four tools:
bash, read_file, write_file, and edit_file. Set
profile = "legacy" to restore the previous broad all-in-one agent, or
agent = NULL for simple chat without tools.
console_chat(
session = NULL,
system_prompt = NULL,
tools = NULL,
hooks = NULL,
stream = TRUE,
verbose = FALSE,
agent = "auto",
skills = NULL,
working_dir = tempdir(),
sandbox_mode = "permissive",
show_thinking = verbose,
startup_dir = getwd(),
initial_prompt = NULL,
profile = c("minimal", "legacy"),
extensions = "auto"
)
session |
A ChatSession object, a LanguageModelV1 object, or a model string ID to create a new session. |
system_prompt |
Optional system prompt (merged with agent prompt if agent is used). |
tools |
Optional list of additional Tool objects. |
hooks |
Optional HookHandler object. |
stream |
Whether to use streaming output. Default TRUE. |
verbose |
Logical. If |
agent |
Agent configuration. Options:
|
skills |
Optional skill paths, |
working_dir |
Working directory for sandboxed console tools. Defaults to |
sandbox_mode |
Sandbox mode for the console agent: "strict", "permissive" (default), or "none". |
show_thinking |
Logical. Whether to show model thinking blocks when the
provider exposes them. Defaults to |
startup_dir |
R session startup directory used for project-aware context. Defaults to |
initial_prompt |
Optional user prompt to send automatically before entering the interactive REPL. |
profile |
Console profile. |
extensions |
Extension loading mode. Defaults to |
The ChatSession object (invisibly) when chat ends.
if (interactive()) {
# Start with default agent (intelligent terminal mode)
console_chat("openai:gpt-4o")
# Start in debug mode with full tool logs
console_chat("openai:gpt-4o", verbose = TRUE)
# Simple chat mode without tools
console_chat("openai:gpt-4o", agent = NULL)
# Start with an existing session
chat <- create_chat_session("anthropic:claude-3-5-sonnet-latest")
console_chat(chat)
# Start with a custom agent
agent <- create_agent("MathAgent", "Does math", system_prompt = "You are a math wizard.")
console_chat("openai:gpt-4o", agent = agent)
# Available commands in the chat:
# /quit or /exit - End the chat
# /save [path] - Save session to file
# /load [path] - Load session from file
# /model - Open the provider/model chooser
# /model [id] - Switch to a different model
# /model current - Show the active model
# /history - Show conversation history
# /stats - Show token usage statistics
# /clear - Clear conversation history
# /stream [on|off] - Toggle streaming mode
# /inspect [on|off] - Toggle inspect mode
# /inspect turn - Open overlay for the latest turn
# /inspect tool <index> - Open overlay for a tool in the latest turn
# /inspect next - Move inspector overlay to the next tool
# /inspect prev - Move inspector overlay to the previous tool
# /inspect close - Close the active inspect overlay
# /debug [on|off] - Toggle detailed tool/thinking output
# /local [on|off]- Toggle local execution mode (Global Environment)
# /help - Show available commands
# /agent [on|off] - Toggle agent mode
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.