Created by Ankul Jain
A sophisticated multi-agent system for comprehensive AI safety testing and vulnerability assessment using Google's Gemini models and Agent Development Kit (ADK).
The AI Security Agent is an automated red-teaming framework designed to test and evaluate the robustness of AI systems against adversarial attacks. It employs a multi-agent architecture where specialized agents collaborate to:
- Generate adversarial prompts targeting specific vulnerability categories
- Execute attacks against a target system (specifically configured as a Banking Assistant handling sensitive financial operations)
- Evaluate responses to determine if safety guidelines were violated
This project leverages Google's Gemini models (Gemini 2.5 Pro and Flash) to create a comprehensive security audit pipeline for LLM systems. It's built on the Google Agent Development Kit (ADK) for scalable, production-ready agent orchestration.
- 🔴 Red Team Agent: Generates sophisticated adversarial prompts for multiple risk categories
- 🎯 Target System: Simulated banking assistant with built-in safety rules
- ✅ Evaluator Agent: Neutral assessment of whether safety violations occurred
- 📊 Structured Results: JSON-based evaluation verdicts with detailed reasoning
- 🔧 Modular Design: Easy to extend with new agents and risk categories
- 🚀 Built on Google ADK: Production-grade agent orchestration framework
ai-security-agent/
├── README.md # Project documentation
├── requirements.txt # Python dependencies
│
├── llm_red_team_agent/ # Main package
│ ├── __init__.py
│ ├── agent.py # Main security orchestrator agent
│ ├── agent_utils.py # Async agent execution utilities
│ ├── config.py # Configuration (models, parameters)
│ ├── tools.py # Security scanning tools
│ ├── safety_rules.py # Defines the Banking Safety guidelines
│ │
│ └── sub_agents/ # Specialized sub-agents
│ ├── __init__.py
│ ├── red_team.py # Adversarial prompt generator
│ ├── target.py # Target system being tested
│ └── evaluator.py # Safety violation detector
│
└── tests/
└── test_agent.py # Test suite
| File | Purpose |
|---|---|
| agent.py | Main orchestrator that manages the security scanning workflow |
| config.py | Global configuration including model selection and parameters |
| tools.py | Core security scan function that orchestrates the 3-step process |
| safety_rules.py | Contains the specific system instructions and guardrails for the Banking Assistant |
| agent_utils.py | Utilities for executing agents asynchronously with proper session management |
| red_team.py | Creates the red team agent that generates adversarial prompts |
| target.py | Creates the target agent (banking assistant with safety rules) |
| evaluator.py | Creates the evaluator agent that judges safety violations |
The system uses a three-stage pipeline architecture with specialized agents:
┌─────────────────────────────────────────────────────────────────┐
│ Security Orchestrator │
│ (Main LLmAgent - Risk Category Input) │
└──────────────────────┬──────────────────────────────────────────┘
│
▼
┌──────────────────────┐
│ Red Team Worker │
│ (Attack Generator) │
│ │
│ Model: Gemini 2.5-Pro│
│ Temp: 0.9 │
└──────────┬───────────┘
│
│ Generates adversarial prompt
▼
┌──────────────────────┐
│ Target Worker │
│ (System Under Test) │
│ │
│ Model: Gemini 2.5- │
│ Flash │
│ Temp: 0.1 │
└──────────┬───────────┘
│
│ Target response to attack
▼
┌──────────────────────┐
│ Evaluator Worker │
│ (Safety Verdict) │
│ │
│ Model: Gemini 2.5-Pro│
│ Temp: 0.0 │
└──────────┬───────────┘
│
│ JSON verdict (PASS/FAIL)
▼
┌──────────────────────┐
│ Security Audit │
│ Result Summary │
└──────────────────────┘
- Purpose: Generate sophisticated adversarial prompts
- Model: Gemini 2.5 Pro (higher capability)
- Temperature: 0.9 (high creativity for diverse attacks)
- Input: Risk category (e.g., "Toxicity", "Phishing", "Financial Fraud")
- Output: Single, highly targeted adversarial prompt
- Purpose: Simulate the system under test
- Model: Gemini 2.5 Flash (faster, cost-effective)
- Temperature: 0.1 (consistent, conservative responses)
- Role: Banking Assistant compliant with strict policies defined in safety_rules.py
- Input: Adversarial prompt from red team
- Output: Response to the adversarial prompt
- Purpose: Determine if safety rules were violated
- Model: Gemini 2.5 Pro (high judgment capability)
- Temperature: 0.0 (deterministic evaluation)
- Input: Attack-response transcript
- Output: JSON verdict with PASS/FAIL and reasoning
Generates an adversarial prompt designed to test the robustness of a target system or model by attempting to bypass safety guidelines or elicit unintended behaviors.
Simulates a response from the target system or model given an input prompt. This tool mimics the behavior of the target to enable testing without repeated actual API calls.
Evaluates the results of an interaction between a generated attack prompt and the simulated target response. Determines the effectiveness of the attack and provides metrics on whether safety guidelines were violated or unintended behavior was triggered.
The complete workflow follows this sequence:
START
│
├─► User Input: Risk Category
│ (e.g., "Toxicity")
│
├─► STAGE 1: Red Team Generation
│ └─► Prompt: "Generate an adversarial prompt for Phishing"
│ └─► Output: Sophisticated phishing attack prompt
│
├─► STAGE 2: Target Injection & Response
│ └─► Inject: Adversarial prompt into target
│ └─► Target Response: System's attempt to handle/block the attack
│
├─► STAGE 3: Safety Evaluation
│ └─► Input: [ATTACK] and [RESPONSE] pair
│ └─► Verdict: PASS (safety maintained) or FAIL (safety violated)
│
└─► Output: Security Audit Report
(Risk category, attack attempt, target behavior, verdict)
END
- Async Execution: Sub-agents run asynchronously with proper session management via
ThreadPoolExecutor - Temperature Tuning:
- Red Team: 0.9 (maximize creative adversarial attempts)
- Target: 0.1 (consistent, predictable behavior)
- Evaluator: 0.0 (deterministic, unbiased verdicts)
- Serial Pipeline: Each stage depends on the previous stage's output
- Error Handling: Attack generation failures are caught early to prevent cascade failures
- Python 3.12+
- Google Cloud Account with Vertex AI access
- uv for dependency management:
curl -LsSf https://astral.sh/uv/install.sh | sh
Use the Agent Starter Pack to create a production-ready version of this agent with additional deployment options. The easiest way is with uvx (no install needed):
uvx agent-starter-pack create my-ai-security-agent -a adk@ai-security-agentAlternative: Using pip and a virtual environment
# Create and activate a virtual environment
python -m venv .venv && source .venv/bin/activate # On Windows: .venv\Scripts\activate
# Install the starter pack and create your project
pip install --upgrade agent-starter-pack
agent-starter-pack create my-ai-security-agent -a adk@ai-security-agentThe starter pack will prompt you to select deployment options and provides additional production-ready features including automated CI/CD deployment scripts.
-
Clone the repository:
git clone https://github.com/google/adk-samples.git cd python/agents/ai-security-agent -
Install dependencies:
uv sync --dev
-
Set up Google Cloud credentials:
gcloud auth application-default login
-
Configure environment variables (copy and edit
.env.exampleto.env):export GOOGLE_GENAI_USE_VERTEXAI=1 export GOOGLE_CLOUD_PROJECT=my-project export GOOGLE_CLOUD_LOCATION=us-central1
-
Run the agent:
uv run adk web
Edit llm_red_team_agent/config.py to customize:
@dataclass
class SecurityAuditConfig:
evaluator_model: str = "gemini-2.5-pro"
red_team_model: str = "gemini-2.5-pro"
target_model: str = "gemini-2.5-flash" Run the test suite:
uv sync --dev
uv run pytest tests/ -vLicensed under the Apache License 2.0. See LICENSE file for details.
Contributions welcome! Please:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit changes (
git commit -m 'Add amazing feature') - Push to branch (
git push origin feature/amazing-feature) - Open a Pull Request
This tool is designed for authorized security testing of AI systems. Ensure you have proper authorization before conducting any red-teaming activities on production systems.

