Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Modality feedback in multi-turn attacks (Crescendo example)

This notebook shows how attacks such as CrescendoAttack, RedTeamingAttack, and TAPAttack use target capabilities to decide whether media should be forwarded turn-to-turn.

We use a two-seed image-editing setup:

  • seed 1: roakey.png

  • seed 2: a real photo of a three-masted ship

and an intentionally detailed objective:

show the character from seed 1 boarding the three-masted ship from seed 2 at night, hanging upside down from a scarlet rope and yelling, while a turquoise clockwork albatross with brass wings holds a red key in its beak atop the center mast.

The Crescendo image-generation system prompt starts with a benign base composition without previewing later details, then introduces bounded refinements in later turns. The same modality wiring applies across Crescendo, Red Teaming, and TAP; we run Crescendo end-to-end here.

Found default environment files: ['./.pyrit/.env', './.pyrit/.env.local']
Loaded environment file: ./.pyrit/.env
Loaded environment file: ./.pyrit/.env.local
[pyrit:alembic] No new upgrade operations detected.

1) Choose objective-target capability profile

This controls how media is handled in the attack loop:

  • "edit-only": requires text + image_path every turn.

  • "hybrid": accepts either text-only or text + image_path; this seeded example uses media.

Objective capability profile: hybrid
Objective input modalities: frozenset({frozenset({'image_path', 'text'}), frozenset({'text'})})

2) Build adversarial target and inspect whether it can receive image feedback

The modality router checks this up front. If the adversarial target advertises {"text", "image_path"} input, the objective image output can be forwarded along with score feedback; otherwise only text feedback is sent.

Adversarial input modalities: frozenset({frozenset({'image_path', 'text'}), frozenset({'text'}), frozenset({'image_path'})})
Adversarial accepts text+image feedback: True

3) Prepare the two seed images

  • roakey.png is loaded from the docs root.

  • A modern color photo of a three-masted ship is loaded from a checked-in asset.

  • Ship photo source: Gorch Fock unter Segeln Kieler Foerde 2006 (Wikimedia Commons), licensed under CC BY-SA 2.5.

Seed 1 (roakey): ./git/copilot-worktrees/PyRIT/romanlutz-bookish-disco/doc/roakey.png
Seed 2 (ship photo): ./git/copilot-worktrees/PyRIT/romanlutz-bookish-disco/doc/code/executor/assets/three_masted_ship_color.jpg

4) Create a seed message with adversarial placeholder + two images

The first text piece is an adversarial placeholder. The attack fills it with the generated prompt, while preserving the two seed images.

5) Define objective + scorer and execute Crescendo

The scorer checks visible final-image criteria jointly. It does not receive the seed images, so it deliberately avoids claiming exact pixel-level identity with either reference. The unusual albatross-and-key detail makes accidental first-turn success unlikely while giving Crescendo several independent details to introduce progressively. The objective target receives its previously generated image as the edit input rather than receiving the two original seeds again.

<IPython.core.display.Image object>
<IPython.core.display.Image object>
<IPython.core.display.Image object>
<IPython.core.display.Image object>
<IPython.core.display.Image object>
<IPython.core.display.Image object>
<IPython.core.display.Image object>
<IPython.core.display.Image object>
<IPython.core.display.Image object>
<IPython.core.display.Image object>
<IPython.core.display.Image object>
Fetching long content....

6) The same pattern for Red Teaming and TAP

To run this with RedTeamingAttack or TAPAttack, keep:

  • the same objective_target capability profile,

  • the same next_message with adversarial placeholder + two seeds,

  • an image-capable scoring setup.

Then swap only the attack class and (optionally) the adversarial system prompt.