RewardFunction
Protocol defining the interface for reward functions.dict
Task dictionary containing question, answer, and other metadata.
str | Action
Agent’s response/solution. Can be a string or Action object.
RewardOutput
Reward output containing reward value and metadata.
RewardOutput
Dataclass for reward function results.float
The computed reward value (typically 0.0 or 1.0).
dict
Additional information about the evaluation.
Built-in Reward Functions
math_reward_fn
Reward function for mathematical reasoning tasks.answerorground_truth: Expected answerdata_source: Dataset identifier (optional)
code_reward_fn
Reward function for code generation tasks with execution-based evaluation.test_cases: List of input/output test pairsentry_point: Function name to testtimeout: Execution timeout in seconds (optional)
search_reward_fn
Reward function for information retrieval and question answering tasks.ground_truthoranswer: Expected answersupporting_facts: Supporting evidence (optional)data_source: Dataset identifier (optional)
f1_reward_fn
Generic F1 score-based reward function using token overlap.- Normalizes text (lowercase, remove punctuation/articles)
- Computes token-level precision and recall
- Returns F1 score as reward
zero_reward
Placeholder reward function that always returns 0.Custom Reward Functions
Example: Custom Keyword Reward
Example: Custom Length Penalty
Example: Multi-Criteria Reward
Using Rewards in an AgentFlow
Modern agents use theEvaluator protocol — a separate function that
reads the Episode produced by an AgentFlow and returns an EvalOutput.
The reward functions in rllm.rewards are wrapped inside the evaluator:
cookbooks/math/math_eval.py
for the full version that this snippet is adapted from.

