How aryan09092001/self-red-teaming-multi-agent-platform works
Purpose and Entry Points
This is an AWS-deployed asynchronous research-report platform with self-red-teaming. A FastAPI API accepts research jobs, returns a job ID, and a co-hosted worker produces safety-checked reports through a multi-agent LLM graph. A separate PyRIT dashboard attacks the live API.
Core entry points:
• API and job worker: app/main.py
• Agent graph: app/agents.py
• Red-team service: pyrit_dashboard/main.py
• Browser UI: index.html
API, Queue, and Job Lifecycle
POST /research validates/authenticates the request, rate-limits it, runs the input safety check, then puts accepted work on a Redis Stream rather than awaiting LLM execution. Clients poll result endpoints by job_id.
The worker in app/main.py consumes and acknowledges queue messages via app/queue.py. Job state/results are persisted in Redis. API and worker currently share one process, an intentional scaling boundary.
Safety and Access Boundary
Safety is enforced at both sides of generation:
• Input guardrail rejects unsafe topics before queueing/model usage.
• Output guardrail rejects generated reports before persistence, caching, or return.
AWS Bedrock Guardrails integration is isolated in app/guardrails.py; optional API-key middleware is in app/auth.py. The README identifies a current prompt-injection gap: classification occurs on raw topic input rather than the assembled prompt.
Retrieval, Cache, and Memory Tiers
Worker processing uses a cost/latency-ordered lookup:
1. Semantic Redis cache for near-duplicate topics.
2. pgvector-backed long-term report recall.
3. Full agent graph on misses.
app/cache.py implements embedding-similarity caching. app/memory.py manages Redis session history (short-term context) and PostgreSQL/pgvector report memory (recall, writer context, and report comparison). app/pool.py owns database connectivity. Only output-guardrail-passed generated reports enter cache or long-term storage.
Multi-Agent Research Graph and LLM Boundary
app/agents.py defines a LangGraph shared-state pipeline: search → summarize → write → verify. The critic can route failed reports back to search until a configured iteration cap, bounding retry cost.
Agents call TensorZero rather than providers directly. tensorzero/tensorzero.toml defines routing from OpenAI GPT-4o to Groq fallback; prompt specializations live in:
• tensorzero/templates/research_summarize_system.minijinja
• tensorzero/templates/report_write_system.minijinja
app/retry.py adds application-level exponential retry around calls. This separates model/provider failover policy from Python orchestration.
Results, Evaluation, and Red Teaming
Generated reports can be returned as text, structured JSON, PDF, and diffs through output handling in app/output.py. Evaluation is asynchronous: four LLM judges score completed reports without delaying job completion, implemented in app/eval.py and traced through LangSmith.
The independent PyRIT FastAPI service in pyrit_dashboard/main.py runs jailbreak, injection, crescendo, and skeleton-key attacks against the deployed app, persisting its run data through Redis/SQLite-oriented harness dependencies. It is exposed separately from the main API.
Deployment and Operating Environment
The production runtime is ECS Fargate behind an ALB, with the app, TensorZero sidecar, and PyRIT service packaged by:
• app/Dockerfile
• tensorzero/Dockerfile
• pyrit_dashboard/Dockerfile
terraform/main.tf provisions VPC/private networking, ECS, ALB, ElastiCache Redis, RDS PostgreSQL with pgvector, Bedrock guardrails, ECR, Secrets Manager, IAM, CloudWatch, and scheduled EventBridge red-team execution. .github/workflows/deploy.yml builds images, publishes to ECR, updates ECS services, waits for stability, and rolls back on failure.
Main entry points: main.py API + job worker · output.py Result output · guardrails.py Bedrock guardrails · agents.py Research agent graph
Components 18
Research Runtime
Co-hosted API and asynchronous worker.
- Research clients
- API + job worker · Accepts jobs, polls results, and consumes stream work in one process.
app/main.py - Redis Stream · Decouples accepted research jobs from LLM execution.
app/queue.py - Result output
app/output.py
Research & Models
Retrieval and multi-agent generation.
- Semantic cache · Checks near-duplicate topics before long-term recall or generation.
app/cache.py - Report memory · Provides long-term report recall, writer context, and comparison.
app/memory.py - Research agent graph · Searches, summarizes, writes, and verifies; failed reports loop to search within a cap.
app/agents.py - TensorZero sidecar · Routes GPT-4o calls to Groq fallback.
tensorzero/tensorzero.toml - Prompt templates
tensorzero/templates/report_write_system.minijinja
State & Safety
Guardrails, job state, cache, and memory.
- API-key middleware
app/auth.py - Bedrock guardrails · Checks topics before queueing and reports before persistence or return.
app/guardrails.py - Redis · Stores job state, stream messages, session history, and semantic cache.
- PostgreSQL + pgvector
app/pool.py
Evaluation & Red Team
Post-completion assessment and adversarial testing.
- Async evaluation · Scores completed reports without delaying job completion and traces through LangSmith.
app/eval.py - PyRIT dashboard · Attacks the live API with jailbreak, injection, crescendo, and skeleton-key campaigns.
pyrit_dashboard/main.py
AWS Delivery
Container deployment and infrastructure.
- ECS Fargate + ALB · Runs separately exposed app, TensorZero, and PyRIT containers.
- Terraform infrastructure · Provisions networking, ECS, Redis, RDS, guardrails, secrets, IAM, and observability.
terraform/main.tf - Deploy workflow · Builds and publishes images, updates ECS, verifies stability, and rolls back failures.
.github/workflows/deploy.yml
Connections 25
- Research clients → API + job worker: POST /research; poll by job ID
- API + job worker → API-key middleware: authenticate / rate-limit
- API + job worker → Bedrock guardrails: input check
- Bedrock guardrails → Redis Stream: accepted jobs
- Redis Stream → API + job worker: consume + acknowledge
- API + job worker → Redis: job state and results
- API + job worker → Semantic cache: first lookup
- Semantic cache → Redis: embeddings / cached reports
- API + job worker → Report memory: cache miss recall
- Report memory → PostgreSQL + pgvector: long-term reports
- API + job worker → Research agent graph: full miss generation
- Research agent graph → TensorZero sidecar: agent calls with retries
- Prompt templates → TensorZero sidecar: specialized prompts
- Research agent graph → Bedrock guardrails: generated report output check
- Bedrock guardrails → Result output: passed reports only
- Result output → Redis: persist result
- Result output → Semantic cache: populate after pass
- Result output → Report memory: store after pass
- Result output → Async evaluation: completed reports
- PyRIT dashboard → API + job worker: live attack campaigns
- Deploy workflow → ECS Fargate + ALB: deploy containers
- Terraform infrastructure → ECS Fargate + ALB: provisions runtime
- ECS Fargate + ALB → API + job worker: hosts app
- ECS Fargate + ALB → TensorZero sidecar: hosts sidecar
- ECS Fargate + ALB → PyRIT dashboard: hosts separate service