Implementation:AISecurityLab Hackagent RunTracker record
| Knowledge Sources | |
|---|---|
| Domains | Security_Testing, Persistence, Tracking |
| Last Updated | 2026-10-29 00:00 GMT |
Overview
Concrete tool for persisting campaign run records — attacks, attempts, traces, and evaluation results — to the HackAgent store.
Description
RunTracker owns the store records of one attack run. When it starts, it creates the attack and run rows, setting the run to RUNNING. As each attempt is judged, record() persists it: a result row per attempt, optional trace rows per attempt's search steps, and the evaluation status and metrics. When the run ends, complete(), fail(), or cancel() sets the final status and flushes.
The record method handles:
- Creating a result row with the goal, goal index, request messages (if save_prompts), and identity (attack type, request index, labels).
- Writing trace rows for each TraceNode in the attempt's trace (if save_traces), plus a final interaction trace row.
- Updating the result with evaluation status (SUCCESSFUL_JAILBREAK, FAILED_JAILBREAK, ERROR_TEST_FRAMEWORK), evaluation metrics, response text, latency, and error.
The module also provides open_store (opens the local SQLite or remote HTTP store named by StorageSpec) and register_target (creates or updates the agent record runs are attached to).
Usage
Import this class when you need to persist attack run records. The campaign runner creates a RunTracker per attack run and calls record for each attempt. You rarely call it directly — it is used by _AttackRunner.run and _AttackRunner._run_goal.
Code Reference
Source Location
- Repository: AISecurityLab_Hackagent
- File: hackagent/orchestrator/campaign/tracking.py
Signature
class RunTracker:
"""Store records of one attack run."""
def __init__(
self,
store: Store,
*,
agent_id: UUID,
attack_name: str,
configuration: Mapping[str, Any],
expected_goals: int,
output: OutputSpec,
campaign_run_id: Optional[UUID] = None,
) -> None: ...
def record(self, attempt: Attempt) -> None:
"""Persist one attempt with its evaluation."""
def complete(self) -> None: ...
def fail(self, error: BaseException) -> None: ...
def cancel(self) -> None: ...
def open_store(storage: StorageSpec, settings: Optional[Settings] = None) -> Store: ...
def register_target(store: Store, target: ModelConfig) -> UUID: ...
Import
from hackagent.orchestrator.campaign.tracking import RunTracker, open_store, register_target
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| store | Store | Yes | Persistence backend (local SQLite or remote HTTP) |
| agent_id | UUID | Yes | Target agent record |
| attack_name | str | Yes | Attack technique name |
| configuration | Mapping[str, Any] | Yes | Attack parameters and role labels |
| expected_goals | int | Yes | Number of goals this attack will run |
| output | OutputSpec | Yes | Controls save_prompts/responses/traces |
| attempt | Attempt | Yes (record) | One judged attempt with messages, response, verdict, trace |
Outputs
| Name | Type | Description |
|---|---|---|
| run_id | UUID | The created run's ID (stored on self.run_id) |
| Store records | various | Result rows, trace rows, evaluation status/metrics |
Usage Examples
Creating a Tracker and Recording an Attempt
from hackagent.orchestrator.campaign.tracking import RunTracker, open_store, register_target
from hackagent.orchestrator.campaign.results import Attempt
# Open the store and register the target
store = open_store(spec.execution.storage)
agent_id = register_target(store, spec.target)
# Create a tracker for one attack run
tracker = RunTracker(
store,
agent_id=agent_id,
attack_name="baseline",
configuration={"parameters": {}},
expected_goals=10,
output=spec.execution.output,
)
# Record each attempt as it is judged
tracker.record(attempt)
# Mark the run as complete
tracker.complete()