Compare two models from the CLI
This example builds a small dataset, grades it with an LLM judge and compares two models on one agent.
This example takes an empty workspace to graded results. You need the CLI set up as in the quickstart. You also need a key with both Read evals and Change evals (the quickstart key has only Read evals; create another as on API keys), and jq to read values out of each JSON response. Runs call models, which your organization pays for.
-
Set the workspace and agent
Copy the workspace ID as in the quickstart. For the agent,
context evals filter-optionslists the agents that have trace data, with their IDs.Code -
Create a dataset and add dataset tasks
Each dataset task is a prompt and, optionally, the answer you expect (
--golden). The CLI calls a dataset task an item. Run the second command once per dataset task; a few of them make the comparison mean something.Code -
Set the criteria
Save this as
criteria.json. It asks an LLM judge whether each answer matches the policy:CodeoutputTypeisbooleanfor pass or fail, orfloatfor a score from 0 to 1. Ininstructions,{{output}}is the agent’s answer and{{expected_output}}is the dataset task’s expected answer.weightsets how much this criterion counts toward the dataset task’s score, relative to the others.modelOverride: nulluses the benchmark’s judge model.context evals describe criteria-setprints the file’s full shape.Code -
Save the dataset
Tasks and criteria stay unsaved until you save them, and a run grades only the latest saved version. Save the version you reviewed:
Code -
Create the benchmark
List the models your agent can run, and pick two:
CodeSave the axis as
axes.json, with your agent ID and the two model IDs.testingnames what changes between cells,valueslists the models to compare, andheldfixes everything else:CodeA benchmark is the kind of evaluation that compares models on a dataset.
--judge-modelsets the model that gradesllm_judgecriteria; pick one withcontext evals models list --agent "$AGENT_ID" | jq -r '.judges.models[].id'. Without it, the deployment’s default small model grades. Create the benchmark and link the dataset:Code -
Run it and read the scores
Codewatchprints progress on standard error and the final status on standard output. It exits0when the run completed,3when someone stopped it and4when it failed. It exits2when the server refuses (an unknown run ID, say),130when you press Ctrl-C and1when the watch itself failed (the run may still be going). The last line prints each cell’s ID, model and average score.To see each task’s answer and verdicts for one cell, use
context evals benchmark run tasks "$RUN_ID" --cell <cell-id>with acellIdfrom that output.
In CI
Install the CLI in the job with the command from Settings > Terminal, set CONTEXT_APP_ORIGIN, CONTEXT_ORG_ID and CONTEXT_API_KEY (as a secret), plus WORKSPACE_ID and AGENT_ID, and run the same commands. Exit 0 from watch means only that the run completed, even if every task scored 0. To fail the job on low scores, check the scores:
Code