High-level chat interface to GitHub Copilot models. Manages conversation history, tool registration, and streaming. API surface mirrors ellmer::Chat for familiarity.
Uses HalClient for JSON-RPC transport to the Copilot SDK CLI, which handles model-specific format translation internally – no proxy translation bugs.
The ACP server maintains conversation history server-side. Turns are
also tracked locally so you can inspect them with $get_turns().
Value
An R6 object of class HalChat. Methods return
values as documented per method; construct with HalChat$new().
See also
HalClient for the low-level transport layer,
hal_models() for available models.
Methods
HalChat$new()
Create a new Copilot chat session.
Usage
HalChat$new(
model = NULL,
system_prompt = NULL,
client = NULL,
echo = NULL,
on_text = NULL,
on_tool_call = NULL,
on_thought = NULL,
mode = NULL,
permission_policy = "auto-allow",
quiet = FALSE
)Arguments
modelModel identifier (e.g.,
"claude-sonnet-5","gpt-5.2"). IfNULL, uses the server default.system_promptSystem prompt string.
clientA HalClient instance, or
NULLto create one.echoEcho mode:
"none","output", or"all".on_textCallback for streaming text chunks:
function(chunk).on_tool_callCallback for tool call events:
function(tool_call).on_thoughtCallback for thought chunks:
function(chunk).modeSession mode:
"agent"(default),"plan", or"autopilot". Applied after the session is created on the first prompt.permission_policyPermission policy for the agent:
"auto-allow","auto-deny", or a custom function. Ignored ifclientis provided.quietLogical; suppress informational messages (default: FALSE).
HalChat$chat()
Send a message and get a response.
HalChat$register_tool()
Register a tool for the model to call.
Arguments
toolA tool definition. Can be an
ellmer::ToolDefor a list withname,description,parameters, andfunfields.
HalChat$set_mode()
Set the session mode.
Usage
HalChat$set_mode(mode = c("agent", "plan", "autopilot"))HalChat$cancel()
Cancel the current in-flight prompt.
Stops the streaming loop and returns a partial response with
stop_reason = "interrupted". For interactive use, Ctrl+C (ESC in
RStudio) during $chat() achieves the same effect automatically.
Useful from Shiny observers, callbacks, or a second R session.
Examples
if (FALSE) { # \dontrun{
# Preferred: use hal_chat()
chat <- hal_chat()
chat$chat("Explain the pipe operator in R")
# Or use R6 constructor directly
chat <- HalChat$new(model = "gpt-5.2")
chat$chat("Hello!")
} # }
