Skip to content

docs(tutorials): add Inspect AI evaluation tutorial and notebook - #628

Merged
burtenshaw merged 16 commits into
huggingface:mainfrom
sergiopaniego:feature/eval-inspect-tutorial
May 5, 2026
Merged

docs(tutorials): add Inspect AI evaluation tutorial and notebook#628
burtenshaw merged 16 commits into
huggingface:mainfrom
sergiopaniego:feature/eval-inspect-tutorial

Conversation

@sergiopaniego

Copy link
Copy Markdown
Member

Summary

Adds docs/source/tutorials/evaluation-inspect.md and a matching examples/evaluation_inspect.ipynb Colab notebook covering how to evaluate OpenEnv agents with Inspect AI's InspectAIHarness. The tutorial walks through defining a Task (dataset + solver + scorer), using asyncio.Semaphore to serialise concurrent env connections, and running a structured EvalResult via InspectAIHarness. Also adds model_base_url and max_connections forwarding to InspectAIHarness.run(), discovered as needed while writing the tutorial.

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation
  • New environment
  • Refactoring

Alignment Checklist

Before submitting, verify:

  • I have read .claude/docs/PRINCIPLES.md and this PR aligns with our principles
  • I have checked .claude/docs/INVARIANTS.md and no invariants are violated
  • I have run /pre-submit-pr (or bash .claude/hooks/lint.sh and tests) and addressed all issues

RFC Status

  • Not required (bug fix, docs, minor refactoring)
  • RFC exists: #___
  • RFC needed (will create before merge)

Test Plan

  • Build docs locally and confirm the page renders: cd docs && make html, then open docs/_build/html/tutorials/evaluation-inspect.html
  • Verify the Next Steps links resolve to https://meta-pytorch.org/OpenEnv/tutorials/
  • Open examples/evaluation_inspect.ipynb in Jupyter (or Colab); run all cells with a valid OpenAI or Anthropic API key — expected result: {'accuracy': 1.0} printed after the harness run
  • Run the existing harness unit tests: PYTHONPATH=src:envs uv run pytest tests/core/test_evals/test_inspect_harness.py -v — all 23 pass
  • Confirm no lint regressions in touched files: uv run ruff format src/openenv/core/evals/inspect_harness.py --check && uv run ruff check src/openenv/core/evals/inspect_harness.py

Claude Code Review

Automated Checks

  • Lint: PASS — inspect_harness.py was reformatted as part of this PR; pre-existing failures in chat_env, repl_env, textarena_env are not in scope
  • Debug code: CLEAN — no debug statements in any files touched by this PR

Open RFCs Context

  • RFC 005 (agentic-harnesses) covers the EvalHarness infrastructure this tutorial builds on. Changes here are additive and compatible — no conflicts.

Tier 1: Fixes Required

None.

Tier 2: Alignment Discussion

None identified. The tutorial uses MCPToolClient (correct for MCP envs), keeps all reward logic inside the environment, and does not expose reset controls to the agent. The harness change is a transparent parameter pass-through to inspect_ai.eval().

Summary

  • 0 mechanical issues
  • 0 alignment points for human review
  • 0 RFC conflicts

sergiopaniego and others added 11 commits April 30, 2026 18:03
Adds a tutorial and Colab notebook for evaluating OpenEnv agents with
Inspect AI via InspectAIHarness. Uses a unified solver design that works
transparently with OpenAI, Anthropic, and HF Inference Providers — the
HF path calls InferenceClient via run_in_executor and bypasses generate()
while still producing a structured EvalResult. Also adds model_base_url
parameter support to InspectAIHarness.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Simplifies the Inspect AI tutorial and notebook to support only OpenAI and
Anthropic via their APIs. The HF path (InferenceClient bypass) triggered
local model weight downloads when users misused the hf/ prefix, and
InferenceClient is not natively supported by Inspect AI's model routing.
Removing it eliminates the confusion and keeps the notebook straightforward.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…apacity-limited envs

The free HF Space echo_env only allows 1 concurrent WebSocket session.
Inspect AI's default concurrency tries all samples in parallel, causing
CAPACITY_REACHED errors for samples 2-5. Adding max_connections=1 to
eval_parameters serializes processing. Also adds max_connections to the
InspectAIHarness forwarded parameter list.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
max_connections limits model API concurrency, not env WebSocket concurrency.
Inspect AI still dispatches all samples concurrently, causing all 5 to attempt
simultaneous WebSocket connections against the single-session HF Space.
A module-level Semaphore(1) in the solver ensures env connections are opened
one at a time, regardless of Inspect AI's internal scheduling.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
EvalConfig stores the Task object in eval_parameters for harness routing,
but Task is not JSON-serializable. Use a fallback encoder that str()-ifies
any non-serializable type instead of crashing.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
….5B)

