Grader assigns the reward for the single sample produced by a rollout execution.
Grader Base Class
grade() receives the sample, reference label, metadata, and optional artifacts directory through GraderContext.
GraderContext
Thectx 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.
Writing Artifacts
Usectx.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.
ctx.artifacts_dir. Artifact collection never affects rewards or rollout status.
RolloutSample
ctx.sample is a RolloutSample object containing the AgentWorkflow’s output:
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.
Implementation Patterns
Exact Match Grading
The simplest grading strategy is to compare the agent’s final text againstctx.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 astoolUse content blocks on assistant messages:
GraderConfig
Custom grader configs follow the same pattern asAgentWorkflowConfig: extend GraderConfig, create an instance, and pass it explicitly to the backend:
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: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.