翻篇收录说明
翻篇网页快照

Custom Scanners – Inspect Scout

https://meridianlabs-ai.github.io/inspect_scout/custom_scanner.html

最近抓取:2026-12-04 20:19:02(北京时间)

最近内容变化:2026-12-02 07:47:14(北京时间)

这是最近一次有效抓取的文本快照,不含网页脚本、图片和动态交互内容。实际网页可能已更新。

访问原网页

页面简介

Transcript Analysis for AI Agents

正文摘录

Overview Scanners are the main unit of processing in Inspect Scout and can target a wide variety of content types. In this article we’ll cover the basic scanning concepts, and then drill into creating scanners that target various types (Transcript, ChatMessage, Event, or Timeline) as well as creating custom loaders which enable scanning of lists of events or messages. This article goes in depth on custom scanner development. If you are looking for a straightforward high-level way to create an LLM-based scanner see the LLM Scanner documentation. Note that you can also use scanners directly as Inspect scorers (see Scanners as Scorers for details). Scanner Basics A Scanner is a function that takes a ScannerInput (typically a Transcript, but possibly an Event, ChatMessage, Timeline, or list of events or messages) and returns a Result. The result includes a value which can be of any type—this might be True to indicate that something was found but might equally be a number to indicate a count. More elaborate scanner values (dict or list) are also possible. Here is a simple scanner that uses a model to look for agent “confusion”—whether or not it finds confusion, it still returns the model completion as an explanation: from inspect_scout import ( Result, Scanner, Transcript, scanner, message_numbering ) from inspect_ai.model import get_model import re @scanner(messages="all") def confusion() -> Scanner[Transcript]: async def scan(transcript: Transcript) -> Result: # setup message numbering messages_as_str, extract_refs = message_numbering() # call model output = await get_model().generate( "Here is a transcript of an LLM agent " + "solving a puzzle:\n\n" + "===================================" + await messages_as_str(transcript.messages) + "===================================\n\n" + "In the transcript above do you see the " + "agent becoming confused? Respond " + "beginning with 'Yes' or 'No', followed " + "by an explanation." ) # extract the first word match = re.match(r"^\w+", output.completion.strip()) # return result if match: answer = match.group(0) explanation = output.completion return Result( value=answer.lower() == "yes", answer=answer, explanation=explanation, references=extract_refs(explanation), ) else: return Result(value=False, explanation=output.completion) return scan This scanner illustrates some of the lower-level mechanics of building custom scanners. You can also use the higher level llm_scanner() to implement this in far fewer lines of code: from inspect_scout import Transcript, llm_scanner, scanner @scanner(messages="all") def confusion() -> Scanner[Transcript]: return llm_scanner( question="In the transcript above do you see " + "the agent becoming confused?" answer="boolean" ) Input Types Transcript is the most common ScannerInput however several other types are possible: Event — Single event from the transcript (e.g. ModelEvent, ToolEvent, etc.). ChatMessage — Single chat message from the transcript message history. Timeline — Hierarchical span tree representing the structure of agent execution. See Timeline Scanners below for details. list[Event] or list[ChatMessage] — Arbitrary sets of events or messages extracted from the Transcript (see Loaders below for details). See the sections on Transcripts, Events, Messages, Timelines, and Loaders below for additional details on handling various input types. Input Filtering One important principle of the Inspect Scout transcript pipeline is that only the precise data to be scanned should be read, and nothing more. This can dramatically improve performance as messages and events that won’t be seen by scanners are never deserialized. Scanner input filters are specified as arguments to the @scanner decorator (you may have noticed the messages="all" attached to the scanner decorator in the example above). For example, here we are looking for instances of assistants swearing—for this task we only need to look at assistant messages so we specify messages=["assistant"] @scanner(messages=["assistant"]) def assistant_swearing() -> Scanner[Transcript]: async def scan(transcript: Transcript) -> Result: swear_words = [ word for m in transcript.messages for word in extract_swear_words(m.text) ] return Result( value=len(swear_words), explanation=",".join(swear_words) ) return scan With this filter, only assistant messages (and no events at all) will be loaded from transcripts during scanning. Note that by default, no filters are active, so if you don’t specify values for messages, events, and/or timeline your scanner will not be called! (metadata does not count as a filter here: it controls what is read alongside the content, not whether the scanner runs.) The available filter parameters are: messages — Filter for message types: "all" or a list like ["user", "assistant"]. events — Filter for event types: "all" or a list like ["model", "tool"]. timeline — Enable timeline loading: True for all event types, "all", or a list like ["model", "tool"]. metadata — Whether to read the sample’s full metadata, target and scores from the log body (default True). Pass False if your scanner never reads transcript.metadata["sample_metadata"], ["target"] or ["scores"]; the log’s summary values are kept instead, and a log with gigabytes of sample metadata is not held in memory while scanning. You can also provide a version parameter to track scanner versions. When the version is incremented, previously scanned transcripts will be re-scanned with the updated scanner. Transcripts Transcripts are the most common input to scanners. If you are reading from Inspect eval logs, each log will have samples * epochs transcripts. If you are reading from another source, each agent trace will yield a single Transcript. Transcript Fields Here are the available Transcript fields: Field Type Description transcript_id str Globally unique identifier for a transcript (maps to EvalSample.uuid in Inspect logs). source_type str Type of transcript source (e.g. “eval_log”, “weave”, etc.). source_id str Globally unique identifier for a transcript source (maps to eval_id in Inspect logs) source_uri str URI for source data (e.g. full path to the Inspect log file). date iso Date/time when the transcript was created. task_set str Set from which transcript task was drawn (e.g. Inspect task name or benchmark name) task_id str Identifier for task (e.g. dataset sample id). task_repeat int Repeat for a given task id within a task set (e.g. epoch). agent str Agent used to to execute task. agent_args dict JSON Arguments passed to create agent. model str Main model used by agent. model_options dict JSON Generation options for main model. score JsonValueJSON Value indicating score on task. score_explanation str Scorer’s account of how it reached score, where it gave one. success bool Boolean reduction of score to succeeded/failed. message_count int Total messages in conversation. total_time number Time required to execute task (seconds) total_tokens number Tokens spent in execution of task. error str Error message that terminated the task. limit str Limit that caused the task to exit (e.g. “tokens”, “messages, etc.) trust_content bool Whether the viewer may render the transcript’s model output richly. False shows it as plain text. For Inspect logs this is the task’s ViewerConfig(trust_content=...). messages_from list[str] uuids of the ModelEvents whose conversation messages is. Set by the transcript importers; None for Inspect logs. metadata dict[str, JsonValue] Transcript source specific metadata (e.g. model, task name, errors, epoch, dataset sample id, limits, etc.). For Inspect logs this includes sample_metadata, target and scores from the sample body unless the scanner passes metadata=False. messages list[ChatMessage] Message history. events list[Event] Event history (e.g. model events, tool events, etc.) timelines list[Timeline] Optional list of custom timelines for this transcript. Content Filtering Note that the messages and events fields will not be populated unless you specify a messages or events filter on your scanner. For example, this scanner will see all messages and events: @scanner(messages="all", events="all") def my_scanner() -> Scanner[Transcript]: ... This scanner will see only model and tool events: @scanner(events=["model", "tool"]) def my_scanner() -> Scanner[Transcript]: ... This scanner will see only assistant messages: @scanner(messages=["assistant"]) def my_scanner() -> Scanner[Transcript]: ... Sample metadata, target and scores are merged into transcript.metadata from the log body by default. A scanner that does not read them can decline with metadata=False, which leaves the index’s summary values in place: metadata thinned to about 1 KB per key, target as a single string, and scores as score_* values only. Declining takes effect when every scanner in a scan declines; a scanner that shares a read with one that wants metadata receives it anyway. Presenting Messages When processing transcripts, you will often want to present an entire message history to a model for analysis. The message_numbering() function provides numbered message formatting and reference extraction: # setup message numbering messages_as_str, extract_refs = message_numbering() # call model output = await get_model().generate( "Here is a transcript of an LLM agent " + "solving a puzzle:\n\n" + "===================================" + await messages_as_str(transcript.messages) + "===================================\n\n" + "In the transcript above do you see the agent " + "becoming confused? Respond beginning with 'Yes' " + "or 'No', followed by an explanation." ) # extract references from the model's explanation explanation = output.completion references = extract_refs(explanation) The message_numbering() function returns a (messages_as_str, extract_refs) pair: messages_as_str() converts a list of messages into a numbered string representation, using auto-incrementing labels ([M1], [M2], etc.). If called multiple times within