Skip to content

feat(legal-agent-bench): add native execution through agent sessions - #5968

Closed
rystewart-nvidia wants to merge 36 commits into
NVIDIA-NeMo:mainfrom
rystewart-nvidia:lab-refresh/native
Closed

rystewart-nvidia wants to merge 36 commits into
NVIDIA-NeMo:mainfrom
rystewart-nvidia:lab-refresh/native

Conversation

@rystewart-nvidia

@rystewart-nvidia rystewart-nvidia commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

What does this PR do?

Add a native LAB agent that uses Gym's shared agent sessions. The official Harvey LABs implementation uses a native agent that this implementation mirrors. Depends on #5792 which has its own PR dependencies. Will rebase onto main once 5792 merges.

  • LAB resources server manages the sandbox creation, task input staging, output collection, and stoppage/teardown. It also creates and cleans up a separate verifier sandbox for grading.
  • The agent borrows a connection to the task sandbox. Closing the agent session stops its tool processes and disconnects; sandbox teardown remains the resources server's responsibility.
  • Use LAB's tools and finish behavior with the same task source and judges as the existing Harbor LAB path. Keep judge credentials and hidden criteria out of the agent sandbox.
  • Retain outputs and grading reports. Bound archive transfer and extraction, reject unsafe entries, and preserve cleanup handles when teardown needs a retry.
  • Include activation setup and staging in the agent deadline. Return a scoreable incomplete result only after confirmed cleanup; provider and cleanup failures remain operational errors.
  • Set resources-server concurrency from num_samples_in_parallel, defaulting to one.

Validation

All 281 tests in the LAB, native-agent, benchmark, and shared-executor suites passed. All-files pre-commit and import checks passed.

From the repository root, run below to test:

git archive HEAD | docker run --rm -i --cpus 4 --memory 8g --pids-limit 1024 \
  --mount type=volume,src=gym-lab-test-uv,dst=/uv-cache \
  -e UV_CACHE_DIR=/uv-cache -e UV_LINK_MODE=copy \
  python:3.13.14-slim-bookworm bash -c '
set -euo pipefail
mkdir /workspace
tar -xf - -C /workspace
cd /workspace
apt-get update -qq
apt-get install -y --no-install-recommends git procps curl ca-certificates libgomp1
python -m pip install uv==0.13.7
uv sync --locked --project responses_api_agents/harbor_agent_general
export PYTHONPATH=/workspace LITELLM_LOCAL_MODEL_COST_MAP=True
responses_api_agents/harbor_agent_general/.venv/bin/python -m pytest \
  resources_servers/legal_agent_bench/tests \
  responses_api_agents/legal_agent_bench_native/tests \
  benchmarks/legal_agent_bench/tests \
  tests/unit_tests/agents/test_sandbox_session.py \
  --import-mode=importlib -q --tb=short -ra
'

LITELLM_LOCAL_MODEL_COST_MAP=True avoids downloading model prices during imports.

Rollouts

Ran all five example.jsonl tasks through Gym's native LAB agent and Docker with openai/openai/gpt-5.6-sol. Each run called finish, retained its DOCX outputs and both judge reports, and completed without operational or judge errors. Profiling covered all five runs; none were masked.

Example task Claude Sonnet 4.6 criteria passed GPT-5.5 criteria passed Reward
Trust documents 21/23 22/23 0
Transition services agreement 68/75 71/75 0
Compliance program 44/49 45/49 0
ADA accommodation 45/55 47/55 0
Document production review 57/67 55/67 0

Neither judge passed every criterion on any task, so all full-task rewards were zero. These runs check the integration, not benchmark performance.

Live provider checks passed for Enroot, Apptainer, OpenSandbox, and OpenShell: reattachment, supervised execution, owner survival after disconnect, exact 1 MiB artifact transfer, separate verifier state, and teardown. Apptainer's root/fakeroot execution also passed. Its nested cgroup limits could not be validated; the test container enforced the outer limits. Fargate's ECS/S3, transfer, ownership, and cleanup checks passed with LocalEmu; real AWS provisioning remains untested because I don't have AWS credentials for testing.

Configure policy and judge endpoints in env.yaml using the LAB evaluation guide. This run used Claude Sonnet 4.6 and GPT-5.5 through a shared endpoint:

# env.yaml
judge_base_url: https://your-judge-endpoint.example/v1
judge_api_key: your-judge-key
lab_judges:
  - model_name: azure/anthropic/claude-sonnet-4-6
  - model_name: openai/openai/gpt-5.5

Replace the URL and key with your endpoint settings, and use the model IDs your endpoint accepts. Both judges inherit the shared URL and key; individual entries can override them with base_url and api_key. For single judging, keep just one entry.

From the repository root:

PYTHONPATH=. uv run --locked --project resources_servers/legal_agent_bench \
  python -m resources_servers.legal_agent_bench.prepare \
  --input resources_servers/legal_agent_bench/data/example.jsonl \
  --tasks-dir results/lab-native-smoke/tasks \
  --skills-dir results/lab-native-smoke/skills

cat > lab-native-smoke.yaml <<'YAML'
num_samples_in_parallel: 2
responses_create_params:
  max_output_tokens: 65536
legal_agent_bench_benchmark_resources_server:
  resources_servers:
    legal_agent_bench:
      harbor_tasks_cache_dir: results/lab-native-smoke/tasks
      harness_skills_dir: results/lab-native-smoke/skills
      auto_prepare_assets: false
      agent_timeout_seconds: 1200
      verifier_timeout_seconds: 1200
      judge_request_timeout_seconds: 120
legal_agent_bench_benchmark_native_agent:
  responses_api_agents:
    legal_agent_bench_native:
      max_turns: 40
      agent_timeout_seconds: 1200
      model_timeout_seconds: 300
YAML

gym env start --config benchmarks/legal_agent_bench/config_native.yaml \
  --config responses_api_models/openai_model/configs/openai_model.yaml \
  --config lab-native-smoke.yaml

# In another terminal:
gym eval run --no-serve \
  --config benchmarks/legal_agent_bench/config_native.yaml \
  --config responses_api_models/openai_model/configs/openai_model.yaml \
  --config lab-native-smoke.yaml \
  --agent legal_agent_bench_benchmark_native_agent \
  --input resources_servers/legal_agent_bench/data/example.jsonl \
  --output results/lab-native-smoke.jsonl --num-repeats 1 --limit 5 --concurrency 2

gym eval profile \
  --inputs results/lab-native-smoke_materialized_inputs.jsonl \
  --rollouts results/lab-native-smoke.jsonl

Compatibility and benchmark impact

Harbor remains the default. The LAB native agent uses an Environment Server with single_agent_turn_legacy for Gym JSONL task rows. Select benchmarks/legal_agent_bench/config_native.yaml to use the native agent; task rows and judge configuration stay the same. Harness changes can affect scores. Automatic LAB image building requires Docker; other providers need a prepared compatible image.

Checklist

  • I have read the contributing guidelines.
  • The change is focused; unrelated "drive-by" edits are tracked as separate issues/PRs.
  • Tests added or updated and pass locally, or N/A for docs-only / non-code changes (so CI unit/server checks pass when applicable).
  • Documentation added or updated, or N/A with justification.
  • Pre-commit checks pass locally (pre-commit run --all-files) (so CI lint/format checks pass).
  • New source files include the required Apache-2.0 SPDX header.
  • All commits have DCO sign-off (git commit -s) (so the DCO check passes).

@copy-pr-bot

copy-pr-bot Bot commented Nov 10, 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 Nov 10, 2026
Signed-off-by: Ryan Stewart <[email protected]>

# Conflicts:
#	resources_servers/legal_agent_bench/app.py
#	resources_servers/legal_agent_bench/tests/test_app.py
@github-actions github-actions Bot added the sla:triage-overdue Review assignment is over the one-business-day SLA label Nov 11, 2026
@rystewart-nvidia

Copy link
Copy Markdown
Contributor Author

Superseded by #5788, which includes the LAB Native agent and Harbor Environment Server integration.

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 sla:triage-overdue Review assignment is over the one-business-day SLA

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant