CopilotSession
objectA 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.
- Kind Object
- Library Copilot
- Category AI in scripts
- Functions 3
How to get one
- Copilot .session()
- CopilotSession
local chat = Copilot.session(prompt)Returned by
Functions
-
sendAgentSessionResult Sends the next message of the conversation and waits for the answer. -
idstring | nil Returns the Copilot session id of this conversation, the same value as the sessionId field. -
closeself Closes this session and stops its Copilot process if one is still running.
send()
Section titled “send()”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
-
promptstring - The next message in the conversation
Returns
AgentSessionResult The result of a message sent in a CLI agent session.
Fields of AgentSessionResult
-
successboolean - true when the CLI exited with code 0
-
exitnumber - process exit code
-
textstring - the answer of the agent
-
allstring - the complete CLI output
-
durationnumber - run time in milliseconds
-
sessionIdstring - id of the session, nil until the CLI reports it
-
messagesany[] - the answer messages as a list of strings
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
close()
Section titled “close()”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.