Continuous Agent Evals in CI/CD: Automated LLM-as-a-Judge Regression Gates with Deterministic Tool-Trajectory Assertions
Why "Vibe Checking" Prompts Breaks in Production
Every AI team has experienced this regression: you tweak a single paragraph in the system prompt to fix a formatting bug—and 3 days later you discover the agent stopped calling verify_permissions before issuing database updates.
Traditional unit tests (assert response == "Hello") fail on stochastic LLM outputs, while manual QA doesn't scale across 50 golden user scenarios per PR.
Two-Layer CI Eval Architecture
Production agent evals separate hard deterministic invariants (did it call the right tools in a safe order?) from soft semantic quality (was the final explanation accurate and grounded?):
text[Pull Request Opened (prompts/ or agent/ changed)] │ ▼ [Run 50 Golden Scenarios Against Mocked / Cassette Tools] │ ├──► Layer 1: Deterministic Trajectory Assertions (0ms, $0) │ • assert "verify_user" called BEFORE "issue_refund" │ • assert total_tool_calls <= 6 │ • assert no schema validation errors │ └──► Layer 2: Calibrated LLM-as-a-Judge (Binary Pass/Fail Rubric) • Check factual grounding strictly against retrieved tool outputs • Block PR merge if composite pass rate drops > 2% vs main!
Python pytest + Trajectory Eval Harness
Here is a clean, CI-ready evaluation pattern you can run in GitHub Actions on every prompt change:
pythonimport pytest def assert_trajectory_order(executed_tools: list[str], required_before: str, target: str): assert required_before in executed_tools, f"Missing prerequisite tool: {required_before}" assert target in executed_tools, f"Missing target tool: {target}" assert executed_tools.index(required_before) < executed_tools.index(target), ( f"Security invariant violated: {target} called before {required_before}" ) @pytest.mark.asyncio async def test_refund_agent_safety_and_accuracy(agent_runner, judge_client): trace = await agent_runner.run("Refund order #ORD-9921 for duplicate charge") # 1. Deterministic Trajectory Invariant (Catches silent tool-skipping regressions) tool_names = [step.tool_name for step in trace.tool_calls] assert_trajectory_order(tool_names, required_before="lookup_order", target="issue_refund") assert len(tool_names) <= 4, f"Agent looped excessively: {tool_names}" # 2. Binary LLM-as-a-Judge Grounding Check (Never use 1-5 Likert scales!) verdict = await judge_client.grade_binary( rubric="PASS only if the final answer cites exact order #ORD-9921 amount from lookup_order output without inventing policy rules.", tool_outputs=trace.tool_outputs, final_answer=trace.final_answer, ) assert verdict.passed, f"Judge failed output: {verdict.reason}"
Two Golden Rules for CI Evals
- Use Binary (
PASS/FAIL) Rubrics, Not 1–5 Scales: 1–5 ratings drift unpredictably (3.8vs4.1), whereas strict binary criteria produce >92% inter-judge consistency. - Gate on Trajectory First: 80% of agent failures happen in tool selection and ordering, which can be asserted deterministically in Python before spending a cent on an LLM judge.