agent/eval.py file. It holds one EvalRunner subclass from lmnr.evals, in Laminar’s Python SDK. The runner’s attributes declare the image, the services, and the secrets. Its methods set up each case, run your app, and grade the result. Your app can be in any language. Only the runner is Python.
This page covers the runner’s attributes, its methods, and the ctx object the methods receive. For the files around eval.py, see What you write and what lmnr-cli writes.
Here is an example runner for a made-up Python support app. The app has a Postgres database, a seed script, and an HTTP server. Your image, services, commands, and checks will be your app’s own. The snippets on this page show the API, not a required setup.
Example: evals/support/agent/eval.py
eval.py is imported more than once: first to read its configuration, then again to run it. So keep module-level code to constants and definitions.
Attributes
Methods
Each trial calls these methods in order. Each method gets actx for that trial:
setup(ctx)runs after the services have started and loaded the case’s seed. Use it to start the app, and to seed data that a service seed can’t express. By default, it runs the case’s ownenvironment/seed.pyorseed.sh, if the case has one.run(ctx)calls your app’s entry point and records the outcome withctx.set_result(...).collect(ctx)is optional. It runs afterrun(), even whenrun()raised or timed out. Use it to save state for grading or to export a trajectory.verify(ctx)grades the result and returns the rewards.
ctx.container reaches into the trial’s container (see Where the code runs):
Run commands in the container
ctx.container.sh(cmd, env=None, cwd=None, user="agent", timeout=None, check=True)runs abashcommand and returns itsstdout,stderr, andreturn_code. On a non-zero exit, it raisesCommandError, unlesscheck=False. When a command runs past itstimeout, it is killed with its children. ThenshraisesCommandTimeout, aTimeoutErrorthat carries the output so far.user="agent"is the case’s agent user, and"root"is root.ctx.container.run_file(path, *args)uploads a script from the host to a new temporary folder, runs it, and deletes it. This way, harness scripts don’t stay where the agent could find them. A script with a shebang runs directly. A.pyfile runs withpython3, and anything else withbash.ctx.container.spawn(name, cmd, ready=..., env=None, timeout=60, user="agent")starts a long-running process, typically the app’s server, and waits untilreadypasses. Its output goes to/logs/agent/<name>.log.cmdmust stay in the foreground, for examplepostgres -D ...instead ofpg_ctl start. A process that exits counts as crashed, and the error shows the end of its log. Readiness checks areport(8080),http(url), andcmd("pg_isready")fromlmnr.evals, or a plain shell command.ctx.container.wait_for(ready, timeout=60)waits for a readiness check without starting anything. For example, it can wait until an async job writes its final status. It raisesTimeoutErrorwhen the check doesn’t pass in time.ctx.container.copy(host, path)copies a host file or folder into the container.write_file(path, content),read_text(path), andread_json(path)write and read container files.
run_file or copy is relative to the file whose code calls it. So ctx.container.run_file("seed.py") in eval.py runs the seed.py next to eval.py. Keep these files inside the evals/ folder, because a --remote run has only that folder on its host (see Where the code runs).
Read the case and record the outcome
ctx.caseis the current case. It has:name: its[task] name;dir: its folder;metadata:[metadata]in itstask.toml;instruction: itsinstruction.md;file(path): a file underenvironment/;expected():tests/expected.json;fixture_text(path),fixture_json(path),fixture_bytes(path), andfixture_path(path): files undertests/fixtures/.
ctx.set_result(**fields)records fields in the trial’sresult.json, merged with earlier calls.ctx.result()reads them back, also inverify(). When the trial has no trajectory, Laminar shows these fields as the trial’s output.ctx.modelis the model for this run.ctx.envis the resolved env, including the variables that services and mocks set.ctx.loggeris a logger. Its lines inverify()go to the trial’s verifier log.self.service(Postgres)orself.service("postgres")returns a declared service, so you can use its helpers.
- An exception fails the trial. Harbor records it in
exception.txt, and the trial gets no score. Call your app withcheck=False, and record its failures as outcomes, such asctx.set_result(outcome="failed", ...)or"timeout". Thenverify()grades them as wrong answers. Let only harness errors raise, such as a service that won’t start. - Keep command timeouts below the case’s
[agent] timeout_sec. That timeout limits the total time of the services’ start, the seeds,setup,run, andcollect.
ctx.model to your app instead of hard-coding a model, so --model and model sweeps work.
Grade the result
verify(ctx) returns the rewards: a number, a bool (True counts as 1), or a dict of them, such as {"refund": True, "reply": 0.5}. Each key becomes a score in Laminar. The same method grades all cases, using each case’s data.
verify() reads the reference answer with ctx.case.expected(). It reads the state the run left through ctx.container and the services’ helpers. For example, this checks the credits in the database and a report file the app wrote:
Example
LLM judges
A judge is your own function.verify() runs on the host, so it can call any SDK listed in evals/pyproject.toml. Decorate the judge with @observe to give it its own span in the trial’s trace. Leave the API key out of the recorded inputs. This judge is from the quickstart’s example:
Example: evals/billing/agent/eval.py
verify() with the key from ctx.secrets. In Laminar, verify() is traced under the trial’s verifier span, and the judge’s LLM calls show up as LLM spans. The ctx.logger lines from verify() become the trial’s verifier/test-stdout.txt.
Artifacts
Artifacts are container files that are collected for grading after the run. Declare them on the runner, or save them fromcollect(). For example:
Example
verify(), read them on the host with ctx.artifacts.read_text(path), read_json(path), and path(path). Pass the container path the file came from. ctx.artifacts.list() lists them. ctx.artifacts.save replaces anything the agent may have put at the same path.
Grade in a separate container
By default,verify() runs while the trial’s container is still up. The services are still running, and everything the run left behind is still there. You can instead grade from a fresh container that sees only what you collected. To do that, set environment_mode = "separate" under [verifier] in each case’s task.toml. For new cases, also add {"verifier": {"environment_mode": "separate"}} to the runner’s new_task_toml. In the fresh container:
- No services run. To save a service’s state after the run, give it
snapshot=["table", ...], orsnapshot=Truefor a simulator. Read the state withctx.state("postgres", "credits"). ctx.result(),ctx.artifacts, andctx.mocksstill work. Declared artifacts are also copied into the grading container at their original paths.
Grade with per-case scripts
Datasets imported from Harbor have atests/test.sh in each case. To grade with those scripts, set grade_with_test_sh = True and don’t define verify(). Each script runs in the container. It writes its reward to /logs/verifier/reward.txt, or several named rewards to /logs/verifier/reward.json. For such a dataset, lmnr-cli doesn’t write stub test.sh files.
Secrets and env vars
Declare secrets by name and keep their values out of the code, for example:env = {"ANTHROPIC_API_KEY": secret("ANTHROPIC_API_KEY")}passes a secret to all commands in the container.secret()also declares it.secrets = ["JUDGE_API_KEY"]declares a secret that must not reach the container.verify()reads it asctx.secrets["JUDGE_API_KEY"].verify()can read any declared secret this way.
lmnr-cli eval run reads each secret from your shell, then from .env.local and .env in the current directory. If one is missing, it stops before anything starts, with exit code 19. With --remote, the values travel with the run as env vars. .env* files are not uploaded. Commit a .env.example that lists the names. Add .env and evals/*/jobs/ to .gitignore.
Per-command variables go in ctx.container.sh(..., env={...}). In setup, run, and collect, they can’t override a key that the runner’s env sets.
Python packages
eval.py and verify() run on the host, so the packages they import, such as an LLM judge’s SDK, go in evals/pyproject.toml under [project] dependencies:
Example: evals/pyproject.toml
lmnr-cli installs them next to the runner, on Python 3.13. To add packages for one dataset only, put a PEP 723 block at the top of its eval.py. Packages that the app or a container script needs belong in the image.
Shared runners
Several datasets can test the same app with the same harness. Then put the runner in a folder inevals/ that isn’t a dataset, by convention evals/_shared/. Each dataset’s eval.py subclasses it. For example:
Example: evals/_shared/support.py
Example: evals/refunds/agent/eval.py
- The
evals/folder is on the import path.--remoteuploads the shared folder with the run. - Relative paths are relative to the file that declares them. So the shared runner’s paths and scripts work from any dataset.
- Datasets whose images come out the same share one build.
lmnr-cli eval describe <dataset>shows the runner’s class chain. For each image step and service, it shows the file and line that declared it.
Next steps
Build the image
Bases, dependencies, and source, or an existing Dockerfile.
Services
Postgres, ClickHouse, Valkey, custom services, and simulated SaaS APIs.
Mocks
Answer for an internal service or an observed function.
Capture the trajectory
Get the app’s LLM and tool calls into each trial’s trace.