Shows how to evaluate a local HuggingFace model via Inspect AI's hf/ prefix,
covering both Hub IDs and local checkpoint paths from TRL training.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…grade for hf/ backend

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…rmers line

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…_CONCURRENT_ENVS

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…ebsite

- Use ECHO_ENV_URL variable in EvalConfig (notebook and .md now identical)
- Add temperature comment noting it should be omitted for hf/ backend
- Fix Next Steps links in notebook and .md to point to meta-pytorch.org/OpenEnv
  instead of raw GitHub .md file URLs

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Apr 30, 2026
@greptile-apps

greptile-apps Bot commented Apr 30, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR adds a new Inspect AI evaluation tutorial (evaluation-inspect.md) and matching Colab notebook (evaluation_inspect.ipynb), and extends InspectAIHarness with two transparent pass-through parameters (model_base_url, max_connections) forwarded directly to inspect_ai.eval(). The changes are additive, align with all stated invariants (rewards stay inside the environment, agents cannot call reset, MCP is used for tool interaction), and no RFC is required.

Confidence Score: 4/5

Safe to merge; only a P2 style concern in the notebook's API-key cell.

All code changes are correct and minimal. The single P2 finding (hardcoded API key placeholder pattern in the notebook) is a best-practice concern, not a functional defect. P2s alone cap at 4/5.

examples/evaluation_inspect.ipynb — API key cell pattern.

Important Files Changed

Filename Overview
src/openenv/core/evals/inspect_harness.py Adds model_base_url and max_connections pass-through to inspect_ai.eval() — minimal, correct, well-documented change with no logic issues.
docs/source/tutorials/evaluation-inspect.md New tutorial covering InspectAIHarness usage; content is accurate, aligns with principles, and follows existing tutorial structure.
examples/evaluation_inspect.ipynb Companion Colab notebook; otherwise clean but the API-key cell pattern encourages hardcoding secrets in notebook cells (P2).
docs/source/tutorials/index.md Adds the new tutorial entry to the toctree — trivial, correct change.

Sequence Diagram

sequenceDiagram
    participant User
    participant InspectAIHarness
    participant inspect_eval
    participant Solver
    participant MCPToolClient

    User->>InspectAIHarness: run_from_config(EvalConfig)
    InspectAIHarness->>inspect_eval: eval(task, model, max_connections, model_base_url, ...)
    loop For each Sample
        inspect_eval->>Solver: solve(state, generate)
        Solver->>Solver: generate(state)  [LLM call]
        Solver->>MCPToolClient: reset()
        Solver->>MCPToolClient: call_tool("echo_message", ...)
        MCPToolClient-->>Solver: echoed result
        Solver->>MCPToolClient: close()
        Solver-->>inspect_eval: updated TaskState
    end
    inspect_eval-->>InspectAIHarness: EvalLog[]
    InspectAIHarness->>InspectAIHarness: _extract_scores(logs[0])
    InspectAIHarness-->>User: EvalResult { scores: {accuracy: 1.0} }
Loading
Prompt To Fix All With AI
Fix the following 1 code review issue. Work through them one at a time, proposing concise fixes.

---

### Issue 1 of 1
examples/evaluation_inspect.ipynb:60
**Hardcoded API key placeholder encourages insecure notebook hygiene**

Setting the key as a string literal in a cell trains users to put their real secret at the same position — notebooks get accidentally committed or shared, leaking credentials. Using `getpass` prompts for the key at runtime and avoids storing it in the cell output or notebook JSON.

```suggestion
import getpass, os
os.environ.setdefault("OPENAI_API_KEY", getpass.getpass("OpenAI API key: "))
MODEL = "openai/gpt-4o-mini"
```

Reviews (1): Last reviewed commit: "docs(tutorials): sync notebook with .md ..." | Re-trigger Greptile

Comment thread examples/evaluation_inspect.ipynb
sergiopaniego and others added 3 commits April 30, 2026 19:45
…laceholder

Replaces `os.environ["KEY"] = "sk-..."` with `os.environ.setdefault(KEY, getpass.getpass(...))`.
Keys are prompted at runtime and never stored in cell output or notebook JSON.
`setdefault` makes the prompt a no-op when the var is already in the environment.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…utorial

Adds a tip block encouraging users to run eval before training to establish
a baseline. Updates model references from gpt-4o-mini to gpt-5-mini. Adds
end-to-end walkthrough and SFT warm-up tutorial links to the Next steps section.
Removes the time/difficulty/gpu metadata note from the header.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

@burtenshaw burtenshaw left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Approved per maintainer merge request after required checks passed.

@burtenshaw burtenshaw left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Approved per maintainer merge request after required checks passed.

@burtenshaw
burtenshaw merged commit 3e4d813 into huggingface:main May 5, 2026
9 checks passed
@sergiopaniego
sergiopaniego deleted the feature/eval-inspect-tutorial branch May 6, 2026 07:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants