Metadata-Version: 2.4
Name: decodingtrust-agent-sdk
Version: 0.2.6
Summary: DecodingTrust Agent Platform (DTap) — A controllable and interactive red-teaming platform for AI agents
Author-email: DTap Team <zhaorun@uchicago.edu>
License:                                  Apache License
                                   Version 2.0, January 2004
                                http://www.apache.org/licenses/
        
           TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
        
           1. Definitions.
        
              "License" shall mean the terms and conditions for use, reproduction,
              and distribution as defined by Sections 1 through 9 of this document.
        
              "Licensor" shall mean the copyright owner or entity authorized by
              the copyright owner that is granting the License.
        
              "Legal Entity" shall mean the union of the acting entity and all
              other entities that control, are controlled by, or are under common
              control with that entity. For the purposes of this definition,
              "control" means (i) the power, direct or indirect, to cause the
              direction or management of such entity, whether by contract or
              otherwise, or (ii) ownership of fifty percent (50%) or more of the
              outstanding shares, or (iii) beneficial ownership of such entity.
        
              "You" (or "Your") shall mean an individual or Legal Entity
              exercising permissions granted by this License.
        
              "Source" form shall mean the preferred form for making modifications,
              including but not limited to software source code, documentation
              source, and configuration files.
        
              "Object" form shall mean any form resulting from mechanical
              transformation or translation of a Source form, including but
              not limited to compiled object code, generated documentation,
              and conversions to other media types.
        
              "Work" shall mean the work of authorship, whether in Source or
              Object form, made available under the License, as indicated by a
              copyright notice that is included in or attached to the work
              (an example is provided in the Appendix below).
        
              "Derivative Works" shall mean any work, whether in Source or Object
              form, that is based on (or derived from) the Work and for which the
              editorial revisions, annotations, elaborations, or other modifications
              represent, as a whole, an original work of authorship. For the purposes
              of this License, Derivative Works shall not include works that remain
              separable from, or merely link (or bind by name) to the interfaces of,
              the Work and Derivative Works thereof.
        
              "Contribution" shall mean any work of authorship, including
              the original version of the Work and any modifications or additions
              to that Work or Derivative Works thereof, that is intentionally
              submitted to Licensor for inclusion in the Work by the copyright owner
              or by an individual or Legal Entity authorized to submit on behalf of
              the copyright owner. For the purposes of this definition, "submitted"
              means any form of electronic, verbal, or written communication sent
              to the Licensor or its representatives, including but not limited to
              communication on electronic mailing lists, source code control systems,
              and issue tracking systems that are managed by, or on behalf of, the
              Licensor for the purpose of discussing and improving the Work, but
              excluding communication that is conspicuously marked or otherwise
              designated in writing by the copyright owner as "Not a Contribution."
        
              "Contributor" shall mean Licensor and any individual or Legal Entity
              on behalf of whom a Contribution has been received by Licensor and
              subsequently incorporated within the Work.
        
           2. Grant of Copyright License. Subject to the terms and conditions of
              this License, each Contributor hereby grants to You a perpetual,
              worldwide, non-exclusive, no-charge, royalty-free, irrevocable
              copyright license to reproduce, prepare Derivative Works of,
              publicly display, publicly perform, sublicense, and distribute the
              Work and such Derivative Works in Source or Object form.
        
           3. Grant of Patent License. Subject to the terms and conditions of
              this License, each Contributor hereby grants to You a perpetual,
              worldwide, non-exclusive, no-charge, royalty-free, irrevocable
              (except as stated in this section) patent license to make, have made,
              use, offer to sell, sell, import, and otherwise transfer the Work,
              where such license applies only to those patent claims licensable
              by such Contributor that are necessarily infringed by their
              Contribution(s) alone or by combination of their Contribution(s)
              with the Work to which such Contribution(s) was submitted. If You
              institute patent litigation against any entity (including a
              cross-claim or counterclaim in a lawsuit) alleging that the Work
              or a Contribution incorporated within the Work constitutes direct
              or contributory patent infringement, then any patent licenses
              granted to You under this License for that Work shall terminate
              as of the date such litigation is filed.
        
           4. Redistribution. You may reproduce and distribute copies of the
              Work or Derivative Works thereof in any medium, with or without
              modifications, and in Source or Object form, provided that You
              meet the following conditions:
        
              (a) You must give any other recipients of the Work or
                  Derivative Works a copy of this License; and
        
              (b) You must cause any modified files to carry prominent notices
                  stating that You changed the files; and
        
              (c) You must retain, in the Source form of any Derivative Works
                  that You distribute, all copyright, patent, trademark, and
                  attribution notices from the Source form of the Work,
                  excluding those notices that do not pertain to any part of
                  the Derivative Works; and
        
              (d) If the Work includes a "NOTICE" text file as part of its
                  distribution, then any Derivative Works that You distribute must
                  include a readable copy of the attribution notices contained
                  within such NOTICE file, excluding those notices that do not
                  pertain to any part of the Derivative Works, in at least one
                  of the following places: within a NOTICE text file distributed
                  as part of the Derivative Works; within the Source form or
                  documentation, if provided along with the Derivative Works; or,
                  within a display generated by the Derivative Works, if and
                  wherever such third-party notices normally appear. The contents
                  of the NOTICE file are for informational purposes only and
                  do not modify the License. You may add Your own attribution
                  notices within Derivative Works that You distribute, alongside
                  or as an addendum to the NOTICE text from the Work, provided
                  that such additional attribution notices cannot be construed
                  as modifying the License.
        
              You may add Your own copyright statement to Your modifications and
              may provide additional or different license terms and conditions
              for use, reproduction, or distribution of Your modifications, or
              for any such Derivative Works as a whole, provided Your use,
              reproduction, and distribution of the Work otherwise complies with
              the conditions stated in this License.
        
           5. Submission of Contributions. Unless You explicitly state otherwise,
              any Contribution intentionally submitted for inclusion in the Work
              by You to the Licensor shall be under the terms and conditions of
              this License, without any additional terms or conditions.
              Notwithstanding the above, nothing herein shall supersede or modify
              the terms of any separate license agreement you may have executed
              with Licensor regarding such Contributions.
        
           6. Trademarks. This License does not grant permission to use the trade
              names, trademarks, service marks, or product names of the Licensor,
              except as required for reasonable and customary use in describing the
              origin of the Work and reproducing the content of the NOTICE file.
        
           7. Disclaimer of Warranty. Unless required by applicable law or
              agreed to in writing, Licensor provides the Work (and each
              Contributor provides its Contributions) on an "AS IS" BASIS,
              WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
              implied, including, without limitation, any warranties or conditions
              of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
              PARTICULAR PURPOSE. You are solely responsible for determining the
              appropriateness of using or redistributing the Work and assume any
              risks associated with Your exercise of permissions under this License.
        
           8. Limitation of Liability. In no event and under no legal theory,
              whether in tort (including negligence), contract, or otherwise,
              unless required by applicable law (such as deliberate and grossly
              negligent acts) or agreed to in writing, shall any Contributor be
              liable to You for damages, including any direct, indirect, special,
              incidental, or consequential damages of any character arising as a
              result of this License or out of the use or inability to use the
              Work (including but not limited to damages for loss of goodwill,
              work stoppage, computer failure or malfunction, or any and all
              other commercial damages or losses), even if such Contributor
              has been advised of the possibility of such damages.
        
           9. Accepting Warranty or Additional Liability. While redistributing
              the Work or Derivative Works thereof, You may choose to offer,
              and charge a fee for, acceptance of support, warranty, indemnity,
              or other liability obligations and/or rights consistent with this
              License. However, in accepting such obligations, You may act only
              on Your own behalf and on Your sole responsibility, not on behalf
              of any other Contributor, and only if You agree to indemnify,
              defend, and hold each Contributor harmless for any liability
              incurred by, or claims asserted against, such Contributor by reason
              of your accepting any such warranty or additional liability.
        
           END OF TERMS AND CONDITIONS
        
           APPENDIX: How to apply the Apache License to your work.
        
              To apply the Apache License to your work, attach the following
              boilerplate notice, with the fields enclosed by brackets "[]"
              replaced with your own identifying information. (Don't include
              the brackets!)  The text should be enclosed in the appropriate
              comment syntax for the file format. We also recommend that a
              file or class name and description of purpose be included on the
              same "printed page" as the copyright notice for easier
              identification within third-party archives.
        
           Copyright [yyyy] [name of copyright owner]
        
           Licensed under the Apache License, Version 2.0 (the "License");
           you may not use this file except in compliance with the License.
           You may obtain a copy of the License at
        
               http://www.apache.org/licenses/LICENSE-2.0
        
           Unless required by applicable law or agreed to in writing, software
           distributed under the License is distributed on an "AS IS" BASIS,
           WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
           See the License for the specific language governing permissions and
           limitations under the License.
        
Project-URL: Homepage, https://decodingtrust-agent.com
Project-URL: Documentation, https://decodingtrust-agent.com/docs
Project-URL: Repository, https://github.com/AI-secure/DecodingTrust-Agent
Project-URL: Bug Tracker, https://github.com/AI-secure/DecodingTrust-Agent/issues
Keywords: AI safety,red-teaming,LLM,agents,benchmark,MCP,prompt injection
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Science/Research
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Classifier: Topic :: Security
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: mcp>=1.0.0
Requires-Dist: fastmcp>=2.0.0
Requires-Dist: pydantic>=2.0
Requires-Dist: pydantic-settings>=2.0
Requires-Dist: PyYAML>=6.0
Requires-Dist: python-dotenv>=1.0.0
Requires-Dist: aiohttp>=3.9.0
Requires-Dist: aiofiles>=22.0
Requires-Dist: httpx>=0.27.0
Requires-Dist: requests>=2.28.0
Requires-Dist: websockets>=10.0
Requires-Dist: anyio>=3.6.0
Requires-Dist: fastapi>=0.100.0
Requires-Dist: uvicorn>=0.20.0
Requires-Dist: starlette>=0.27.0
Requires-Dist: typer>=0.12.0
Requires-Dist: click>=8.0.0
Requires-Dist: rich>=13.0.0
Requires-Dist: pandas>=2.0.0
Requires-Dist: psutil>=5.9.0
Requires-Dist: huggingface_hub>=0.20.0
Provides-Extra: openai
Requires-Dist: openai>=2.6.1; extra == "openai"
Requires-Dist: openai-agents>=0.8.4; extra == "openai"
Requires-Dist: openapi-pydantic>=0.5.1; extra == "openai"
Provides-Extra: claude
Requires-Dist: anthropic>=0.18.0; extra == "claude"
Requires-Dist: claude-agent-sdk>=0.1.18; extra == "claude"
Requires-Dist: claude-code-sdk>=0.0.25; extra == "claude"
Provides-Extra: google
Requires-Dist: google-adk>=1.27.5; extra == "google"
Requires-Dist: a2a-sdk<0.4.0,>=0.3.22; extra == "google"
Requires-Dist: google-generativeai>=0.3.0; extra == "google"
Requires-Dist: google-genai>=1.0.0; extra == "google"
Requires-Dist: google-api-core>=2.28.0; extra == "google"
Requires-Dist: google-api-python-client>=2.100.0; extra == "google"
Provides-Extra: strands
Requires-Dist: strands-agents>=1.40.0; extra == "strands"
Provides-Extra: langchain
Requires-Dist: langchain>=0.3.0; extra == "langchain"
Requires-Dist: langchain-core>=0.3.0; extra == "langchain"
Requires-Dist: langchain-openai>=0.2.0; extra == "langchain"
Requires-Dist: langchain-anthropic>=0.2.0; extra == "langchain"
Provides-Extra: pocketflow
Requires-Dist: pocketflow==0.0.3; extra == "pocketflow"
Provides-Extra: all
Requires-Dist: decodingtrust-agent-sdk[claude,google,langchain,openai,pocketflow,strands]; extra == "all"
Provides-Extra: dev
Requires-Dist: pytest>=7.0; extra == "dev"
Requires-Dist: pytest-asyncio>=0.21; extra == "dev"
Requires-Dist: ruff>=0.1.0; extra == "dev"
Requires-Dist: build>=0.10; extra == "dev"
Requires-Dist: twine>=4.0; extra == "dev"
Dynamic: license-file

