Skip to content

Commit edf0821

Browse files
authored
FEAT Breaking: Adding Resiliency to Scenarios (#1164)
1 parent dd4c007 commit edf0821

28 files changed

+3038
-259
lines changed

doc/_toc.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ chapters:
120120
- file: code/memory/chat_message
121121
- file: code/setup/0_configuration
122122
sections:
123+
- file: code/setup/1_resiliency
123124
- file: code/setup/default_values
124125
- file: code/setup/pyrit_initializer
125126
- file: code/auxiliary_attacks/0_auxiliary_attacks

doc/api.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@ API Reference
215215
MultiPromptSendingAttack
216216
MultiPromptSendingAttackContext
217217
MultiTurnAttackContext
218+
AttackExecutorResult
218219
PromptSendingAttack
219220
RTASystemPromptPaths
220221
RedTeamingAttack
@@ -541,7 +542,6 @@ API Reference
541542
:toctree: _autosummary/
542543

543544
AtomicAttack
544-
AtomicAttackResult
545545
EncodingScenario
546546
FoundryStrategy
547547
FoundryScenario

doc/code/scenarios/scenarios.ipynb

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@
3232
"\n",
3333
"## How It Works\n",
3434
"\n",
35-
"Each `Scenario` contains a collection of `AttackRun` objects. When executed:\n",
35+
"Each `Scenario` contains a collection of `AtomicAttack` objects. When executed:\n",
3636
"\n",
37-
"1. Each `AttackRun` is executed sequentially\n",
38-
"2. Every `AttackRun` tests its configured attack against all specified objectives and datasets\n",
37+
"1. Each `AtomicAttack` is executed sequentially\n",
38+
"2. Every `AtomicAttack` tests its configured attack against all specified objectives and datasets\n",
3939
"3. Results are aggregated into a single `ScenarioResult` with all attack outcomes\n",
4040
"4. Optional memory labels help track and categorize the scenario execution\n",
4141
"\n",
@@ -64,7 +64,7 @@
6464
{
6565
"data": {
6666
"application/vnd.jupyter.widget-view+json": {
67-
"model_id": "108387f8a81646c289f28c1e3255bb5a",
67+
"model_id": "ecb802c8f9964212b3f6c3ff7a416e79",
6868
"version_major": 2,
6969
"version_minor": 0
7070
},
@@ -168,6 +168,7 @@
168168
" ScenarioCompositeStrategy(strategies=[FoundryStrategy.Caesar, FoundryStrategy.CharSwap]), # Composed strategy\n",
169169
"]\n",
170170
"\n",
171+
"\n",
171172
"# Create a scenario from the pre-configured Foundry scenario\n",
172173
"foundry_scenario = FoundryScenario(\n",
173174
" objective_target=objective_target,\n",
@@ -183,6 +184,30 @@
183184
"foundry_results = await foundry_scenario.run_async() # type: ignore\n",
184185
"await printer.print_summary_async(foundry_results) # type: ignore"
185186
]
187+
},
188+
{
189+
"cell_type": "markdown",
190+
"id": "2",
191+
"metadata": {},
192+
"source": [
193+
"## Resiliency\n",
194+
"\n",
195+
"Scenarios can run for a long time, and because of that, things can go wrong. Network issues, rate limits, or other transient failures can interrupt execution. PyRIT provides built-in resiliency features to handle these situations gracefully.\n",
196+
"\n",
197+
"### Automatic Resume\n",
198+
"\n",
199+
"If you re-run a `scenario`, it will automatically start where it left off. The framework tracks completed attacks and objectives in memory, so you won't lose progress if something interrupts your scenario execution. This means you can safely stop and restart scenarios without duplicating work.\n",
200+
"\n",
201+
"### Retry Mechanism\n",
202+
"\n",
203+
"You can utilize the `max_retries` parameter to handle transient failures. If any unknown exception occurs during execution, PyRIT will automatically retry the failed operation (starting where it left off) up to the specified number of times. This helps ensure your scenario completes successfully even in the face of temporary issues.\n",
204+
"\n",
205+
"### Dynamic Configuration\n",
206+
"\n",
207+
"During a long-running scenario, you may want to adjust parameters like `max_concurrency` to manage resource usage, or switch your scorer to use a different target. PyRIT's resiliency features make it safe to stop, reconfigure, and continue scenarios as needed.\n",
208+
"\n",
209+
"For more information, see [resiliency](../setup/1_resiliency.ipynb)"
210+
]
186211
}
187212
],
188213
"metadata": {

doc/code/scenarios/scenarios.py

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,6 @@
66
# format_name: percent
77
# format_version: '1.3'
88
# jupytext_version: 1.17.3
9-
# kernelspec:
10-
# display_name: pyrit-dev
11-
# language: python
12-
# name: python3
139
# ---
1410

1511
# %% [markdown]
@@ -40,10 +36,10 @@
4036
#
4137
# ## How It Works
4238
#
43-
# Each `Scenario` contains a collection of `AttackRun` objects. When executed:
39+
# Each `Scenario` contains a collection of `AtomicAttack` objects. When executed:
4440
#
45-
# 1. Each `AttackRun` is executed sequentially
46-
# 2. Every `AttackRun` tests its configured attack against all specified objectives and datasets
41+
# 1. Each `AtomicAttack` is executed sequentially
42+
# 2. Every `AtomicAttack` tests its configured attack against all specified objectives and datasets
4743
# 3. Results are aggregated into a single `ScenarioResult` with all attack outcomes
4844
# 4. Optional memory labels help track and categorize the scenario execution
4945
#
@@ -83,6 +79,7 @@
8379
ScenarioCompositeStrategy(strategies=[FoundryStrategy.Caesar, FoundryStrategy.CharSwap]), # Composed strategy
8480
]
8581

82+
8683
# Create a scenario from the pre-configured Foundry scenario
8784
foundry_scenario = FoundryScenario(
8885
objective_target=objective_target,
@@ -97,3 +94,22 @@
9794
# Execute the entire scenario
9895
foundry_results = await foundry_scenario.run_async() # type: ignore
9996
await printer.print_summary_async(foundry_results) # type: ignore
97+
98+
# %% [markdown]
99+
# ## Resiliency
100+
#
101+
# Scenarios can run for a long time, and because of that, things can go wrong. Network issues, rate limits, or other transient failures can interrupt execution. PyRIT provides built-in resiliency features to handle these situations gracefully.
102+
#
103+
# ### Automatic Resume
104+
#
105+
# If you re-run a `scenario`, it will automatically start where it left off. The framework tracks completed attacks and objectives in memory, so you won't lose progress if something interrupts your scenario execution. This means you can safely stop and restart scenarios without duplicating work.
106+
#
107+
# ### Retry Mechanism
108+
#
109+
# You can utilize the `max_retries` parameter to handle transient failures. If any unknown exception occurs during execution, PyRIT will automatically retry the failed operation (starting where it left off) up to the specified number of times. This helps ensure your scenario completes successfully even in the face of temporary issues.
110+
#
111+
# ### Dynamic Configuration
112+
#
113+
# During a long-running scenario, you may want to adjust parameters like `max_concurrency` to manage resource usage, or switch your scorer to use a different target. PyRIT's resiliency features make it safe to stop, reconfigure, and continue scenarios as needed.
114+
#
115+
# For more information, see [resiliency](../setup/1_resiliency.ipynb)

doc/code/setup/0_configuration.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"id": "0",
66
"metadata": {},
77
"source": [
8-
"# Configuring PyRIT\n",
8+
"# 0. Configuring PyRIT\n",
99
"\n",
1010
"Before running PyRIT, you need to call the `initialize_pyrit` function which will set up your configuration.\n",
1111
"\n",

doc/code/setup/0_configuration.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
# ---
1010

1111
# %% [markdown]
12-
# # Configuring PyRIT
12+
# # 0. Configuring PyRIT
1313
#
1414
# Before running PyRIT, you need to call the `initialize_pyrit` function which will set up your configuration.
1515
#

0 commit comments

Comments
 (0)