| HalChat | R Documentation |
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().
An R6 object of class HalChat. Methods return
values as documented per method; construct with HalChat$new().
HalChat$new()Create a new Copilot chat session.
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 )
modelModel identifier (e.g., "claude-sonnet-5", "gpt-5.2").
If NULL, uses the server default.
system_promptSystem prompt string.
clientA HalClient instance, or NULL to 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 if client is provided.
quietLogical; suppress informational messages (default: FALSE).
HalChat$chat()Send a message and get a response.
HalChat$chat(..., timeout = NULL)
...Character strings, concatenated as the user message.
timeoutTimeout in seconds for the response.
Assistant's text response (invisibly if echo != "none").
HalChat$register_tool()Register a tool for the model to call.
HalChat$register_tool(tool)
toolA tool definition. Can be an ellmer::ToolDef or a list
with name, description, parameters, and fun fields.
HalChat$register_tools()Register multiple tools.
HalChat$register_tools(tools)
toolsA list of tool definitions.
HalChat$get_turns()Get conversation turns.
HalChat$get_turns(include_system_prompt = FALSE)
include_system_promptInclude the system prompt turn.
List of turn objects.
HalChat$last_response()Get the full response from the last prompt.
HalChat$last_response()
A hal_response object, or NULL if no responses yet.
HalChat$last_turn()Get the last assistant turn.
HalChat$last_turn()
A hal_turn object, or NULL if no turns yet.
HalChat$last_tool_calls()Get tool calls from the last assistant turn.
HalChat$last_tool_calls()
List of hal_tool_call objects, or NULL if none.
HalChat$switch_model()Switch models mid-session without losing context.
HalChat$switch_model(model)
modelModel identifier (e.g., "gpt-4.1", "claude-haiku-4.5").
Invisibly returns self.
HalChat$set_mode()Set the session mode.
HalChat$set_mode(mode = c("agent", "plan", "autopilot"))
mode"agent" (default), "plan", or "autopilot".
Invisibly returns self.
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.
HalChat$cancel()
Invisibly returns self.
HalChat$get_model()Get the model identifier.
HalChat$get_model()
Character string.
HalChat$get_client()Get the underlying client.
HalChat$get_client()
A HalClient instance.
HalChat$clone()The objects of this class are cloneable with this method.
HalChat$clone(deep = FALSE)
deepWhether to make a deep clone.
HalClient for the low-level transport layer,
hal_models() for available models.
## Not run:
# 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!")
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.