Skip to content

feat: litmus_agent resources server (domain-agnostic answer verifier + sandbox code-exec tool) - #1911

Merged
cmunley1 merged 9 commits into
NVIDIA-NeMo:mainfrom
OliviaViessmann:olivia/litmus-agent-pr
Jul 13, 2026
Merged

cmunley1 merged 9 commits into
NVIDIA-NeMo:mainfrom
OliviaViessmann:olivia/litmus-agent-pr

Conversation

@OliviaViessmann

Copy link
Copy Markdown
Contributor

What

Adds litmus_agent, a domain-agnostic answer-verification resources server — the generic generalization of the chemistry-specific rdkit_chemistry scorer (keeps the scoring path, drops everything RDKit/domain-specific).

  • Extracts the model's final answer, pulls a value via the requested answer_format regex (the fmt_00–fmt_30 wrapper family), and scores it against expected_answer via a small answer_type taxonomy (float/bool/string). Reward 1.0 on match, else 0.0.
  • Swappable reward rules: exact / isclose / abs_window / rel_window / bool_eq / string_eq.
  • Domain fields (smiles, property, …) are pass-through (extra="allow") — accepted and echoed, never required or interpreted. The example dataset uses chemistry only to illustrate this.
  • Optional sandbox-backed stateful Python code-exec tool when sandbox_provider is set — provider-neutral via nemo_gym.sandbox. Two configs: litmus_agent.yaml (OpenSandbox) and litmus_agent_apptainer.yaml (local Apptainer; no service/API key).

Why

Reusable scoring for any benchmark whose tasks reduce to "match the expected answer," with optional tool use. Backs the litmus-bench chemistry eval but isn't tied to it.

Tests

resources_servers/litmus_agent/tests/test_app.py — 71 tests (answer extraction/parsing, all reward rules, verify paths, and the sandbox code-exec tool: session isolation, state-persistence across cells, output truncation, session cleanup/shutdown). All pass; ruff-format clean; DCO-signed; verified: false set per new-env policy.

Notes

OliviaViessmann and others added 3 commits July 2, 2026 09:47
Add litmus_agent, a domain-agnostic answer verifier and generalization of
the rdkit_chemistry scorer with all RDKit/chemistry specifics removed.

- Extracts a model's final answer from the rollout via an answer_format
  regex (the fmt_00-fmt_30 wrapper-syntax family) and scores it against
  expected_answer using a small answer_type taxonomy (float, bool, string).
- Swappable, per-row reward rules (exact, isclose, abs/rel windows, bool_eq,
  string_eq) with sensible per-type defaults and a `match` override.
- Legacy property_type / use_box_format back-compat for older rows.
- Optional sandbox-backed stateful Python code-execution tool (lazy create,
  reaped at /verify) for tool-using rows; pure verifier when unset.
- Two configs: litmus_agent.yaml (OpenSandbox provider) and
  litmus_agent_apptainer.yaml (local Apptainer provider, no API key).
- README, example dataset, and tests.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Signed-off-by: OliviaViessmann <[email protected]>
OpenSandbox passes workdir as each command's working_directory and does not create it (unlike Apptainer, which creates its mount_point), so /workspace 400'd every code-exec. /tmp exists in the sandbox image.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Signed-off-by: OliviaViessmann <[email protected]>
Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Signed-off-by: OliviaViessmann <[email protected]>
@copy-pr-bot

copy-pr-bot Bot commented Jul 2, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@nemo-automation-bot nemo-automation-bot Bot added the community-request Issue reported or requested by someone from the community label Jul 2, 2026
@OliviaViessmann
OliviaViessmann marked this pull request as ready for review July 2, 2026 14:43
@svcnvidia-nemo-ci svcnvidia-nemo-ci added the waiting-on-maintainers Waiting on maintainers to respond label Jul 4, 2026
BaseVerifyResponse,
SimpleResourcesServer,
)
from nemo_gym.sandbox import AsyncSandbox, SandboxResources, SandboxSpec

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cc @hemildesai to check out sandbox!

@cmunley1

Copy link
Copy Markdown
Contributor

/claude review

@claude

claude Bot commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

SHIP WITH CARE — verifier scoring path is correct and well-tested; findings are edge-cases, not blockers.

Reviewed the core (app.py), configs, example data, deps, and the 71-test suite against the rdkit_chemistry server this generalizes.

What's solid:

  • Scoring correctness. verify() → resolve_answer_type → extract_predicted_value → compute_reward is clean. Reward rules are pure functions with sane defaults; None/NaN → 0.0; misconfigured rows fail loudly (unsupported answer_type, missing rule, unknown reward rule all raise) rather than scoring 0.0 silently. Legacy property_type back-compat is explicit and tested.
  • Async. No httpx, no ray.get. All coroutines awaited. Session concurrency is correct: _registry_lock guards the lock/session maps, per-session asyncio.Lock serializes a session's cells while allowing cross-session parallelism. Sandbox facade is provider-neutral.
  • Operability. Lazy sandbox creation (direct rows never need a provider/API key), per-rollout cleanup via the /verify wrapper, and a lifespan hook that reaps leaked sandboxes on shutdown. Route swap preserves the verify() contract.
  • Deps/hygiene. [sandbox] extra declared; provider imports are lazy so the core lib stays importable. verified: false set. Both configs (OpenSandbox + Apptainer) are coherent and well-commented.

