Skip to content

Rewards

The catalog a reward's type names, and the rewards openarena adds to it.

rewards

Reward registry + YAML resolver.

Combines the framework's built-in Reward subclasses (auto-discovered via the framework's reward registry) with the project-local rewards the framework has no equivalent of (MultiJudgePanel, AnswerAccuracy, RetrievalRecall, ToolCallsAccuracy) into a single _REWARD_TYPES map keyed by the reward's snake_case class name. The rubrics, agent, recursive and deep judges that used to live here ship with the framework since 0.10. get(spec) instantiates a reward from either a string name ("exact_match") or a YAML-shaped dict; string language_model: / embedding_model: values flow straight into the reward constructor — the framework resolves them via language_models.get / embedding_models.get — and a {model, ...params} mapping (a models.yaml entry with params) is built into that model first.

get

get(spec, **kwargs)

Resolve a reward spec into an instantiated rewards.Reward.

spec can be: - A string snake_case reward name, e.g. "exact_match". - A dict shaped like the YAML config:

name: lm_as_judge
language_model: ollama/llama3.2
instructions: |
  ...
Every key besides name is forwarded as a kwarg to the reward constructor. String language_model: / embedding_model: values pass through verbatim — the framework resolves them into concrete LanguageModel / EmbeddingModel instances on demand. A model given as a mapping, {model: openai/gpt-4o, temperature: 0.0} (what Config resolves a models.yaml entry with params to), is built here with those params. An answer_fields: list scopes the reward to those top-level fields (AnswerFields).

Parameters:

Name Type Description Default
spec

Snake_case name or config dict (see above).

required
**kwargs

Extra constructor kwargs, merged on top of any in spec.

{}

Raises:

Type Description
KeyError

If no reward is registered under the resolved name.

accepted_kwargs

accepted_kwargs(name: str) -> set[str]

The config keys the reward registered as name takes: its named constructor kwargs, less the hidden ones, plus the masks.

category

category(name: str) -> str

How the reward registered as name scores: rubrics_judge, agent_judge, lm_judge or deterministic.

A named override, else its base class, else what it calls out to: a deterministic reward compares by rule or by embedding, with no judge.

AnswerAccuracy

AnswerAccuracy(schema=None, in_mask=None, out_mask=None, in_mask_pattern=None, out_mask_pattern=None, name='answer_accuracy')

Grade each field of the answer with the deterministic metric that fits its type, and average.

Parameters:

Name Type Description Default
schema

Optional. The output_schema (JSON Schema) each field is routed by; a field it does not declare is routed by its value.

None
in_mask / in_mask_pattern

The fields to grade, by name or by pattern; every field of the target otherwise.

required
out_mask / out_mask_pattern

Names left out of the comparison, at every level.

required
name

The reward instance's name.

'answer_accuracy'

fields

fields(target: dict) -> list[str]

The target's fields to grade: what the in-mask keeps, less what the out-mask drops.

MultiJudgePanel

MultiJudgePanel(panel_language_models=None, smart_language_model=None, agreement_threshold=0.2, prompt_template=None, examples=None, instructions=None, name='multi_judge_panel', in_mask=None, out_mask=None, reduction='mean', in_mask_pattern=None, out_mask_pattern=None, program=None)

Judge panel: multiple small LMs vote, smart LM breaks ties.

Each (y_true, y_pred) is scored in parallel by every model in panel_language_models. If the spread between the lowest and highest panel scores is <= agreement_threshold, the panel is treated as in agreement and the panelist whose score is closest to the mean wins. If the spread exceeds the threshold, smart_language_model is invoked and its verdict overrides the panel.

Example:

program.compile(
    reward=MultiJudgePanel(
        panel_language_models=[
            "ollama/llama3.2",
            "ollama/mistral",
            "ollama/qwen",
        ],
        smart_language_model="openai/gpt-4o",
        agreement_threshold=0.2,
        instructions="Score 0.0–1.0 on factual correctness.",
    ),
)

Parameters:

Name Type Description Default
panel_language_models list

The panelists, each given as a LanguageModel, a config dict, or a string identifier (e.g. "ollama/llama3.2"). Required.

None
smart_language_model

Escalation model used on disagreement. Same forms as panelists. Required.

None
agreement_threshold float

Maximum allowed (max - min) panel score spread for the panel to be deemed "in agreement" (default 0.2).

0.2
prompt_template str

The default jinja2 prompt template forwarded to every panelist and the smart judge.

None
examples list

The default examples forwarded to every judge.

None
instructions str

The default judging-task instructions forwarded to every judge (same prompt, different LMs).

None
name str

Optional. string name of the reward instance (default "multi_judge_panel").

'multi_judge_panel'
in_mask list

Optional. list of keys to keep to compute the reward.

None
out_mask list

Optional. list of keys to remove to compute the reward.

None
reduction str

Optional. How per-sample rewards are reduced over a batch — one of "mean" (default), "sum", "min", "max", "none".

'mean'
in_mask_pattern str

Optional. Regex; fields whose names match are kept (OR-combined with in_mask).

None
out_mask_pattern str

Optional. Regex; fields whose names match are dropped (OR-combined with out_mask).

None

RetrievalRecall

RetrievalRecall(name='retrieval_recall', in_mask=None, out_mask=None, in_mask_pattern=None, out_mask_pattern=None)

Recall of the target's list fields in the prediction's.

ToolCallsAccuracy

ToolCallsAccuracy(name='tool_calls_accuracy', in_mask=None, out_mask=None, in_mask_pattern=None, out_mask_pattern=None)

How many of the gold tool calls the model made, with the right arguments and nothing extra.

HarborVerifier

HarborVerifier(key='reward', name='harbor_verifier', in_mask=None, out_mask=None, in_mask_pattern=None, out_mask_pattern=None)

The verifier's score for the row: rewards[key] of the Harbor trajectory.