Why agents are harder to test
A conventional program returns the same output for the same input, and a unit test can check it exactly. An agent built on a language model breaks most of those assumptions:
- Non-deterministic output. The same request can produce different wording, different tool calls, or a different order of steps.
- Many steps. A task may involve reading, searching, calling several tools and writing a result. An early mistake can be hidden by a plausible final answer.
- Side effects. Agents send emails, update records and book appointments. A wrong action is worse than a wrong sentence.
- Open-ended answers. Many outputs have no single correct string, so exact-match tests do not apply.
- Changing foundations. A new model version or a small prompt edit can change behaviour across the board.
Test in layers
No single test catches everything. We use six layers, from the cheapest and most precise to the broadest.
| Layer | What it checks | Typical grader |
|---|---|---|
| 1 · Tools | Each tool the agent can call behaves correctly on its own: inputs, outputs, errors, permissions. | Unit tests |
| 2 · Steps | Individual decisions: classifying a request, retrieving the right documents, extracting the right fields. | Code checks, labelled data |
| 3 · Trajectory | The path: did the agent call the right tools, with the right arguments, in a sensible order, without unnecessary actions? | Code checks on traces |
| 4 · Task | End to end in a sandbox: is the final state correct (record updated, appointment booked, answer right)? | State checks, model judge |
| 5 · Adversarial | Prompt injection, malicious documents, out-of-scope requests, attempts to reach data the user should not see. | Red-team cases |
| 6 · Production | Live behaviour: failures, escalations, user corrections, drift after model updates. | Monitoring, human review |
Layers 3 and 4 are where agent testing differs most from ordinary software testing. Checking the final answer alone misses agents that reach the right result by a risky route, such as editing a record they should only have read.
Simulate the user and the world
Many agent tasks are conversations. A useful pattern, used in the τ-bench benchmark (Yao et al., 2024), is to run the agent against a simulated user played by another model with a hidden goal, inside a sandboxed environment with fake databases and tools. At the end, the test compares the final state of the environment with the expected state.
This tests what matters, the outcome, without depending on exact wording. It also lets you replay the same scenario many times, which is how reliability problems show up.
Public benchmarks such as AgentBench (Liu et al., 2023) and SWE-bench (Jimenez et al., 2023) follow the same principle of judging agents on completed tasks. They are useful for comparing models, but they do not replace tests built from your own workflows.
Choosing graders
Code checks
Whenever the answer can be checked by code, check it by code: a field value, a database state, a tool argument, a JSON schema, a forbidden action that must not appear in the trace. These checks are fast, cheap and repeatable.
Model-based judges
For open-ended outputs, a language model can grade against a rubric. Zheng et al. (2023) found that strong models used as judges can agree with human preferences at a level close to human-to-human agreement, but also documented biases, for example towards longer answers and towards the answer shown first. Keep rubrics specific, ask for a judgement on one criterion at a time, and check the judge against human labels before trusting it.
Human review
People are the reference. Use them to label a calibration set, review disagreements between graders, and look at samples of production traffic. Their time is the scarcest resource, so spend it where automated graders are least reliable.
Measure reliability, not luck
Because outputs vary, a single passing run proves little. Run each test case several times and report how consistently it passes. τ-bench introduced a pass^k measure for exactly this: the chance that an agent succeeds on all k attempts at the same task. Agents that look good on one attempt often drop sharply as k grows. For anything that acts on a customer's behalf, consistency matters more than the best run.
Building the evaluation set
- Start from real requests. Historical tickets, emails or call transcripts, cleaned of personal data, reflect what the agent will really face.
- Add the edge cases people already know about. The team that does the work today can list the awkward cases in an afternoon.
- Turn every failure into a test. When the agent gets something wrong in testing or production, the case goes into the set so it cannot quietly come back.
- Version the set alongside prompts and code, so results are comparable over time.
- Agree release thresholds with the business before launch: which cases must always pass, and what pass rate is acceptable for the rest.
- Run it automatically on every change to prompts, models, tools or retrieval, the same way a software team runs its test suite.
Security belongs in the test suite
Agents read untrusted content: emails, web pages, uploaded files. Greshake et al. (2023) showed that instructions hidden in such content can take over an LLM-integrated application, an attack known as indirect prompt injection. Test it directly. Include documents with hidden instructions, requests to reveal other users' data, and attempts to trigger actions outside the agent's role, and check that the agent's tool permissions limit the damage when the model is fooled.
How Quest approaches it
Testing is where our lab started. Our published research covers search-based and model-based test generation, including automated exploration of web applications and test data generation for complex constraints. We bring the same discipline to agents: layered tests, an evaluation set built from the client's real work, repeated runs, and release gates agreed before launch.
Open source: LLM-Judge
We built LLM-Judge for our own projects to catch a problem we kept seeing: answer quality quietly getting worse as an application evolves, especially when it moves from one model provider to another. We have released its core version as open source under the MIT licence.
It has two parts. The judge server runs a locally hosted open model through Ollama and does the evaluation: it stores a baseline set of questions and answers, then compares each new set against it. Because the judge runs locally, test data does not have to leave your own infrastructure. The client library, published as the Python package quest-llm-judge, connects your application to the server by adding an endpoint the judge can query. Together they turn "did this change make our answers worse?" into a check you can run on every release.
Frequently asked questions
Can we test an agent with ordinary unit tests?
Partly. Tools and deterministic steps should have ordinary unit tests. The agent's decisions and final outcomes need evaluation methods that tolerate varied wording and check results instead of exact strings.
How many test cases do we need?
Enough to cover every request type and known edge case, with each case run several times. Start small with real cases and grow the set from every failure you find.
Is using a model to grade another model reliable?
It can be, for well-defined rubrics, but judges have known biases. Calibrate them against human labels and prefer code checks wherever the answer can be verified directly.
Do we need to re-test when the model provider releases a new version?
Yes. Model updates can change behaviour in ways prompts do not control. Run the full evaluation set before switching versions, and before switching providers. Comparing new answers against a stored baseline, as LLM-Judge does, makes regressions visible.
References
- Yao, S. et al. (2024). τ-bench: a benchmark for tool-agent-user interaction in real-world domains. arXiv:2406.12045.
- Zheng, L. et al. (2023). Judging LLM-as-a-judge with MT-Bench and Chatbot Arena. NeurIPS 2023. arXiv:2306.05685.
- Liu, X. et al. (2023). AgentBench: evaluating LLMs as agents. arXiv:2308.03688.
- Jimenez, C. E. et al. (2023). SWE-bench: can language models resolve real-world GitHub issues? arXiv:2310.06770.
- Quest (2025). LLM-Judge and quest-llm-judge. Open source, MIT licence. github.com/QuestPK/LLM-Judge.
- Greshake, K. et al. (2023). Not what you've signed up for: compromising real-world LLM-integrated applications with indirect prompt injection. arXiv:2302.12173.
info@questlab.pk →