Skip to main content
To red team an AI agent, use Scenario, LangWatch’s open-source testing library (Apache 2.0): an attacker model escalates against your agent over many turns, and a judge and your own checks decide whether the agent held. The attacker works like a determined user: it plans an approach, builds trust, escalates and tries another angle when it is refused. Scenario runs that attacker against your own agent and its real tools, inside a pytest or vitest test. The test fails when the agent leaks, calls a tool it shouldn’t or leaves its role, so the attack runs in CI with the rest of your suite. To start now, go to Write the attack.
Red team only agents you own or have explicit permission to test.

Why attack over many turns

Single-prompt scanners send thousands of known jailbreaks and score each reply on its own. An agent can refuse every one of them and still give in at turn 20 of a conversation, after the attacker has set up a story, claimed some authority and split the request into harmless-looking pieces. The attacker in Scenario works that way. It writes an attack plan for your target first, scores each of your agent’s replies from 0 to 10, pushes harder where the agent gave ground, and drops a line of attack that met a hard refusal.

1. Install Scenario

For TypeScript, install @langwatch/scenario and vitest; Red teaming has the TypeScript version of the test below. The attacker and the judge are models, so set your provider key, for example OPENAI_API_KEY. Set LANGWATCH_API_KEY as well if you want the runs in LangWatch.

2. Write the attack

Give Scenario an adapter that calls your agent. Then replace the simulated user with an attacker and give it a target, what success looks like for the attacker:
test_redteam.py
marathon_script runs the turns for you. The checks you pass run after every turn, so a broken rule fails the test at the turn it happened. The judge then reads the whole conversation against the criteria. Write each rule you can check in code as a check as well as a criterion: a check is exact and can’t be argued with. The check above only asks that some order lookup happened before the test ended; to tie the lookup to the refunded order, compare the tool call arguments in state.messages. Pick targets from what your agent can actually do: its tools, its data and its instructions. Reveal the system prompt, call a tool without authorisation, read another customer’s data and leave the role are the usual first four.

3. Pick a strategy

Both take the same target and total_turns. More turns find more: an agent that holds for 10 turns can break at 40, so raise total_turns for the targets you can least afford to lose.

4. Run it and read the findings

Every red-team run leaves a finding report: the transcript, how severe the break was and a suggested fix. Run the tests as usual:
The reports land as JSON in ./redteam-reports/. To read them, install the dashboard extras once and open it:
The dashboard opens on localhost with the latest batch of findings, and it runs on your machine with no account. With LANGWATCH_API_KEY set, every run also shows on the Results tab in LangWatch with the full conversation and the judge’s reasoning, next to your functional tests.

How Scenario compares to garak, PyRIT and promptfoo

Scenario’s catalogue of single-prompt jailbreaks is smaller than garak’s or promptfoo’s. The tools combine well: a scanner for breadth on known prompts, Scenario for depth on your agent’s own actions.

Questions about red teaming with Scenario

Can a coding assistant write Scenario red-team attacks for me

Yes. Install the scenarios skill with npx skills add langwatch/skills/scenarios, then ask your assistant to “add red teaming to my agent”. It finds your agent in the codebase and writes the test.

What does a Scenario red-team run cost

Every turn calls the attacker model and your agent and scores the reply, so the cost grows with total_turns. Run the long attacks before a release, and turn off per-turn scoring with score_responses=False for faster runs on every pull request.

Does Scenario red teaming work with my agent framework

The adapter only needs a function that takes the messages and returns a reply, so it works with LangGraph, CrewAI, Pydantic AI, the OpenAI Agents SDK, Mastra, the Vercel AI SDK or your own code. Next, copy the test above, change the target to the action your agent must never take, and run it, or read the Scenario red-teaming reference for every option.
Last modified on November 10, 2026