Implementation:AISecurityLab Hackagent write outputs
| Knowledge Sources | |
|---|---|
| Domains | Security_Testing, Output, Reporting |
| Last Updated | 2026-10-29 00:00 GMT |
Overview
Concrete tool for writing a campaign run's output files — results, traces, and audit — to disk, provided by the HackAgent orchestrator.
Description
write_outputs writes a run's files into <directory>/<run_id>/. It produces:
- campaign.yaml: The campaign that ran, so the run can be reproduced even when it was never saved as a file. Credentials are redacted.
- results.json and/or results.jsonl: One row per attempt, with goal index, prompt, response, decoded text, evaluation status and metrics, error, and metadata. The OutputSpec controls whether prompts and responses are included.
- traces.jsonl: Search traces of iterative attacks, one line per attempt, plus run-scoped trace. Each node carries its path so the tree can be rebuilt from the flat list. Only written when save_traces is on.
- audit.json: The judge audit report, when one ran.
The companion functions attempt_row, trace_payload, and trace_step_type produce the flat, JSON-safe views of attempts and trace nodes that are serialized. The summary() function produces a short machine-readable report of a run.
Usage
Import this function when you need to write campaign results to disk. It is called automatically by arun_campaign after all attacks complete.
Code Reference
Source Location
- Repository: AISecurityLab_Hackagent
- File: hackagent/orchestrator/campaign/results.py
Signature
def write_outputs(
result: CampaignResult,
output: OutputSpec,
campaign: Optional[Mapping[str, Any]] = None,
) -> tuple[Path, ...]:
"""Write a run's files into <directory>/<run_id>/."""
def attempt_row(attempt: Attempt, output: OutputSpec) -> dict[str, Any]: ...
def trace_payload(node: TraceNode, output: OutputSpec) -> dict[str, Any]: ...
def summary(result: CampaignResult) -> dict[str, Any]: ...
Import
from hackagent.orchestrator.campaign.results import write_outputs, summary
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| result | CampaignResult | Yes | The completed run |
| output | OutputSpec | Yes | directory, formats, save_prompts/responses/traces |
| campaign | Optional[Mapping] | No | Redacted campaign dict for reproducibility |
Outputs
| Name | Type | Description |
|---|---|---|
| return | tuple[Path, ...] | Files written under <directory>/<run_id>/ |
Usage Examples
Write Outputs After a Run
from hackagent.orchestrator.campaign.results import write_outputs, summary
from hackagent.orchestrator.campaign.runner import run_campaign
result = run_campaign("campaigns/quick_check.yaml")
# Outputs are already written by arun_campaign, but you can re-write:
files = write_outputs(result, result.spec_execution_output, campaign_dict)
for path in files:
print(f"Wrote: {path}")
# Short machine-readable summary
print(summary(result))