Implementation:AISecurityLab Hackagent AttackParams
| Knowledge Sources | |
|---|---|
| Domains | Security_Testing, Dependency_Injection |
| Last Updated | 2026-10-29 00:00 GMT |
Overview
Concrete tool for defining validated, immutable attack configurations that declare their auxiliary model roles as typed fields, provided by the HackAgent attacks framework.
Description
AttackParams is the base pydantic model for all attack configurations. It implements the inversion-of-control contract: an attack never builds, configures, or calls a model on its own. Whatever it needs is a callable supplied from outside. Fields annotated with Completion (chat messages in, reply text out) or Embedder (texts in, vectors out) are roles — auxiliary models supplied by the campaign runner. Every other field is a plain algorithm parameter.
The contract types defined in this module are:
- Completion:
Callable[[Messages], Awaitable[str]]— an auxiliary chat model. - Target:
Callable[..., Awaitable[CompletionResult]]— the model under test, passed to iterative attacks at run time. - Judge:
Callable[[Sample], Awaitable[Verdict]]— the evaluation panel as an attack sees it. - Embedder:
Callable[[Sequence[str]], Awaitable[list[list[float]]]]— an embedding model. - Messages: list[dict[str, Any]] — a chat message list.
AttackParams provides introspection methods (completion_roles, embedder_roles, role_names) so campaign resolution can discover which fields are roles and validate them.
Usage
- Defining an attack's parameters: Subclass AttackParams, annotate role fields with Completion or Embedder, and plain parameters with standard types.
- Required roles: Set the REQUIRED_ROLES class variable to a frozenset of role names the attack cannot run without.
Code Reference
Source Location
- Repository: AISecurityLab_Hackagent
- File: hackagent/attacks/techniques/contract.py
Signature
Message = dict[str, Any]
Messages = list[Message]
Completion = Callable[[Messages], Awaitable[str]]
Target = Callable[..., Awaitable[CompletionResult]]
Embedder = Callable[[Sequence[str]], Awaitable[list[list[float]]]]
Judge = Callable[[Sample], Awaitable[Verdict]]
class AttackParams(BaseModel):
"""Validated, immutable attack configuration."""
model_config = ConfigDict(extra="forbid", frozen=True)
REQUIRED_ROLES: ClassVar[frozenset[str]] = frozenset()
@classmethod
def completion_roles(cls) -> frozenset[str]: ...
@classmethod
def embedder_roles(cls) -> frozenset[str]: ...
@classmethod
def role_names(cls) -> frozenset[str]: ...
Import
from hackagent.attacks.techniques.contract import (
AttackParams, Completion, Messages, Target, Judge, Embedder, Message,
)
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| kwargs | dict | Yes | Algorithm parameters and role callables, validated by pydantic |
Outputs
| Name | Type | Description |
|---|---|---|
| return | AttackParams subclass | Frozen, validated configuration instance |
Usage Examples
Defining Attack Parameters with Roles
from hackagent.attacks.techniques.contract import AttackParams, Completion
class PairParams(AttackParams):
"""PAIR attack parameters."""
attacker: Completion # role: generates adversarial prompts
attacker_temperature: float = 1.0 # plain parameter
max_rounds: int = 20
REQUIRED_ROLES = frozenset({"attacker"})
# Introspect roles
print(PairParams.completion_roles()) # frozenset({"attacker"})
print(PairParams.role_names()) # frozenset({"attacker"})
Defining a RAG Attack with an Embedder Role
from hackagent.attacks.techniques.contract import AttackParams, Completion, Embedder
class RagParams(AttackParams):
"""RAG indirect injection attack."""
embedder: Embedder # role: embeds poisoned documents
attacker: Completion # role: generates poison text
num_documents: int = 5
REQUIRED_ROLES = frozenset({"embedder", "attacker"})