pyrit.prompt_target.WebSocketCopilotTarget#

class WebSocketCopilotTarget(*, websocket_base_url: str = 'wss://substrate.office.com/m365Copilot/Chathub', max_requests_per_minute: int | None = None, model_name: str = 'copilot', response_timeout_seconds: int = 60, authenticator: CopilotAuthenticator | ManualCopilotAuthenticator | None = None)[source]#

Bases: PromptTarget

A WebSocket-based prompt target for integrating with Microsoft Copilot.

This class facilitates communication with Microsoft Copilot over a WebSocket connection. Authentication can be handled in two ways:

  1. Automated (default): Via CopilotAuthenticator, which uses Playwright to automate browser login and obtain the required access tokens. Requires COPILOT_USERNAME and COPILOT_PASSWORD environment variables as well as Playwright installed.

  2. Manual: Via ManualCopilotAuthenticator, which accepts a pre-obtained access token. This is useful for situations where browser automation is not possible.

Once authenticated, the target supports multi-turn conversations through server-side state management. For each PyRIT conversation, it automatically generates consistent session_id and conversation_id values, enabling Copilot to preserve conversational context across multiple turns.

Because conversation state is managed entirely on the Copilot server, this target does not resend conversation history with each request and does not support programmatic inspection or manipulation of that history. At present, there appears to be no supported mechanism for modifying Copilot’s server-side conversation state.

Note

This integration only works with licensed Microsoft 365 Copilot. The free version of Copilot is not compatible.

__init__(*, websocket_base_url: str = 'wss://substrate.office.com/m365Copilot/Chathub', max_requests_per_minute: int | None = None, model_name: str = 'copilot', response_timeout_seconds: int = 60, authenticator: CopilotAuthenticator | ManualCopilotAuthenticator | None = None) None[source]#

Initialize the WebSocketCopilotTarget.

Parameters:
  • websocket_base_url (str) – Base URL for the Copilot WebSocket endpoint. Defaults to wss://substrate.office.com/m365Copilot/Chathub.

  • max_requests_per_minute (Optional[int]) – Maximum number of requests per minute.

  • model_name (str) – The model name. Defaults to “copilot”.

  • response_timeout_seconds (int) – Timeout for receiving responses in seconds. Defaults to 60s.

  • authenticator (Optional[Union[CopilotAuthenticator, ManualCopilotAuthenticator]]) – Authenticator instance. Supports both CopilotAuthenticator and ManualCopilotAuthenticator. If None, a new CopilotAuthenticator instance will be created with default settings.

Raises:
  • ValueError – If response_timeout_seconds is not a positive integer.

  • ValueError – If websocket_base_url does not start with “wss://”.

Methods

__init__(*[, websocket_base_url, ...])

Initialize the WebSocketCopilotTarget.

dispose_db_engine()

Dispose database engine to release database connections and resources.

get_identifier()

Get the typed identifier for this object.

send_prompt_async(**kwargs)

Send a normalized prompt async to the prompt target.

set_model_name(*, model_name)

Set the model name for this target.

Attributes

CONNECTION_TIMEOUT_SECONDS

RESPONSE_TIMEOUT_SECONDS

SUPPORTED_DATA_TYPES

supported_converters

A list of PromptConverters that are supported by the prompt target.

CONNECTION_TIMEOUT_SECONDS: int = 30#
RESPONSE_TIMEOUT_SECONDS: int = 60#
SUPPORTED_DATA_TYPES = {'text'}#
async send_prompt_async(**kwargs: Any) Any#

Send a normalized prompt async to the prompt target.

Returns:

A list of message responses. Most targets return a single message,

but some (like response target with tool calls) may return multiple messages.

Return type:

list[Message]