Agent Client Protocol - v0.4.7
    Preparing search index...

    Class ClientSideConnection

    A client-side connection to an agent.

    This class provides the client's view of an ACP connection, allowing clients (such as code editors) to communicate with agents. It implements the Agent interface to provide methods for initializing sessions, sending prompts, and managing the agent lifecycle.

    See protocol docs: Client

    Implements

    Index

    Constructors

    • Creates a new client-side connection to an agent.

      This establishes the communication channel between a client and agent following the ACP specification.

      Parameters

      • toClient: (agent: Agent) => Client

        A function that creates a Client handler to process incoming agent requests

      • stream: Stream

        The bidirectional message stream for communication. Typically created using ndJsonStream for stdio-based connections.

        See protocol docs: Communication Model

      Returns ClientSideConnection

    Methods

    • Establishes the connection with a client and negotiates protocol capabilities.

      This method is called once at the beginning of the connection to:

      • Negotiate the protocol version to use
      • Exchange capability information between client and agent
      • Determine available authentication methods

      The agent should respond with its supported protocol version and capabilities.

      See protocol docs: Initialization

      Parameters

      Returns Promise<InitializeResponse>

    • Creates a new conversation session with the agent.

      Sessions represent independent conversation contexts with their own history and state.

      The agent should:

      • Create a new session context
      • Connect to any specified MCP servers
      • Return a unique session ID for future requests

      May return an auth_required error if the agent requires authentication.

      See protocol docs: Session Setup

      Parameters

      Returns Promise<NewSessionResponse>

    • Sets the operational mode for a session.

      Allows switching between different agent modes (e.g., "ask", "architect", "code") that affect system prompts, tool availability, and permission behaviors.

      The mode must be one of the modes advertised in availableModes during session creation or loading. Agents may also change modes autonomously and notify the client via current_mode_update notifications.

      This method can be called at any time during a session, whether the Agent is idle or actively generating a turn.

      See protocol docs: Session Modes

      Parameters

      Returns Promise<SetSessionModeResponse>

    • Processes a user prompt within a session.

      This method handles the whole lifecycle of a prompt:

      • Receives user messages with optional context (files, images, etc.)
      • Processes the prompt using language models
      • Reports language model content and tool calls to the Clients
      • Requests permission to run tools
      • Executes any requested tool calls
      • Returns when the turn is complete with a stop reason

      See protocol docs: Prompt Turn

      Parameters

      Returns Promise<PromptResponse>

    • Cancels ongoing operations for a session.

      This is a notification sent by the client to cancel an ongoing prompt turn.

      Upon receiving this notification, the Agent SHOULD:

      • Stop all language model requests as soon as possible
      • Abort all tool call invocations in progress
      • Send any pending session/update notifications
      • Respond to the original session/prompt request with StopReason::Cancelled

      See protocol docs: Cancellation

      Parameters

      Returns Promise<void>

    • Extension method

      Allows the Client to send an arbitrary request that is not part of the ACP spec.

      Parameters

      • method: string
      • params: Record<string, unknown>

      Returns Promise<Record<string, unknown>>

    • Extension notification

      Allows the Client to send an arbitrary notification that is not part of the ACP spec.

      Parameters

      • method: string
      • params: Record<string, unknown>

      Returns Promise<void>