Examples and guides for using the OpenAI API
Harness-aware eval example
Companion to the Harness-aware evaluation of plugins cookbook. Refer to the cookbook for the purpose and tradeoffs of each evaluation approach. This README walks through the steps required to run the example.
From the repository root, change to this example directory before running the commands below:
cd examples/partners/harness_aware_plugin_evals
The notebook harness_aware_plugin_evals.ipynb runs the article top to bottom without an API key.
Open it with uv run jupyter lab harness_aware_plugin_evals.ipynb. It syncs its own dependencies
from uv.lock, runs the direct tool tests live, and replays the recorded runs under data/ through the same
graders. Setting RUN_LIVE=1 in .env runs the standalone loop and Codex with paid API
calls. The Codex result with server instructions remains recorded unless you reproduce the steps in
"Fixing it" below. Only the live standalone loop and Codex runs require an API key.
Every install, config, and run step is a Make target. See the Makefile for the actual commands.
Prerequisites
- uv.
- Python 3.11+ (
uv python install 3.11). - Node.js and npm: Node.js 20.20.x or later in the 20.x line, or 22.22.0 or later, as required by the locked promptfoo version. npm ships with Node.js.
- An OpenAI API key for the standalone loop and Codex
- The standalone loop and Codex can incur additional cost. With the default settings in this example it is roughly $0.01 per run
Setup
make setup
That installs Python and Node dependencies, creates .env from .env.example
if needed, writes absolute CODEX_HOME and PROMPTFOO_PYTHON into .env, and
generates Codex config.toml with the local marketplace path.
Then set OPENAI_API_KEY in .env. The standalone loop and Codex use it.
PROMPTFOO_PYTHON must point at this project's virtualenv. Promptfoo runs the
Python provider and assertions in its own worker; if it picks another
interpreter, the run hangs on a missing import instead of failing cleanly.
Direct tool tests
Direct resolve calls on the structured indicator field.
No model, no API key, no MCP server. The script exits non-zero if any case fails.
make level-1
MCP server for the standalone loop and Codex
Those approaches call the fixture server over HTTP on 127.0.0.1:8000. It answers from a handful of
hardcoded series, so it runs offline and needs no BLS API key. Start it in a separate terminal
from this directory and leave it running:
make server
You can stop it with Ctrl-C when the evals are done.
Standalone function-calling loop
A model drives the MCP tools in a small function-calling loop through promptfoo. Requires the server from the other terminal.
make level-2
Results go to outputs/l2-results.json. Open traces with npx promptfoo view.
Product harness (Codex)
The same queries through the Codex SDK provider, with the example plugin installed
into the local CODEX_HOME. Requires the server from the other terminal.
Installs the plugin, then runs promptfoo.
make level-3
Results go to outputs/l3-results.json. Open traces with npx promptfoo view.
In the saved evaluation results supplied with this example, consumer-price-index and employment-ambiguous pass in the standalone loop and fail under Codex. The standalone loop instructs the model not
to invent series IDs and to ask when candidates tie. Nothing tells Codex the same, so it supplies a
CPI series ID from its own knowledge. For the employment case, Codex may narrow the request before
calling resolve, choose one of the tied candidates afterward, or fetch both. The exact path varies
between runs, but each retrieves at least one series instead of stopping to clarify, so the grader
fails it.
The recorded run under data/l3-trace-before.json scores three out of five. Both cases depend on
the path the model takes, so a fresh run can land on a different count.
Fixing it
The MCP server can publish this guidance in its instructions field. Define the text in
server.py and pass it to the server:
GUIDANCE = """Answer only from this catalog. Call resolve first, passing the indicator the user
asked about without narrowing it. Pass fetch_bls_data only the series IDs that resolve returned,
never one from your own knowledge. If resolve returns no candidate, say the data is unavailable. If
several candidates tie for the best confidence, do not call fetch_bls_data at all. Name them and ask
which one the user wants."""
mcp = FastMCP("BLS evaluation fixture", instructions=GUIDANCE)
Servers send instructions in the initialize response. Codex reads that field and passes it to
the model, so the guidance reaches Codex without any change to the tools or the resolver.
Restart the server and run make level-3 again. In the included recorded run (data/l3-trace-after.json), all five cases pass.
The same behavior change can be observed in the ChatGPT desktop app.
The standalone loop ignores that field and uses its own system prompt. The same text is on the same server for both approaches, and only the harness that reads it is affected.
CODEX_HOME must be the local one, generated at setup. Otherwise Codex
starts with the user default home, the plugin is missing, and the model cannot
call resolve or fetch_bls_data.
Helpers
make help # target list
make test # grader and standalone loop provider unit tests
make replay # regrade the recorded runs under data/
Environment
| Variable | Role |
|---|---|
OPENAI_API_KEY |
Required for the standalone loop and Codex |
MCP_URL |
MCP endpoint for the standalone loop. The server reads it from its process environment |
EVAL_MODEL |
Model id for promptfoo |
EVAL_REASONING_EFFORT |
Reasoning effort passed to the provider |
PROMPTFOO_PYTHON |
Interpreter for promptfoo's Python workers |
CODEX_HOME |
Isolated Codex home with the plugin installed |
The standalone loop reads MCP_URL from .env. The make server target does not load .env, so when
changing the endpoint, also pass it to the server, for example:
MCP_URL=http://127.0.0.1:8001/mcp make server
Codex reads the URL from the plugin's own .mcp.json. Update that URL too so the standalone loop and Codex
connect to the same server.
Layout
| Path | Role |
|---|---|
server.py |
Fixture MCP server (resolve, fetch_bls_data) |
level_one.py |
Direct tool tests runner |
provider.py |
Standalone function-calling loop |
promptfooconfig.yaml |
Shared corpus and standalone loop wiring |
promptfooconfig.codex.yaml |
Codex provider for the product harness |
eval_grading.py |
Shared grader for the standalone loop and Codex |
data/ |
Recorded promptfoo runs behind the article's numbers |
replay.py |
Regrades the recorded runs |
notebook_setup.py |
Environment and server setup for the notebook |
harness_aware_plugin_evals.ipynb |
The article, executed offline |
tests/ |
Unit tests for the grader and the standalone loop provider |
.codex-home/ |
Isolated Codex home and plugin marketplace |