pyrit.executor.attack.AttackContext#

class AttackContext(params: ~pyrit.executor.attack.core.attack_parameters.AttackParamsT, start_time: float = 0.0, related_conversations: set[~pyrit.models.conversation_reference.ConversationReference] = <factory>, _next_message_override: ~pyrit.models.message.Message | None = None, _prepended_conversation_override: ~typing.List[~pyrit.models.message.Message] | None = None, _memory_labels_override: ~typing.Dict[str, str] | None = None)[source]#

Bases: StrategyContext, ABC, Generic[AttackParamsT]

Base class for all attack contexts.

This class holds both the immutable attack parameters and the mutable execution state. The params field contains caller-provided inputs, while other fields track execution progress.

Attacks that generate certain values internally (e.g., RolePlayAttack generates next_message and prepended_conversation) can set the mutable override fields (_next_message_override, _prepended_conversation_override) during _setup_async.

__init__(params: ~pyrit.executor.attack.core.attack_parameters.AttackParamsT, start_time: float = 0.0, related_conversations: set[~pyrit.models.conversation_reference.ConversationReference] = <factory>, _next_message_override: ~pyrit.models.message.Message | None = None, _prepended_conversation_override: ~typing.List[~pyrit.models.message.Message] | None = None, _memory_labels_override: ~typing.Dict[str, str] | None = None) None#

Methods

__init__(params[, start_time, ...])

duplicate()

Create a deep copy of the context.

Attributes

memory_labels

Additional labels that can be applied to the prompts throughout the attack.

next_message

Optional message to send to the objective target.

objective

Natural-language description of what the attack tries to achieve.

prepended_conversation

Conversation that is automatically prepended to the target model.

start_time

params

related_conversations

property memory_labels: Dict[str, str]#

Additional labels that can be applied to the prompts throughout the attack.

property next_message: Message | None#

Optional message to send to the objective target.

property objective: str#

Natural-language description of what the attack tries to achieve.

params: AttackParamsT#
property prepended_conversation: List[Message]#

Conversation that is automatically prepended to the target model.

related_conversations: set[ConversationReference]#
start_time: float = 0.0#