Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Implementation:AISecurityLab Hackagent load campaign

From Leeroopedia
Knowledge Sources
Domains Security_Testing, Configuration
Last Updated 2026-10-29 00:00 GMT

Overview

Concrete tool for loading declarative campaign specifications from YAML files or decoded mappings provided by the HackAgent orchestrator.

Description

The load_campaign function reads a campaign YAML file (or an already-decoded Python mapping) and validates it into a frozen CampaignSpec pydantic model. It is the entry point of the campaign lifecycle — the first step every run takes. The function handles file I/O (path expansion, existence check, YAML parsing) and delegates structural validation to CampaignSpec.model_validate.

Usage

Import this function when you need to load a campaign from a YAML file path or a decoded mapping dict before resolving and executing it. This is the standard way to begin a campaign run programmatically.

Code Reference

Source Location

Signature

def load_campaign(source: str | Path | Mapping[str, Any]) -> CampaignSpec:
    """Validate and return one campaign specification."""

Import

from hackagent.orchestrator.campaign.loader import load_campaign

I/O Contract

Inputs

Name Type Required Description
source Path | Mapping[str, Any] Yes Path to a YAML file, a decoded mapping dict, or a CampaignSpec instance

Outputs

Name Type Description
return CampaignSpec Frozen pydantic model holding the full campaign schema

Usage Examples

Load from YAML File

from hackagent.orchestrator.campaign.loader import load_campaign

# Load a campaign from a YAML file
spec = load_campaign("campaigns/quick_check.yaml")
print(f"Campaign: {spec.campaign.name}, {len(spec.attacks)} attack(s)")

Load from Decoded Mapping

from hackagent.orchestrator.campaign.loader import load_campaign

# Load from an already-decoded dict (e.g., from an API payload)
campaign_dict = {
    "version": 1,
    "campaign": {"name": "Quick jailbreak check"},
    "dataset": {"source": {"preset": "harmbench_standard"}},
    "target": {"name": "victim-model", "connection": {"type": "litellm", "model": "gpt-4o"}},
    "attacks": [{"name": "baseline"}],
}
spec = load_campaign(campaign_dict)

Related Pages

Implements Principle

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment