页面简介
Asking a person to decide about a step with human(), and handling escalations with handle_escalation().
正文摘录
Overview The human() protocol asks a person to decide about a step. The person sees the step and chooses to approve it, reject it, or end the sample, and their answer becomes the protocol’s decision. Usually you don’t want a person asked about every step. A rule or a monitor settles the clear cases and escalates the steps it is unsure about. With human() after it in a sequential(), the person is asked only about the escalated steps. When there is nobody to ask, handle_escalation() answers escalations with a fixed policy instead. Asking a Person human() takes the stages to ask at. The stages are given as strings, which correspond to the stages a protocol can run at: String Stage The person decides about "tool_call" BeforeToolCall A tool call, before it runs. "tool_result" AfterToolCall A tool call’s result, before the agent’s model receives it. "model_input" BeforeGenerate A request to the agent’s model, before it is sent (see Model Requests). "model_output" AfterGenerate A whole assistant turn, before the agent acts on it (see Whole Turns). stages is required, and you can give several. On its own, human(stages=["tool_call"]) asks about every tool call, like Inspect’s human approver. To ask only about some tool calls, put human() at the end of a sequential() after a rule that escalates. Here is examples/escalate_to_human.py: examples/escalate_to_human.py from example_samples import ADD_HOST, CLEANUP, COUNT_ROWS from inspect_ai import Task, task from inspect_ai.agent import react from inspect_ai.tool import bash, python from inspect_sentinel import ( BeforeToolCall, Context, Decision, Escalations, Protocol, call_text, find_words, human, protocol, sequential, tool_matches, ) DELETE_WORDS = ["rm", "rmdir", "-delete", "shutil.rmtree", "os.remove"] @protocol def triage() -> Protocol: async def decide( context: Context, step: BeforeToolCall, escalations: Escalations, ) -> Decision | None: if not tool_matches(step.call, "bash", "python"): return Decision.proceed() text = call_text(step.call) if "/etc" in text: 1 return Decision.reject( "call mentions /etc", message="`/etc` is off limits; work only under /work.", ) deletes = find_words(text, DELETE_WORDS) if deletes: 2 return Decision.escalate(f"call deletes files ({', '.join(deletes)})") 3 return Decision.proceed() return decide @task def escalate_to_human() -> Task: return Task( dataset=[CLEANUP, ADD_HOST, COUNT_ROWS], solver=react(tools=[bash(timeout=60), python(timeout=60)]), sandbox=("docker", "compose.yaml"), message_limit=20, 4 sentinel=sequential([triage(), human(stages=["tool_call"])]), ) 1 A tool call that mentions /etc is rejected without asking anyone. 2 A tool call that deletes files is escalated, with an explanation the person will see. 3 Every other tool call proceeds. Returning None here instead would pass the tool call on to human(), and the person would be asked about it too. 4 human() runs only when triage() escalates. Run it from the repository root: inspect eval examples/escalate_to_human.py --model openai/gpt-5-mini When the agent tries to delete files, the eval pauses and asks you to approve, reject or terminate. The prompt shows the tool call and that triage escalated it because the tool call deletes files. The eval waits for each answer, so run it where someone can answer. Choices choices sets what the person may pick. The defaults depend on the stage: Stage Default choices "tool_call" approve, reject, terminate "tool_result" approve, terminate "model_input" approve, terminate "model_output" approve, terminate reject is offered only before a tool call (see Actions), and rejecting a request or a whole turn is not supported. Offering a choice a stage doesn’t allow raises an error when human() is created. "modify" is accepted before a tool call, but Inspect’s approval channels cannot edit a tool call, so offering it raises an error when the person is asked. Your own review tool cannot be offered "modify" yet either. The answer maps to a decision: approve to proceed, reject to reject, and terminate to terminate. The reason recorded with the answer becomes the decision’s explanation, and on a reject it is also the message the agent receives. The person doesn’t enter a reason: the approval panel and console record a fixed text, such as “Human operator rejected the tool call.”, and an ACP client (an editor or tool that speaks the Agent Client Protocol) records none, so the agent is told “Tool call not approved.” Whole Turns At "model_output", the person decides about a whole assistant turn: its text and every tool call it makes, before any of the tool calls run. Use it when the combined effect of several tool calls matters. Approve lets the turn proceed unchanged, and terminate ends the sample. examples/escalate_turn_to_human.py escalates any turn whose tool calls delete files: Task(..., sentinel=sequential([turn_triage(), human(stages=["model_output"])])) Its turn_triage() rule runs at AfterGenerate. It reads the tool calls from step.output.message.tool_calls and escalates the turn, saying how many of them delete files. Run it with: inspect eval examples/escalate_turn_to_human.py --model openai/gpt-5-mini Model Requests At "model_input", the person decides about a request before the agent’s model is sent it. Use it when what reaches the model matters, such as a tool’s output or a document the agent read. Approve sends the request, and terminate ends the sample without sending it. The person sees the request before any on_before_model_generate hook runs, so a hook that changes requests changes this one after it is approved. The person is shown how many messages the request sends, the tools it offers and which the model must call, and each message the model has not been sent before. That includes a message the scaffold rewrote since it was sent, and an assistant message the scaffold wrote itself, wherever they are in the request. The prompt has limits. A message the model was sent before is not shown again, even if it has moved, and neither is the fact that one was removed. A message that repeats an earlier one, such as an agent’s fixed prompt to continue, is shown when the request holds more copies of it than any request the model was sent before. Images and other content that is not text are counted, not shown. Tools are shown by name, without their descriptions or parameters. Inspect’s TUI shows the first lines of a long prompt, so expand it to read the rest before deciding. The console and the approval panel show no other part of the conversation. The eval’s log has the earlier requests, so the messages sent before can be read there. It has this request only once it is sent. Task(..., sentinel=sequential([request_triage(), human(stages=["model_input"])])) Here request_triage() stands for a rule of your own at BeforeGenerate: it reads the request from step.input and escalates the ones a person should see. On its own, human(stages=["model_input"]) asks before every request. What the Person Sees The person is asked through Inspect’s human approval channels: an attached ACP client, the approval panel in the full-screen display, or the console otherwise (for example, with --display plain). The prompt shows the tool call, the escalations that led to it, and, after a tool call, its result. At "model_output" it shows the turn’s text, the escalations, and each tool call as a numbered code block. At "model_input" it shows the escalations, the tools offered, and each message not sent before as a numbered code block. Characters that change how text displays, such as terminal escape sequences and zero-width characters, appear in the prompt as a marker of their code point, such as ‹U+001B›. Your Own Review Tool If your team already has a tool for reviewing agent actions, such as a web app or a chat bot, human() can ask through it instead of Inspect’s approval channels. For example, you might want to: Keep using the review interface your team already knows. Show reviewers every monitor’s score, or your own rendering of a turn. Let reviewers type the reason the agent is told on a reject. Pass the tool as channel, an async function that takes a HumanQuestion and returns the person’s HumanAnswer. Here review_desk stands for your team’s client for its review tool: from inspect_sentinel import HumanAnswer, HumanQuestion, human, sequential async def ask_review_desk(question: HumanQuestion) -> HumanAnswer: ticket = await review_desk.open( stage=question.stage, sample=question.eval.sample_id if question.eval else None, escalations=[ (e.name, e.report.explanation, e.report.metadata) for e in question.escalations ], choices=question.choices, ) decision, reason = await review_desk.wait(ticket) return HumanAnswer(decision, reason) Task( ..., sentinel=sequential( [triage(), human(stages=["tool_call"], channel=ask_review_desk)] ), ) human() works as before at every stage. The only difference is who asks the person. The Question The HumanQuestion holds what the person needs to decide: Field Holds stage "tool_call", "tool_result", "model_input" or "model_output". step The step itself: a BeforeToolCall with the tool call, an AfterToolCall with the call and its result, a BeforeGenerate with the request about to be sent, or an AfterGenerate with the whole assistant turn. See Stages for their fields. escalations Each escalation that led here, with the name of the protocol that escalated and its full report: the explanation, references and metadata. A threshold() escalation lists every monitor’s score and explanation in metadata["observations"]. Empty when nothing escalated. choices What the person may pick, from approve, reject and terminate. eval The task and sample being run (e.g. eval.sample_id, eval.epoch), so your tool can say which sample is waiting. proxy When the sentinel runs beside a proxy, what the proxy says about the request; otherwise None. The step and the explanations hold text the agent wrote, so show them as text in your tool, not as markup. The Answer Return a Hu