Initialization
Storage instance on init.
Mode Dispatching
Therun() method checks the attack’s mode and calls the right execution method:
run_single
Handles single-turn attacks. Generates prompts, sends each one independently, evaluates, and stores.run_multi_turn
Handles multi-turn attacks. Sends turns sequentially, building conversation context.run_tool_use
Handles tool-use attacks. Sends messages with tool definitions, records tool calls, simulates tool responses, and evaluates whether the model attempted dangerous actions.evaluate_tool_calls() instead of the standard evaluate() - checks for sensitive file access, destructive commands, data exfiltration, etc.
run_batch_parallel
Runs multiple attacks in parallel usingasyncio. Each attack gets its own thread with its own Engine instance (for thread-safe SQLite access).
- Uses
asyncio.Semaphoreto limit concurrency tomax_workers - Each attack runs in a separate thread via
asyncio.to_thread - Each thread creates its own
Engineinstance (same db_path) on_completecallback fires after each attack finishes (used for progress bars)- Errors are caught per-attack - one failure doesn’t crash the batch
Error Handling
Every prompt/turn is wrapped in try/except. If a single prompt fails:- The error is logged
- The result is recorded with
verdict="ERROR"andconfidence=0.0 - The batch continues with the next prompt
Source
src/ai-blackteam/engine.py