Class Evaluators

Object
akka.javasdk.testkit.eval.Evaluators

public final class Evaluators extends Object
The built-in evaluators, and the labels used in the report to group evaluator results.

Each factory returns an Evaluator for one check over the reply and the traced tool calls. An evaluator reads only the evidence it names and is inconclusive when that evidence is absent: a tool that was never called fails shouldCallTools(java.lang.String...), and shouldCallToolWith(java.lang.String, java.lang.String, java.lang.Object) is inconclusive. Give the evaluators to an EvalCase, next to a Judge or a custom evaluator.

Each built-in is a public nested record carrying an EvalLabel. Pass its class to Gate.passRateShouldBeAtLeast(Class, double), for example Evaluators.ToolArgument.class. TARGET and SETUP are reported by the runner when a case did not reach evaluation.

  • Field Details

  • Method Details

    • label

      public static String label(Class<? extends Evaluator> evaluator)
      The label used in the report to group the evaluator's results. It is the EvalLabel value, with CUSTOM_PREFIX added for a custom evaluator.
      Throws:
      IllegalArgumentException - when the class carries no label, a blank label, or a label that starts with CUSTOM_PREFIX
    • shouldCallTools

      public static Evaluator shouldCallTools(String... names)
      These tools must be called, in any order. Other calls are allowed.
    • shouldCallTool

      public static Evaluator shouldCallTool(String name)
      This tool must be called. Other calls are allowed.
    • shouldCallToolsInOrder

      public static Evaluator shouldCallToolsInOrder(String... names)
      These tools must be called in this relative order. Calls to other tools may come between. Inconclusive when one of them was never called.
    • shouldCallToolWith

      public static Evaluator shouldCallToolWith(String tool, String argument, Object value)
      The named tool must be called with this argument value. Numbers compare by value. Inconclusive when the tool was never called.
    • toolResultShouldContain

      public static Evaluator toolResultShouldContain(String tool, String text)
      The result of the named tool must contain this text, case-insensitively. Inconclusive when the tool was never called or the trace carries no result for it.
    • shouldNotCallTools

      public static Evaluator shouldNotCallTools(String... names)
      None of these tools may be called.
    • shouldNotCallTool

      public static Evaluator shouldNotCallTool(String name)
      This tool may not be called.
    • shouldMakeAtMostToolCalls

      public static Evaluator shouldMakeAtMostToolCalls(int calls)
      The agent may make at most this many tool calls while replying.
    • shouldMakeAtMostModelCalls

      public static Evaluator shouldMakeAtMostModelCalls(int calls)
      The agent may make at most this many model calls while replying. Inconclusive when the trace carried no model calls.
    • shouldUseAtMostTokens

      public static Evaluator shouldUseAtMostTokens(long tokens)
      The turn may use at most this many tokens, input and output together. Inconclusive when no model call reported tokens, as with a mocked model.
    • shouldReplyWithin

      public static Evaluator shouldReplyWithin(Duration latency)
      The agent command must complete within this time. Inconclusive when the trace carries no timing.
    • replyShouldContain

      public static Evaluator replyShouldContain(String... texts)
      The reply must contain every given text, case-insensitively.
    • replyShouldMatch

      public static Evaluator replyShouldMatch(String regex)
      The reply must match the regular expression, anywhere in it. Anchor it for a full match. The expression is compiled with Pattern.DOTALL, so . also matches line breaks.
    • replyShouldMatch

      public static Evaluator replyShouldMatch(Pattern pattern)
      The reply must match the pattern, anywhere in it. Anchor the pattern for a full match.
    • replyShouldNotContain

      public static Evaluator replyShouldNotContain(String... texts)
      The reply must not contain any of the given texts, case-insensitively.
    • replyShouldNotMatch

      public static Evaluator replyShouldNotMatch(String regex)
      The reply must not match the regular expression anywhere in it. The expression is compiled with Pattern.DOTALL, so . also matches line breaks.
    • replyShouldNotMatch

      public static Evaluator replyShouldNotMatch(Pattern pattern)
      The reply must not match the pattern anywhere in it.
    • replyShouldNotContainLuhnNumber

      public static Evaluator replyShouldNotContainLuhnNumber(int minDigits, int maxDigits)
      The reply must not contain a sequence of digits within this length range that passes the Luhn checksum. Spaces and dashes are allowed between the digits.

      The Luhn checksum validates many identifiers besides payment cards, and each has its own length: an IMEI has 15 digits, a South African ID 13, a Canadian Social Insurance Number 9.

    • replyShouldNotContainPaymentCard

      public static Evaluator replyShouldNotContainPaymentCard()
      The reply must not contain a payment card number. A card number is a run of 13 to 19 digits, spaces and dashes allowed between them, that passes the Luhn checksum.