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 write outputs

From Leeroopedia
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

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))

Related Pages

Implements Principle

Page Connections

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