Repository navigation
feat: litmus_agent resources server (domain-agnostic answer verifier + sandbox code-exec tool) - #1911
Conversation
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]>
| BaseVerifyResponse, | ||
| SimpleResourcesServer, | ||
| ) | ||
| from nemo_gym.sandbox import AsyncSandbox, SandboxResources, SandboxSpec |
|
/claude review |
|
SHIP WITH CARE — verifier scoring path is correct and well-tested; findings are edge-cases, not blockers. Reviewed the core ( What's solid:
Findings (all inline, none blocking):
The RISK only affects the optional tool path's emulated state, not direct-scoring correctness. Fine to merge once the |
|
|
||
| session, lock = await self._acquire_session(session_id) | ||
| async with lock: | ||
| result = await session.sandbox.exec( |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
I know -- that's why I'd love a persistent python kernel support via OpenSandbox :)
Discusssions on that are on-going in slack
| ) | ||
|
|
||
| return LitmusAgentVerifyResponse( | ||
| **body.model_dump(), |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
…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]>
# Conflicts: # README.md
| @@ -0,0 +1,81 @@ | |||
| litmus_agent: | |||
There was a problem hiding this comment.
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..
… (#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]>
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).
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