Skip to main content

AI Red Teaming Tool and Framework

Project description

AI Agents Red Teaming Framework

Overview

dtx is an advanced red teaming framework designed for analyzing agent security risks. It provides tools for creating agent security scopes and performing AI-driven risk analysis. The framework enables security professionals to evaluate the safety and integrity of AI agents and their interactions.

Additionally, dtx includes an Agents Scope Generator, which helps define and refine agent security scopes based on AI-driven assessments.

Features

  • Generate red teaming scopes
  • Perform AI-driven risk analysis
  • YAML-based scope configuration and output
  • CLI-based interaction
  • Local evaluation using SLMs or LLMs (optional)
  • Generate test cases for security analysis (optional)
  • Support for local and remote evaluation models

Installation

dtx is managed using Poetry. To install it, run:

poetry install

Installing with Additional Features

Morphius provides additional installation options via Poetry extras:

[tool.poetry.extras]
huggingface = ["detoxify"]
autogen = ["playwright", "autogen-agentchat", "autogen-ext", "tiktoken", "aiofiles"]

HuggingFace Support

Morphius also supports Hugging Face models for toxicity analysis and other NLP tasks.

To enable support for Hugging Face models, install:

poetry install --extras "huggingface"

To enable toxicity analysis using Detoxify, install:

poetry install --extras "detoxify"

AutoGen Support

For automatic agent interactions and script-based analysis, install:

poetry install --extras "autogen"

Additional Dependency Groups

Morphius includes specific dependency groups for fine-grained installation control:

AutoGen Group Dependencies

To install dependencies related to AutoGen, use:

poetry install --with autogen

HuggingFace Group Dependencies

To install dependencies related to Hugging Face models, use:

poetry install --with huggingface

Development Dependencies

For development and testing, install:

poetry install --with dev

For automatic agent interactions and script-based analysis, install:

poetry install --extras "autogen"

Quick Usage

Running Smallest Text Generation Model

To generate the required plan:

dtx redteam plan tests/samples/scope/txt_models_red_team_scope.yml redteam_plan.yml --dataset HF_LMSYS

Then, run the model:

dtx redteam run redteam_plan.yml HF_MODEL arnir0/Tiny-LLM

Create .env File and Provide API Keys

cp .env.template .env

Note: Update the API Key before proceeding.

Generate a Red Teaming Scope

To create a new red teaming scope:

poetry run dtx redteam scope "Example agent description" dtx.yml

or Use AI Agent to generate the scope. Refer to the Section Agents Scope Generator

Generate an Analysis Plan

To generate an analysis plan from a scope file:

poetry run dtx redteam plan dtx.yml plan.yml

Command Reference

redteam scope

Generate a red teaming scope with all plugins enabled:

dtx redteam scope "The Jira Toolkit for LangChain enables interaction..."

redteam plan

Run an analysis and produce a structured YAML output:

dtx redteam plan dtx.yml redteam.yml

Running Tests

Morphius includes unit and integration test cases to ensure the reliability of its features. To run the test suite, use the following commands:

Run Unit Tests

poetry run pytest tests/unit

Run Integration Tests

poetry run pytest tests/integration

These tests help verify the correctness and stability of Morphius across different modules.


Running Small LLMs for Text Generation and Classification

Morphius now supports running small LLMs locally for both text generation and classification tasks.

Generating Outputs with Small LLMs (Generate and Run the Plan)

To generate the required plan:

dtx redteam plan tests/samples/scope/txt_models_red_team_scope.yml redteam_plan.yml --dataset HF_LMSYS

Then, run the model:

dtx redteam run redteam_plan.yml HF_MODEL arnir0/Tiny-LLM

To run a small language model for red teaming:

dtx redteam run redteam_plan.yml HF_MODEL ad

dRunning a Small Model for Classification (Generate and Run the Plan)

To generate the required plan:

dtx redteam plan tests/samples/scope/toxic_bert_redteam_scope.yml redteam_plan.yml --dataset HF_LMSYS

Then, run the model:

dtx redteam run redteam_plan.yml HF_MODEL unitary/unbiased-toxic-roberta

To classify AI-generated text using a small model:

dtx redteam run redteam_plan.yml HF_MODEL unitary/unbiased-toxic-roberta

These models enable efficient on-device execution, reducing reliance on large cloud-based LLMs.


Optionally Configuring Ollama for Local LLM Execution

If you prefer running LLMs locally with Ollama, you can set up and configure Ollama for seamless integration with Morphius.

Installing Ollama

Follow the instructions to install Ollama on your system:

curl -fsSL https://ollama.ai/install.sh | sh

Running Ollama Models

After installation, run a local LLM model for inference:

ollama run mistral

Integrating Ollama with Morphius

Modify the execution command to use an Ollama-hosted model:

dtx redteam run redteam_plan.yml HF_MODEL ollama/mistral

This allows you to leverage locally hosted models for red teaming and classification tasks without needing an external API.


Generating Plans Based on Different Datasets

Morphius supports generating security test plans using various predefined datasets for structured risk assessment. Below are commands for generating test plans using different datasets.

STARGAZER Dataset

dtx redteam plan redteam_scope.yml redteam_plan_stargazer.yml --dataset STARGAZER

HF_LMSYS Dataset

dtx redteam plan redteam_scope.yml redteam_plan_hf_lmsys.yml --dataset HF_LMSYS

HF_HACKAPROMPT Dataset

dtx redteam plan redteam_scope.yml redteam_plan_hf_hackaprompt.yml --dataset HF_HACKAPROMPT

STRINGRAY Dataset

dtx redteam plan redteam_scope.yml redteam_plan_stringray.yml --dataset STRINGRAY

Agents Scope Generator

Overview

The Agents Scope Generator is a security assessment script that utilizes AI models to generate a red team scope based on the provided target. It processes information interactively and can produce structured output in YAML format.

Installation & Setup

Ensure you have Python installed and any required dependencies.

To install the extension with additional features, use:

poetry install --extras autogen

Usage

Run the script with the required parameters:

poetry run python dtx/plugins/agents/autogen/agents_scope_generator.py --target <TARGET_URL>

Example Usage

poetry run python dtx/plugins/agents/autogen/agents_scope_generator.py --target https://x.com/nft_xbt

Output

The script generates a structured YAML file containing the red team scope details, which can be used for further analysis.

Notes

  • Ensure you have API access to the AI model specified (gpt-4o by default).
  • The interactive mode may require user input during execution.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dtx-0.13.0.tar.gz (614.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dtx-0.13.0-py3-none-any.whl (698.6 kB view details)

Uploaded Python 3

File details

Details for the file dtx-0.13.0.tar.gz.

File metadata

  • Download URL: dtx-0.13.0.tar.gz
  • Upload date:
  • Size: 614.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.2 CPython/3.11.8 Linux/6.8.0-1021-azure

File hashes

Hashes for dtx-0.13.0.tar.gz
Algorithm Hash digest
SHA256 d2232245cd19f3a5b5a6540790c8ebbc888dd33eee40758f20b47ee0d3aa684e
MD5 de157714d593907fea9a1bfaee0b0ce0
BLAKE2b-256 c2553d9eddf52a535684d487a25d569618fe57c49d4a7a8a6b2ed9238dc533f5

See more details on using hashes here.

File details

Details for the file dtx-0.13.0-py3-none-any.whl.

File metadata

  • Download URL: dtx-0.13.0-py3-none-any.whl
  • Upload date:
  • Size: 698.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.2 CPython/3.11.8 Linux/6.8.0-1021-azure

File hashes

Hashes for dtx-0.13.0-py3-none-any.whl
Algorithm Hash digest
SHA256 82f4fa76ca2e87085d5463d14c5d792575ea9f163062426e720eafec21c7b735
MD5 b930b6e3013212998d4e5decb45ea34b
BLAKE2b-256 cc305e83b5459511e06b88d551c4628d0a0be1c8eb6b1b3666895de63a06f539

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page