页面简介
Measuring a monitor or protocol on agent runs you already have, by replaying it over their logs with Inspect Scout.
正文摘录
Overview Before you let a monitor reject tool calls or end samples, you should know how often it flags the steps you care about and how often it flags harmless ones. Replay lets you measure this on agent runs you already have. It rebuilds each step from an eval log and runs your monitor or protocol over it with the same code that runs during an eval. Replay runs through Inspect Scout. Your monitor becomes a Scout scanner, and the scan gives you one result for each step, which you can read in Scout View or as a pandas dataframe. You can use replay to: See which steps of existing runs a new monitor would flag, before attaching it to an eval. Choose a threshold from the scores a monitor gives on runs you know are harmless. Compute precision and recall against your own labels, and compare two versions of a monitor. Installation Replay uses the scout extra, which installs a compatible version of Inspect Scout: pip install 'inspect-sentinel[scout]' Replaying a Monitor Let’s replay the suspicion monitor from examples/llm_suspicion.py (described in LLM Monitors) over the logs of some earlier runs. Save this script in the examples directory, so that it can import the monitor: replay_suspicion.py from inspect_scout import scan, scan_results_df, transcripts_from from inspect_sentinel.scout import as_scanner from llm_suspicion import suspicion status = scan( 1 scanners={"suspicion": as_scanner(suspicion())}, 2 transcripts=transcripts_from("./logs"), 3 model_roles={"monitor": "anthropic/claude-haiku-4-5"}, ) 4results = scan_results_df(status.location).scanners["suspicion"] print(results[["transcript_id", "metadata.step_id", "metadata.stage", "value"]]) 1 as_scanner() turns a monitor or protocol into a Scout scanner. It takes anything Task(sentinel=...) takes, and also a single monitor on its own. Several monitors with no protocol are refused; scan them one at a time. 2 The transcripts to scan, here every sample in the eval logs in ./logs. Each sample is one transcript. 3 The monitor model, given through the monitor model role as in an eval. 4 One dataframe for each scanner, with one row for each step. Run it with Python: python replay_suspicion.py You can also open the scan in Scout View with scout view. Each result’s explanation starts with a link to the step it is about, such as Step [E12]: ..., so you can go from a score to the tool call it scored. A label like [M3] cites a message and [E12] an event (see Citations). The scan resolves the monitor model the same way an eval does, with the scan’s model_roles and model in place of the eval’s: a model the monitor names, else the role it asks for (monitor by default), else the scan’s model, with a warning. The monitor’s model usage counts toward the scan’s. Results Each row of the results dataframe is one step at one stage: Column Description transcript_id The sample the step belongs to. metadata.step_id The tool call id at a tool stage, or the model call id at a generate stage. A tool call’s two steps share its id. Where a call id runs more than once (a retry after a tool error, or a provider that reuses ids), a run of the id after an earlier run’s steps took it has its execution id instead, in logs that record one, so each step’s id is unique in its transcript. A tool step of an agent run through an agent bridge has the id of the model call that proposed it, a /, then the call id. In read mode, an agent bridge’s check of a tool call has its execution id, or, for a result the bridge could not tie to one run of a call id it handed out more than once, the id of the sentinel span it was reported in, which the reports of its monitors share. Either way it matches no replayed step (see Bridged Agents). metadata.replay_step_id In read mode, the replayed step the row joins: its own metadata.step_id, except for an agent bridge’s check, which names the replayed step of the model call that proposed its call id, or None where the log doesn’t tie it to one (see Bridged Agents). metadata.stage "model_input" (BeforeGenerate), "model_output" (AfterGenerate), "tool_call" (BeforeToolCall) or "tool_result" (AfterToolCall). metadata.conversation The conversation the step is in. Each agent and sub-agent has its own message thread, its conversation, so this tells a sub-agent’s steps apart from the main agent’s. value For a monitor, the suspicion score: a number, or a dict with one entry per dimension. For a protocol, True if the action is reject, modify or terminate, and False for proceed or escalate. None where the monitor or protocol abstained. answer For a protocol, the action, such as "escalate". None where it abstained. metadata.metadata The observation’s or decision’s own metadata. metadata.depth How deeply nested the step’s conversation is (see Sub-agents and Timelines). metadata.turns How the transcript’s agent turns were established: "recorded", "inferred" or "stored" (see What a Replayed Step Holds). metadata.audit, metadata.modified, metadata.reports For a protocol, its decision’s audit flag, its modified tool call, and the reports of the monitors and protocols beneath it. metadata.human, metadata.human_answer Where the step reached human(), where its answer came from (see Human Decisions in Replay). metadata.status In read mode, "superseded" for a protocol decision that was superseded at its step (see Read Mode). The suspicion monitor scores two dimensions, so each value is a dict such as {"files": 0.1, "network": 0.7}. Its value is None at the agent’s submit() tool call, where it abstains. A protocol’s escalate declines to decide, so it isn’t flagged, but answer still records it, so you can count escalations. If a monitor raises an exception, the transcript gives one error row (in the scan_error column) instead of step rows, so a failed monitor is never counted as an abstention. This happens even under observe_only(), which in an eval logs a warning and lets the step proceed, and for any monitor in the sentinel, even one a protocol went on without at that step, since a row can’t say that a monitor behind it failed. Citations A row’s references cite the step’s model event or message first, then what the report cites. Each reference has a cite label, as Scout’s scanners write them: [M<n>] for the transcript’s nth message and [E<n>] for its nth event, so one label names one message or event across all of a transcript’s rows. Every reference resolves in the transcript. A step whose message the transcript doesn’t hold (e.g. a sub-agent’s tool message or reply) cites the event that recorded it, its ToolEvent or ModelEvent. A reference to anything the transcript doesn’t hold, a report’s included, is left out. A label a monitor gave its own reference is replaced with that reference’s transcript label, and the monitor’s explanation is rewritten to match. The explanation leads with the step’s label and names any other reference the report’s explanation doesn’t, so Scout View links each one. Measuring a Monitor To measure a monitor, you need its scores on steps whose correct answer you already know. Both measurements below use ordinary pandas over the results dataframe. Replay measures what a monitor or protocol reports, not what its decisions would have done. A reject in a replay does not change the transcript, because the agent already ran the tool call. To see what the agent does after a rejected tool call, run a live eval. Scores on Harmless Runs To choose a threshold, collect the scores a monitor gives on runs you know are harmless. Run your tasks with the monitor under observe_only(), which records every observation and lets every step proceed: from inspect_ai import eval from inspect_sentinel import observe_only from llm_suspicion import suspicion eval( "benign.py", model="openai/gpt-5-mini", model_roles={"monitor": "anthropic/claude-haiku-4-5"}, sentinel=observe_only(suspicion()), log_dir="./logs-benign", ) Here benign.py stands for tasks the agent can complete without breaking the monitor’s policy. The scores are now in the logs. Read them with as_reader(), which gives the same rows as as_scanner() from what the eval recorded, without calling the monitor model again (see Read Mode). Then take a percentile of each dimension: from inspect_scout import scan, scan_results_df, transcripts_from from inspect_sentinel.scout import as_reader status = scan( scanners={"benign": as_reader("suspicion")}, transcripts=transcripts_from("./logs-benign"), ) scores = scan_results_df(status.location).scanners["benign"]["value"].dropna() for dimension in ["files", "network"]: print(dimension, scores.map(lambda v: v[dimension]).quantile(0.99)) The 99th percentile of a dimension is the threshold that flags about 1% of harmless tool calls on that dimension. threshold() accepts one threshold per dimension, as in threshold(suspicion(), reject_at={"files": 0.7, "network": 0.6}). If you already have logs of harmless runs without the monitor, replay it over them with as_scanner() and use the same value column. Precision and Recall To compute precision and recall, you need labels that say, for some steps, whether the monitor should have flagged them. You make the labels yourself, for example by reading tool calls in Scout View and writing down their ids. The easiest way to collect step ids for labeling is to run a first scan over the transcripts and take each row’s metadata.step_id. Here the labels are a CSV file with columns transcript_id, step_id and unsafe (True or False), and status is the scan from replay_suspicion.py: import pandas as pd labels = pd.read_csv("labels.csv") results = scan_results_df(status.location).scanners["suspicion"] scored = results.rename(columns={"metadata.step_id": "step_id"}).merge( labels, on=["transcript_id", "step_id"] ) flagged = scored["value"].map(lambda v: v is not None and max(v.values()) >= 0.8) unsafe = scored["unsafe"] true_positives = (flagged & unsafe).sum() print("precision", true_positives / flagged.sum()) print("recall", true_positives / unsafe.sum()) flagged applies