Skip to main content
Grader assigns the reward for the single sample produced by a rollout execution.

Grader Base Class

The base class signature from the SDK:
grade() receives the sample, reference label, metadata, and optional artifacts directory through GraderContext.

GraderContext

The ctx parameter passed to grade() provides:
With LocalBackend, a configured Grader runs whenever a dataset row has a label or metadata, so metadata alone can drive reward. With HarborBackend, an existing task tests/test.sh remains authoritative; the Osmosis Grader is installed as the verifier only when that file is absent. See Harbor reward precedence.
One workflow execution produces at most one sample. Evaluation and training can still execute the workflow multiple times for the same prompt ([evaluation].n in evaluation configs, n_samples_per_prompt in training configs); each independent execution receives its own GraderContext.

set_reward

Call ctx.set_reward(reward) to assign a reward to the rollout’s sample. The reward should be a float, typically between 0.0 and 1.0. Any finite float value is accepted, and NumPy-like numeric scalars are normalized to float.
set_reward raises a ValueError when ctx.sample is None. Check for a sample before scoring it; a missing sample usually means the workflow did not construct its supported agent or session inside run().
NaN, infinity, and non-numeric values raise pydantic.ValidationError because they violate the reward’s JSON wire contract. Return the intended numeric reward, or leave the reward unset (do not call set_reward) when the sample is “not graded”.

Writing Artifacts

Use ctx.artifacts_dir to persist rubric traces, diffs, or any other files your grader produces. The directory is per-rollout and shared with the workflow that produced the sample, so your grader can also read files the workflow wrote. It’s None when the environment can’t provision one, so guard with if ctx.artifacts_dir: before writing to it — an unguarded write raises and fails the grader.
After the rollout finishes, collected files appear alongside its sample in the run’s Artifacts panel on the Osmosis Platform, mirroring the layout you write under ctx.artifacts_dir. Artifact collection never affects rewards or rollout status.

RolloutSample

ctx.sample is a RolloutSample object containing the AgentWorkflow’s output:
The messages list is the conversation your workflow produced for that sample. In many graders, you only need to extract the final answer text from the last assistant message.
For real-world references, see rollouts/multiply-local-strands/main.py and rollouts/multiply-local-openai/main.py in the workspace-template repository. Those files are the source of truth for platform-created workspace repositories.

Implementation Patterns

Exact Match Grading

The simplest grading strategy is to compare the agent’s final text against ctx.label. The helper below extracts text from the last message:

LLM-as-Judge Grading

Use a separate LLM to evaluate agent outputs when correctness is subjective or hard to check programmatically. Judge calls do not need the rollout model integration used for policy calls, so you can call another LLM directly. Grading still runs synchronously after the workflow; its latency and failures affect the rollout.

Tool-Call Based Grading

Evaluate whether the agent made any tool calls, rather than just checking the final text output. Strands records tool invocations as toolUse content blocks on assistant messages:
You can combine multiple grading strategies — for example, check that the agent used the right tools and produced a correct final answer, then weight the scores together.

GraderConfig

Custom grader configs follow the same pattern as AgentWorkflowConfig: extend GraderConfig, create an instance, and pass it explicitly to the backend:
Pass the config instance to LocalBackend(grader_config=my_grader_config). Evaluation and training TOML files do not currently set grader config fields directly. GraderConfig extends BaseConfig and includes the same concurrency field as AgentWorkflowConfig, but current backends do not use it to limit grader concurrency. Use evaluation [evaluation].batch_size, workflow/backend concurrency, or an explicit limiter inside the grader when your grader calls external services.

Entry Point Wiring

Grader classes and config objects require explicit wiring. Select them in the backend constructor:
Multiple concrete Grader subclasses can coexist in the entrypoint; only the class passed as grader runs. Submit preflight imports the entrypoint once to surface constructor and dependency errors and does not inspect its module namespace; see Files in a Rollout for when that import is skipped and what it executes locally.

Next Steps

Evaluation

Submit an evaluation run to test your AgentWorkflow and Grader before a training run.
Last modified on August 10, 2026