class
ACP::Session
- ACP::Session
- Reference
- Object
Defined in:
acp/session.crConstructors
-
.create(client : Client, cwd : String, mcp_servers : Array(JSON::Any) | Nil = nil) : Session
Creates a new session via
session/new. -
.load(client : Client, session_id : String, cwd : String, mcp_servers : Array(JSON::Any) | Nil = nil) : Session
Loads (resumes) a previous session via
session/load. -
.new(client : Client, id : String, modes : Protocol::SessionModeState | Nil = nil, config_options : Array(Protocol::ConfigOption) | Nil = nil)
Direct constructor.
Instance Method Summary
-
#available_mode_ids : Array(String)
Returns the list of available mode IDs, or an empty array if the agent doesn't support modes.
-
#cancel : Nil
Sends a
session/cancelnotification to abort the current operation in this session. -
#client : Client
The underlying client this session communicates through.
-
#close : Nil
Marks this session as closed.
-
#closed? : Bool
Whether this session has been explicitly cancelled or closed.
-
#config_options : Array(Protocol::ConfigOption) | Nil
Config options exposed by the agent for this session.
-
#id : String
The unique session ID assigned by the agent.
- #inspect(io : IO) : Nil
-
#modes : Protocol::SessionModeState | Nil
Mode state for this session (may be nil if agent doesn't support modes).
-
#prompt(content_blocks : Array(Protocol::ContentBlock)) : Protocol::SessionPromptResult
Sends a prompt with an array of content blocks and waits for the agent's response.
-
#prompt(text : String) : Protocol::SessionPromptResult
Convenience: sends a simple text prompt.
-
#prompt(*texts : String) : Protocol::SessionPromptResult
Sends a prompt with multiple text strings, each as a separate TextContentBlock.
-
#prompt(& : PromptBuilder -> ) : Protocol::SessionPromptResult
Sends a prompt built from a block.
-
#set_config_option(config_id : String, value : String) : Protocol::SessionSetConfigOptionResult
Changes a session configuration option.
-
#set_mode(mode_id : String) : Nil
Switches the session to the specified mode.
-
#to_s(io : IO) : Nil
Returns a human-readable summary of the session for debugging.
Constructor Detail
Creates a new session via session/new.
#client— an initialized ACP::Client.cwd— the absolute path to the working directory.mcp_servers— optional MCP server references (as JSON::Any).
The client must be in the Initialized (or SessionActive) state.
Returns a new Session instance bound to the created session.
Loads (resumes) a previous session via session/load.
#client— an initialized ACP::Client.session_id— the ID of the session to resume.cwd— the absolute path to the working directory.mcp_servers— optional MCP server references (as JSON::Any).
Returns a Session instance bound to the loaded session.
Direct constructor. Prefer Session.create or Session.load.
Instance Method Detail
Returns the list of available mode IDs, or an empty array if the agent doesn't support modes.
Sends a session/cancel notification to abort the current
operation in this session. This is fire-and-forget.
Marks this session as closed. Further prompt/cancel calls will raise an error. Note: there is no explicit "session/close" method in ACP; this is a client-side state flag.
Config options exposed by the agent for this session.
Mode state for this session (may be nil if agent doesn't support modes).
Sends a prompt with an array of content blocks and waits for
the agent's response. Session update notifications will be
dispatched through the client's on_update callback while
the prompt is being processed.
Returns the prompt result containing the stop reason.
Raises ACP::Error if the session is closed.
Convenience: sends a simple text prompt.
text— the text to send as a single TextContentBlock.
Returns the prompt result containing the stop reason.
Sends a prompt with multiple text strings, each as a separate TextContentBlock.
Sends a prompt built from a block. The block receives a
PromptBuilder for ergonomic content block construction.
Example:
session.prompt do |b|
b.text "Explain this file:"
b.file "/path/to/file.cr"
end
Changes a session configuration option.
config_id— the ID of the config option to change.value— the new value to set.
Returns the full set of config options and their current values. See: https://agentclientprotocol.com/protocol/session-config-options
Switches the session to the specified mode.
mode_id— the ID of the mode to activate.