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:
PromptTargetA 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:
Automated (default): Via
CopilotAuthenticator, which uses Playwright to automate browser login and obtain the required access tokens. RequiresCOPILOT_USERNAMEandCOPILOT_PASSWORDenvironment variables as well as Playwright installed.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_idandconversation_idvalues, 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
CopilotAuthenticatorandManualCopilotAuthenticator. If None, a newCopilotAuthenticatorinstance will be created with default settings.
- Raises:
ValueError – If
response_timeout_secondsis not a positive integer.ValueError – If
websocket_base_urldoes 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
supported_convertersA list of PromptConverters that are supported by the prompt target.
- SUPPORTED_DATA_TYPES = {'text'}#