ExAgent.Judge (ExAgent v2.3.0)

View Source

A second model that reviews the agent's work: final answers before they are accepted, and tool calls before they run.

Review final answers

check =
  ExAgent.Judge.output_validator(
    model: reviewer_model,
    criteria: "Answers every question asked, cites the tool results it relies on."
  )

ExAgent.new(model: model, tools: tools, output_validators: [check], output_retries: 2)

The reviewer sees a bounded text transcript of the conversation (the latest user message and the most recent entries) and the final answer, and replies PASS or FAIL with feedback; a reply in another format is asked again once. On FAIL the feedback goes back to the agent, which continues and answers again; that uses the :output_retries budget, so the run fails with {:unexpected_model_behavior, {:output_retries_exhausted, _}} if the answer never passes. Inside a run the reviewer runs through ExAgent.run_child/4, so its usage counts toward the run's usage and limits; with a persisted continuation it runs as a separate run whose usage is not added.

Review tool calls

approve =
  ExAgent.Judge.approver(
    model: reviewer_model,
    policy: "Reading is fine. Writes only inside /tmp. Never delete files.",
    escalate: &MyApp.ask_a_human/1
  )

ExAgent.run(agent, prompt, permissions: perms, approve: approve)

Use it as the :approve callback for tools whose permission is :ask. The reviewer sees the tool name and arguments and answers ALLOW, DENY or ASK; ASK calls :escalate (a human, for example), and without one the call is denied. Each review is a separate run whose usage is not added to the agent's run, and it counts toward the reviewed tool's timeout (see approver/1).

The reviewer is a model: it can be wrong or manipulated by content it reviews. Keep hard limits in ExAgent.Permissions and in the tools themselves. Telemetry: [:exagent, :judge, :verdict] with metadata %{kind, verdict} (kind is :output or :approval).

Summary

Functions

An :approve callback for ExAgent.run/3 that asks :model whether a tool call follows :policy.

An output validator (see ExAgent.new/1 :output_validators) that asks :model whether the final answer meets :criteria.

Functions

approver(opts)

@spec approver(keyword()) :: (ExAgent.Message.Part.ToolCall.t() -> :approve | :deny)

An :approve callback for ExAgent.run/3 that asks :model whether a tool call follows :policy.

Options: :model and :policy (required); :model_settings; :escalate, a fn tool_call -> :approve | :deny end used for ASK verdicts and reviewer failures (default: deny); :timeout, the reviewer's deadline in milliseconds (default 20_000), after which the call is escalated.

The :approve callback receives only the tool call, not the run, so each review is a separate run: its usage is not added to the run's usage, limits or cost. The review and any escalation happen inside the tool call and count toward that tool's timeout (:tool_timeout by default); keep :escalate quick, or give the reviewed tools a longer timeout.

output_validator(opts)

@spec output_validator(keyword()) :: ExAgent.output_validator()

An output validator (see ExAgent.new/1 :output_validators) that asks :model whether the final answer meets :criteria.

Options: :model and :criteria (required); :model_settings; :max_transcript_bytes (default 24_000); :on_error, :accept (default) or :fail, when the reviewer fails or twice replies in another format. The answer is never accepted unreviewed because the run's own deadline, usage limits or cancellation stopped the reviewer.