<div align="center">

<img src="https://raw.githubusercontent.com/AI-secure/DecodingTrust-Agent/main/dt-logo-new.png" alt="DecodingTrust-Agent" width="180"/>

# DecodingTrust-Agent Platform (DTAP)

**A Controllable and Interactive Red-Teaming Platform for AI Agents**

[![GitHub Repo stars](https://img.shields.io/github/stars/AI-secure/DecodingTrust-Agent?style=social)](https://github.com/AI-secure/DecodingTrust-Agent/stargazers)
[![GitHub last commit](https://img.shields.io/github/last-commit/AI-secure/DecodingTrust-Agent)](https://github.com/AI-secure/DecodingTrust-Agent/commits/main)
[![GitHub contributors](https://img.shields.io/github/contributors/AI-secure/DecodingTrust-Agent?color=orange)](https://github.com/AI-secure/DecodingTrust-Agent/graphs/contributors)
[![License](https://img.shields.io/github/license/AI-secure/DecodingTrust-Agent)](https://github.com/AI-secure/DecodingTrust-Agent/blob/main/LICENSE)
[![Website](https://img.shields.io/badge/website-decodingtrust--agent.com-blue)](https://decodingtrust-agent.com)
[![Paper](https://img.shields.io/badge/paper-DTAP-b31b1b)](https://decodingtrust-agent.com)

**14 real-world domains · 50+ simulation environments · autonomous red-teaming · verifiable judges**

</div>

---

## About

DTAP is the first controllable and interactive red-teaming platform for AI agents, spanning **14 real-world domains** and **50+ simulation environments** that replicate widely-used systems such as Google Workspace, PayPal, and Slack. To scale the risk assessment of agents, we further propose **DTAP-RED**, the first autonomous red-teaming agent that systematically explores diverse injection vectors (prompt, tool, skill, environment, and combinations) and autonomously discovers effective attack strategies tailored to varying malicious goals. Using DTAP-RED, we curate **DTAP-BENCH**, a large-scale red-teaming dataset of high-quality instances across domains, each paired with a verifiable judge that automatically validates attack outcomes against the corresponding security policy.

> *Zhaorun Chen, Xun Liu, Haibo Tong, Chengquan Guo, Yuzhou Nie, Jiawei Zhang, Mintong Kang, Chejian Xu, Qichang Liu, Xiaogeng Liu, Tianneng Shi, Chaowei Xiao, Sanmi Koyejo, Percy Liang, Wenbo Guo, Dawn Song, Bo Li.*
> Virtue AI · University of Chicago · UIUC · UCSB · Johns Hopkins · UC Berkeley · Stanford

Website: <https://decodingtrust-agent.com>

---

## Table of Contents

- [Installation](#installation)
- [Quick Start](#quick-start)
- [Running the Default Benchmark](#running-the-default-benchmark)
  - [A single domain](#a-single-domain)
  - [A single task list (benign / direct / indirect)](#a-single-task-list-benign--direct--indirect)
  - [The entire benchmark](#the-entire-benchmark)
- [Customizing Your Own Task List](#customizing-your-own-task-list)
- [`eval/evaluation.py` CLI Reference](#evalevaluationpy-cli-reference)
- [Supported Domains](#supported-domains)
- [Integrating a Custom Agent](#integrating-a-custom-agent)
- [Tool-Call Hooks](#tool-call-hooks)
- [Citation](#citation)

---

## Installation

```bash
git clone https://github.com/AI-secure/DecodingTrust-Agent.git
cd DecodingTrust-Agent
pip install -r requirements.txt
pip install -e .
```

Set the API key for your backbone model (only the providers you actually use are required):

```bash
export OPENAI_API_KEY=sk-...
export ANTHROPIC_API_KEY=sk-ant-...
export GOOGLE_API_KEY=...
```

Docker is required: each task spins up isolated MCP servers and Docker-based environments through `TaskExecutor`.

---

## Quick Start

A single benign CRM task with the OpenAI Agents SDK backbone:

```bash
python eval/evaluation.py \
  --task-list benchmark/crm/benign.jsonl \
  --agent-type openaisdk \
  --model gpt-4o \
  --max-parallel 4
```

Results are written to `results/benchmark/<agent_type>/<model>/<domain>/<type>/<task_id>/` (overridable with `EVAL_RESULTS_ROOT`).

---

## Running the Default Benchmark

DTAP-BENCH ships pre-curated task lists under [`benchmark/`](benchmark/). Each domain has three files:

| File | Threat model | What it contains |
|---|---|---|
| `benign.jsonl` | — | Benign workflow tasks (utility evaluation) |
| `direct.jsonl` | Direct prompt injection | Adversary controls the user prompt |
| `indirect.jsonl` | Indirect (tool / env / data) | Payload arrives via tool output, document, email, etc. |

Each line in these files is a single task record, e.g.:

```jsonl
{"domain": "crm", "type": "benign", "task_id": "1"}
{"domain": "crm", "type": "malicious", "threat_model": "direct",   "risk_category": "dangerous-actions", "task_id": "1"}
{"domain": "crm", "type": "malicious", "threat_model": "indirect", "risk_category": "dangerous-actions", "task_id": "1"}
```

These records resolve to:
- Benign → `dataset/<domain>/benign/<task_id>/`
- Malicious → `dataset/<domain>/malicious/<threat_model>/<risk_category>/<task_id>/`

### A single domain

Run every benign + direct + indirect task in a domain by pointing `--task-list` at the domain folder:

```bash
python eval/evaluation.py \
  --task-list benchmark/finance \
  --agent-type openaisdk \
  --model gpt-4o \
  --max-parallel 8
```

`eval/evaluation.py` auto-discovers every `*.jsonl` under that directory and runs them in one pass with environment reuse.

### A single task list (benign / direct / indirect)

```bash
# Benign utility only
python eval/evaluation.py --task-list benchmark/crm/benign.jsonl --agent-type openaisdk --model gpt-4o

# Direct prompt injection only
python eval/evaluation.py --task-list benchmark/crm/direct.jsonl --agent-type claudesdk --model claude-sonnet-4-20250514

# Indirect injection only
python eval/evaluation.py --task-list benchmark/crm/indirect.jsonl --agent-type googleadk --model gemini-2.0-flash
```

You can further narrow execution with filters that operate on the loaded records:

```bash
python eval/evaluation.py \
  --task-list benchmark/crm \
  --task-type malicious \
  --threat-model indirect \
  --risk-category data-exfiltration \
  --agent-type openaisdk --model gpt-4o
```

### The entire benchmark

Point `--task-list` at the top-level [`benchmark/`](benchmark/) directory to run all 14 domains:

```bash
python eval/evaluation.py \
  --task-list benchmark \
  --agent-type openaisdk \
  --model gpt-4o \
  --max-parallel 16 \
  --skip-existing
```

`--skip-existing` skips any task that already has a `judge_result.json`, so the same command resumes a partially-finished run.

---

## Customizing Your Own Task List

Any JSONL file with the schema below is a valid `--task-list`. Pick a subset of tasks, mix domains, or focus on one risk category — there is no separate registration step.

**Schema:**

| Field | Required | Description |
|---|---|---|
| `domain` | always | One of the supported domains (see below) |
| `type` | always | `"benign"` or `"malicious"` |
| `task_id` | always | Identifier; matches the directory name under `dataset/…/<task_id>/` |
| `threat_model` | malicious only | `"direct"` or `"indirect"` |
| `risk_category` | malicious only | e.g. `"data-exfiltration"`, `"dangerous-actions"`, `"social-scoring"`, `"manipulative-use"` |

**Example — `my_subset.jsonl`** (mix of domains and risk categories, useful for smoke tests):

```jsonl
{"domain": "crm",     "type": "benign",    "task_id": "1"}
{"domain": "finance", "type": "malicious", "threat_model": "direct",   "risk_category": "dangerous-actions",    "task_id": "5"}
{"domain": "gmail",   "type": "malicious", "threat_model": "indirect", "risk_category": "data-exfiltration",    "task_id": "12"}
{"domain": "legal",   "type": "malicious", "threat_model": "indirect", "risk_category": "manipulative-use",     "task_id": "3"}
```

Run it like any built-in task list:

```bash
python eval/evaluation.py --task-list my_subset.jsonl --agent-type openaisdk --model gpt-4o --max-parallel 4
```

A few practical patterns:

```bash
# Curate from an existing file
grep '"risk_category": "data-exfiltration"' benchmark/crm/indirect.jsonl > my_crm_exfil.jsonl
python eval/evaluation.py --task-list my_crm_exfil.jsonl --agent-type openaisdk --model gpt-4o

# Try just one task end-to-end
echo '{"domain": "crm", "type": "benign", "task_id": "1"}' > one_task.jsonl
python eval/evaluation.py --task-list one_task.jsonl --agent-type openaisdk --model gpt-4o
```

For per-task internals (`config.yaml`, `judge.py`, `setup.sh`), see [docs/quickstart.md](docs/quickstart.md).

---

## `eval/evaluation.py` CLI Reference

| Argument | Default | Description |
|---|---|---|
| `--task-list` | **required** | Path to a JSONL file *or* a directory containing JSONL files |
| `--domain` | `None` | Keep only records whose `domain` matches |
| `--task-type` | `None` | `benign` or `malicious` |
| `--threat-model` | `None` | `direct` or `indirect` |
| `--risk-category` | `None` | e.g. `data-exfiltration` |
| `--max-parallel` | `5` | Concurrent tasks (environments are reused across tasks) |
| `--agent-type` | `openaisdk` | `openaisdk`, `claudesdk`, `googleadk`, `langchain`, `pocketflow`, `openclaw` |
| `--model` | `gpt-4o` | Backbone model identifier |
| `--temperature` | `None` | Sampling temperature (model default if unset) |
| `--port-range` | `None` | Dynamic MCP port range, e.g. `"10000-12000"` |
| `--direct-prompt` | off | For direct threat model, use the malicious goal as-is instead of replaying attack turns |
| `--disallowed-tools` | `None` | Native tools to disable (filesystem tasks have sensible defaults) |
| `--skip-existing` | off | Skip tasks that already have `judge_result.json` |
| `--skip-mcp` | off | Skip MCP server startup (debug) |
| `--skip-judge` | off | Skip judge after task completion (debug) |
| `--keep-envs` | off | Keep Docker envs running after the run (debug) |
| `--debug` | off | Save extra trajectory diagnostics |

Relevant environment variables:

| Variable | Description |
|---|---|
| `OPENAI_API_KEY` / `ANTHROPIC_API_KEY` / `GOOGLE_API_KEY` | Provider keys |
| `EVAL_RESULTS_ROOT` | Output root (default `results/`); layout `{root}/benchmark/{agent_type}/{model}/{dataset_path}/` |
| `DT_PORT_RANGE` / `DT_PORT_DB` | Port allocation for MCP / Docker |

---

## Supported Domains

The 14 domains shipped with DTAP-BENCH:

`browser` · `code` · `crm` · `customer-service` · `finance` · `legal` · `macos` · `medical` · `os-filesystem` · `research` · `telecom` · `travel` · `windows` · `workflow`

Each domain mounts one or more MCP-backed environments (e.g. Salesforce, Gmail, PayPal, Slack, Atlassian, BigQuery, Snowflake, Databricks, GitHub, Google Docs, Booking, hospital, telecom, terminal, Windows / macOS shells). The full mapping lives in [`dt_arena/config/mcp.yaml`](dt_arena/config/mcp.yaml).

---

## Integrating a Custom Agent

DTAP supports two integration modes.

### Option A — Use a pre-built native agent (recommended)

If you already have an agent written in one of the supported SDKs (OpenAI Agents SDK, LangChain, Claude SDK, Google ADK), wrap it with `build_agent`. Your existing tools / MCP servers stay attached; DTAP only **adds** the benchmark MCP servers (and any tool injections defined by the task) to a *clone* of your agent — the original is preserved.

```python
import asyncio
from agents import Agent as OpenAIAgent          # your SDK
from utils.agent_helpers import build_agent
from dt_arena.src.types.agent import AgentConfig, RuntimeConfig

async def main():
    # 1. Your pre-built agent (any extra tools / MCP servers are kept untouched)
    native = OpenAIAgent(
        name="MyAgent",
        instructions="You are a helpful CRM assistant.",
        model="gpt-4o",
        mcp_servers=[my_custom_server],
    )

    # 2. Load the benchmark task config (adds salesforce, gmail, etc.)
    agent_cfg   = AgentConfig.from_yaml("dataset/crm/benign/1/config.yaml")
    runtime_cfg = RuntimeConfig(model="gpt-4o", temperature=0.1, max_turns=200,
                                output_dir="./results")

    # 3. Wrap — auto-detects OpenAI SDK / LangChain / Claude SDK / Google ADK
    agent = build_agent(native_agent=native, agent_cfg=agent_cfg, runtime_cfg=runtime_cfg)

    async with agent:
        result = await agent.run("List all leads in my account",
                                 metadata={"task_id": "demo", "domain": "crm"})
        print(result.final_output)

    assert agent.native_agent is native  # original is untouched

asyncio.run(main())
```

### Option B — Implement a new agent backend

To plug a brand-new framework into `eval/evaluation.py`, subclass `Agent` and add a directory under [`agent/`](agent/) (mirroring `agent/openaisdk/`, `agent/claudesdk/`, etc.):

```python
from typing import Any, Union, List
from dt_arena.src.types.agent import Agent, MCPServerConfig

class MyNewAgent(Agent):
    async def initialize(self) -> None:
        await self.load_mcp_servers()       # connects to all task-declared MCP servers

    def _create_mcp_server(self, cfg: MCPServerConfig) -> Any:
        ...                                  # return your SDK-specific MCP client

    async def run(self, user_input: Union[str, List[str]], metadata=None) -> Any:
        inputs = [user_input] if isinstance(user_input, str) else user_input
        for turn in inputs:
            ...                              # execute one turn, append to trajectory
        return self.get_result()

    async def cleanup(self) -> None:
        self.reset_conversation()
```

Register the new framework name (e.g. `mynewagent`) in [`agent/__init__.py`](agent/__init__.py) and the evaluation driver will accept `--agent-type mynewagent`. Full interface, multi-turn semantics, and trajectory schema are documented in [`agent/README.md`](agent/README.md).

---

## Tool-Call Hooks

Every MCP tool call made by every supported framework flows through a shared pre/post hook system in `dt_arena`. Hooks are configured in a single JSON file and auto-loaded by every agent — no framework wiring, no CLI flags.

Enable hooks by editing [`dt_arena/src/hooks/hooks.json`](dt_arena/src/hooks/hooks.json):

```json
{
  "hooks": [
    "dt_arena.src.hooks.audit_log:AuditHook"
  ]
}
```

Write a hook by dropping a file under `dt_arena/src/hooks/`:

```python
from dt_arena.src.types.hooks import ToolCallContext, ToolCallResult

class MyHook:
    async def on_pre_tool_call(self, ctx: ToolCallContext):
        print(f"calling {ctx.framework}/{ctx.server}/{ctx.tool_name}")

    async def on_post_tool_call(self, ctx: ToolCallContext, result: ToolCallResult):
        print(f"done in {result.duration:.3f}s, error={result.is_error}")
```

See [`dt_arena/src/hooks/audit_log.py`](dt_arena/src/hooks/audit_log.py) for a complete working example, and [docs/hooks.md](docs/hooks.md) for the protocol, parallel-dispatch behavior, and known caveats.

---

## Citation

If you find DTAP useful for your research, please cite:

```bibtex
@article{chen2026decodingtrust,
  title={DecodingTrust-Agent Platform (DTap): A Controllable and Interactive Red-Teaming Platform for AI Agents},
  author={Chen, Zhaorun and Liu, Xun and Tong, Haibo and Guo, Chengquan and Nie, Yuzhou and Zhang, Jiawei and Kang, Mintong and Xu, Chejian and Liu, Qichang and Liu, Xiaogeng and others},
  journal={arXiv preprint arXiv:2605.04808},
  year={2026}
}
```

## License

See [LICENSE](LICENSE).
