Skip to content

CopilotSession

object

A Copilot conversation started by Copilot.session. The first prompt has already been answered when you get it (see last); send continues the same thread, so Copilot remembers earlier messages.

How to get one

  1. Copilot .session()
  2. CopilotSession
local chat = Copilot.session(prompt)

Functions

  • send AgentSessionResult Sends the next message of the conversation and waits for the answer.
  • id string | nil Returns the Copilot session id of this conversation, the same value as the sessionId field.
  • close self Closes this session and stops its Copilot process if one is still running.
chat.send(prompt: string)→AgentSessionResult

Sends the next message of the conversation and waits for the answer. Returns the result table, which is also stored as session.last. Raises an error when the session is closed.

Parameters

prompt string
The next message in the conversation

Returns

AgentSessionResult The result of a message sent in a CLI agent session.
Fields of AgentSessionResult
success boolean
true when the CLI exited with code 0
exit number
process exit code
text string
the answer of the agent
all string
the complete CLI output
duration number
run time in milliseconds
sessionId string
id of the session, nil until the CLI reports it
messages any[]
the answer messages as a list of strings
All table shapes

Example

local chat = Copilot.session("Read tests/checkout.lua and remember its structure.")
local answer = chat.send("Which steps are missing assertions?")
print(answer.text)
chat.close()
chat.id()→string | nil

Returns the Copilot session id of this conversation, the same value as the sessionId field.

Returns

string | nil can be nil The session id, nil until the CLI has reported it
chat.close()→self

Closes this session and stops its Copilot process if one is still running. Afterwards send raises an error.

Returns

self chainable The chat itself, so calls can be chained.