Skip to content

Tutorial: How to build and design verifiers with a new agent skill in Gym #1702

Open

Description

@sephmard

Background

Verifiers are the core of every NeMo Gym environment — they define what counts as a correct agent response and produce the reward signal used for both evaluation and RL training. Despite this central role, there is no single tutorial that walks a user through the full verifier design lifecycle. Related gaps:

This ticket proposes a standalone tutorial page that takes a user from a minimal verifier to a production-ready one, and shows how to iterate on it efficiently.


Proposed tutorial outline

1. The verifier contract

Explain the three moving parts every verifier must implement, grounded in nemo_gym/base_resources_server.py:

  • seed_session — populates the session with the ground-truth data the agent will need
  • verify — receives the agent's full trajectory and returns a BaseVerifyResponse with a scalar reward
  • aggregate_metrics — inherited from AggregateMetricsMixin; profiles every numeric field in verify responses across a rollout batch

Minimal skeleton:

from nemo_gym.base_resources_server import (
    BaseResourcesServerConfig, BaseVerifyRequest, BaseVerifyResponse, SimpleResourcesServer
)

class MyVerifyRequest(BaseVerifyRequest):
    expected_answer: str

class MyServer(SimpleResourcesServer):
    async def verify(self, body: MyVerifyRequest) -> BaseVerifyResponse:
        correct = body.messages[-1].content.strip() == body.expected_answer
        return BaseVerifyResponse(**body.model_dump(), reward=1.0 if correct else 0.0)

2. Rule-based verifiers

Walk through resources_servers/equivalence_rule/app.py as the canonical example. Cover:

  • Selecting a grading rule via config (GradingRule enum)
  • Exact match vs. fuzzy match (SequenceMatcher)
  • When rule-based is appropriate (deterministic outputs, structured answers)

3. Library-based verifiers

Walk through resources_servers/math_with_judge/app.py — using math_verify as a symbolic grader before falling back to an LLM judge. Cover:

  • Calling an external grading library
  • Handling timeouts and concurrency (library_verifier_timeout_seconds, library_verifier_max_concurrency)
  • Chaining a library check with an LLM fallback

4. LLM-as-judge verifiers

Cover the pattern where no deterministic rule exists and a judge model scores the response. Cover:

  • Constructing a judge prompt
  • Calling the judge via nemo_gym.openai_utils
  • Normalizing the judge score to [0, 1]
  • Cost and latency trade-offs vs. rule-based

5. Multi-reward verifiers

Walk through resources_servers/example_tool_call_multireward/app.py. Cover:

  • Adding reward_components: Dict[str, float] to the verify response
  • How aggregate_metrics automatically profiles each component (correctness, format, schema_valid) independently
  • Evaluation use case: reward profiling to diagnose how an agent fails, not just whether it fails
  • RL use case: exposing components as reward1, reward2, ... for GDPO (cross-reference docs: multi-reward verification #1661)

6. Testing your verifier locally

Show how to use ng_test against a resource server before wiring it into a full benchmark run:

ng_test +entrypoint=resources_servers/my_server

7. Iterating without re-running the policy

Surfaces the patterns from #1499:

  • Tuning reward weights, thresholds, and judge prompts via YAML config overrides without creating a new server implementation
  • Re-scoring stored rollouts when only the scoring function changed — avoiding re-invoking the policy model
  • A/B comparing two verifier variants on the same rollout set for fair calibration
  • When full re-rollout is unavoidable vs. when config overrides or offline re-scoring are sufficient

Acceptance criteria


Reference implementations in-tree

Pattern Resource server
Minimal / rule-based resources_servers/equivalence_rule/
Library + LLM judge resources_servers/math_with_judge/
Multi-reward resources_servers/example_tool_call_multireward/
Simple baseline resources_servers/example_single_tool_call/

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions