ExAgent. Judge
(ExAgent v3.0.0)
View Source
A second model that reviews the agent's work: final answers before they are accepted, and tool calls before they run.
Stability — Candidate.
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. For a reply in another format, Judge sends one
reminder using the model state returned by that review. On FAIL the feedback
goes back to the agent, which answers again using the :output_retries budget. The
run fails with {:output_retries_exhausted, _}
if the answer never passes. In an ordinary run, ExAgent.run_child/4 charges
the review to the run's usage and limits. With a persisted continuation the
review runs separately, under the scope's deadline, and its usage is not
added. If the run or an ancestor sets a model request, token, cost or
concurrency limit, validation fails before sending the review, even when
capacity remains.
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).
Both constructors also accept classifier: classifier. The classifier's
instructions and choice descriptions define the review policy. Declare
"allow" and "deny", with an optional "ask" for abstention.
Use ExAgent.Judge.Approval to submit a decision for a persisted request.
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
@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.
The policy must be valid UTF-8 and contain a non-whitespace character.
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.
With :classifier, omit :model, :model_settings and :policy. The
classifier receives a JSON object with "tool_name" and "args".
Classifier approval cannot run inside a chat cassette.
Unknown or duplicate options raise ArgumentError when the callback is built.
The reviewer receives the complete JSON object, up to 8,192 encoded bytes.
If the arguments exceed that limit or cannot be represented as a JSON
object, the original call goes directly to :escalate (default: deny).
The :approval verdict event reports :error when review is unavailable.
During a run with an ExAgent.Fixture, the review records and replays through
that fixture. A replay miss or a :live_model_denied review is not escalated:
it fails the run with
{:tool_approval_failed, tool_name, {:exit, {:model_request_failed, %ExAgent.RequestError{provider: :fixture}}}}.
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.
@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.
Criteria must be valid UTF-8 and contain a non-whitespace character.
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
run fails if its deadline, usage or concurrency limits, strict accounting,
or cancellation stop the reviewer. For a durable run with model limits,
validation detects the conflict after the executor's request and returns
{:error, {:judge_failed, :continuation_child_descriptor_required}} even
with on_error: :accept. Under an ExAgent.Fixture the review replays from the
run's fixture; a replay miss or a :live_model_denied review fails with
{:judge_failed, {:model_request_failed, %ExAgent.RequestError{provider: :fixture}}}
even with on_error: :accept.
With :classifier, omit :model, :model_settings and :criteria. The
classifier receives a JSON object with "conversation" and "answer".
An abstention requests another answer using the ordinary retry budget.
The review consumes one admitted request with qualified usage. Classifier
validation needs a live execution scope and rejects C7 and chat cassettes
even with on_error: :accept.
Unknown or duplicate options raise ArgumentError when the validator is built.