Findings (all inline, none blocking):

  • RISK: driver exit-code protocol (0/1/2) collides with user-code SystemExit — a tool cell calling sys.exit(2) silently wipes session history. except Exception doesn't catch BaseException.
  • NOTE: replay is O(N²) per session and shares the single code_exec_timeout_s — long sessions can time out on replay alone.
  • NOTE: _parse_numeric's last-number fallback can miscore greedy fmt_22–fmt_30 on free-form text (inherited from rdkit; higher exposure here as a general verifier).
  • NOTE: **body.model_dump() in the verify response can 500 on a passthrough field named reward/correct/etc.

The RISK only affects the optional tool path's emulated state, not direct-scoring correctness. Fine to merge once the SystemExit handling is addressed or consciously accepted.

Comment thread resources_servers/litmus_agent/app.py Resolved

session, lock = await self._acquire_session(session_id)
async with lock:
result = await session.sandbox.exec(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NOTE — replay cost is O(N²) per session and shares the single code_exec_timeout_s.

Every call replays all prior cells before the new one, so a session's total exec work grows quadratically and each individual call's replay eats into the same 120s timeout_s. A long tool session (many cells, or one prior cell that's slow/non-deterministic) can start timing out on replay alone — surfacing as a spurious failure of the newest cell. The docstring flags the side-effect-replay cost but not the timeout interaction. Consider documenting the practical cell-count ceiling, or budgeting replay vs. new-cell time separately.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know -- that's why I'd love a persistent python kernel support via OpenSandbox :)
Discusssions on that are on-going in slack

Comment thread resources_servers/litmus_agent/app.py Resolved
Comment thread resources_servers/litmus_agent/app.py Outdated
)

return LitmusAgentVerifyResponse(
**body.model_dump(),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NOTE — **body.model_dump() splat can 500 the verify endpoint on a name-collision.

model_dump() includes all extra="allow" passthrough fields. If a dataset row carries a passthrough field named reward, correct, predicted_value, resolved_answer_type, or resolved_reward_rule, this becomes TypeError: got multiple values for keyword argument → 500, hanging the rollout rather than scoring it. Low probability (requires an oddly-named domain field), but since passthrough field names are author-controlled and unvalidated, consider popping the reserved keys from the dump first, or building the response via model_dump() merge instead of a splat.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed in 5557473. verify() now drops the reserved keys (reward, predicted_value, correct, resolved_answer_type, resolved_reward_rule) from the passthrough dump before the splat, so a colliding author-controlled domain field can't TypeError/500. Added test

OliviaViessmann and others added 4 commits July 13, 2026 15:52
…chemistry

Address PR review:
- Add example rollouts for the 5 direct (no-tool) rows, collected against
  gpt-oss-20b. Commit rollouts + aggregate metrics + materialized inputs.
- Update README Example Usage to the `gym env start` / `gym eval run` CLI.
- Deprecate rdkit_chemistry in favor of the domain-agnostic litmus_agent
  (README banner + config description; root README table regenerated).

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Signed-off-by: OliviaViessmann <[email protected]>
Address claude[bot] review findings:
- Code-exec driver caught only `except Exception`, so a user cell calling
  `sys.exit()`/raising SystemExit (a BaseException) escaped and its status was
  read as one of the driver's reserved control codes: `sys.exit(2)` silently
  reset the session, `sys.exit(0)` got the cell retained then desynced replay.
  Trap BaseException around both replay and the newest-cell exec so user code
  can never reach the reserved exit codes.
- verify() splatted `**body.model_dump()`, which includes extra="allow"
  passthrough fields. A row carrying a field named like one we set (reward,
  correct, ...) raised TypeError and 500'd the endpoint. Drop the reserved
  keys before the splat.

Add tests for both fixes plus the reset/malformed-body/string-content paths;
coverage back to 96%.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Signed-off-by: OliviaViessmann <[email protected]>
Address claude[bot] review notes:
- Warn that greedy answer_formats (fmt_22–fmt_30) can misparse trailing tokens;
  recommend delimited formats for numeric answers.
- Document that per-session replay is O(N²) and shares code_exec_timeout_s, so
  long tool sessions can time out on replay alone.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Signed-off-by: OliviaViessmann <[email protected]>
@svcnvidia-nemo-ci svcnvidia-nemo-ci removed the waiting-on-maintainers Waiting on maintainers to respond label Jul 13, 2026
@@ -0,0 +1,81 @@
litmus_agent:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i would also suggest putting configs/dataprep/instructions into environments/ or benchmarks/ but np for now we can do that in future as more envs are migrated..

@cmunley1
cmunley1 merged commit 059075e into NVIDIA-NeMo:main Jul 13, 2026
10 of 13 checks passed
cmunley1 pushed a commit that referenced this pull request Jul 13, 2026
… (#2008)

Follow-up to #1911, which was squash-merged just before the final
data-validation commit landed. As a result, `main` currently **fails**
`gym env test` data validation for `litmus_agent`:

- `example.jsonl` has 6 rows; the validator (`nemo_gym/cli/env.py`)
requires exactly 5.
- `example_metrics.json` is missing.

This PR applies only that missing fix:
- Drop the 6th (`mcp-python` tool-use) row so the example set is the 5
direct rows that have rollouts.
- Add the generated `example_metrics.json` (`gym dataset collate --mode
example_validation`).

The tool path remains covered by unit tests and documented in the
README/configs.

Verified locally:
```
gym env test +entrypoint=resources_servers/litmus_agent +should_validate_data=true
# -> The data for resources_servers/litmus_agent has been successfully validated!
```

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Signed-off-by: OliviaViessmann <[email protected]>
Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

community-request Issue reported or requested by someone from the community

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants