Sitemap
Ndeto Martin

Ndeto Martin

Always Building

Consistent Agents: Evaluating Agent Behavior

4 min readNov 3, 2026

--

Press enter or click to view image in full size

In traditional software, the same input produces the same output. This is deterministic. Large language models are not: even with low randomness, their answers can vary. So how do we assess a non-deterministic agent’s correctness?

Guardrails set the boundaries. Agent evaluations are structured tests that measure whether an agent stays within those bounds over time, from one small decision to a full run. Across representative cases, they show whether the agent is functioning as intended. Here’s an example.

Refund agent evaluators

Start by recording desired behaviour in a dataset of examples, conditions, and expected outcomes. For example:

1. Eligible refund

  • Input: Order placed 10 days ago.
  • Condition: Refunds are allowed within 30 days.
  • Expected outcome: eligible: true

2. Ineligible refund

  • Input: Order placed 45 days ago.
  • Condition: Refunds are allowed within 30 days.
  • Expected outcome: eligible: false

3. Refund status

  • Input: “i sent it back 3 wks ago, where’s my money?” The return arrived 15 business days ago, and the refund has not been issued.
  • Condition: The policy requires escalation after 10 business days.
  • Expected outcome: Recognize a refund status request and escalate. Don’t claim the refund is on its way.

An evaluation experiment runs a task on each dataset example and scores its output. Three evaluation methods are covered:

  • Code evaluators check clear, repeatable rules, such as pattern matches and other deterministic conditions.
  • LLM judges assess meaning, such as whether the agent understood a message with a typo.
  • Pairwise evaluation compares responses from two versions of the same agent, such as the current and updated prompt, on the same inputs. A judge selects which response better meets the chosen criteria.

Code evaluators

A code evaluator is a function that scores an output against an expected result. It works well for deterministic checks, such as matching required patterns, validating required fields, or confirming that an output matches one of a set of allowed options.

Get Ndeto Martin’s stories in your inbox

Join Medium for free to get updates from this writer.

For example, the dataset can define the expected refund decision:

{"input": {"days_since_purchase": 10}, "expected_output": {"eligible": true}}
{"input": {"days_since_purchase": 45}, "expected_output": {"eligible": false}}

For each example, the task runs the agent on that input. Here, eligibility_check is the evaluator. It compares the agent’s result with the example’s expected result.

from langfuse import Evaluation, get_client

langfuse = get_client()

data = [
{
"input": {"days_since_purchase": 10},
"expected_output": {"eligible": True},
},
{
"input": {"days_since_purchase": 45},
"expected_output": {"eligible": False},
},
]

def task(*, item, **kwargs):
"""Run the agent's refund eligibility check for one example."""
days = item["input"]["days_since_purchase"]
return refund_agent.check_eligibility(days_since_purchase=days)

def eligibility_check(*, output, expected_output, **kwargs):
"""Score whether the agent's decision matches the expected result."""
correct = output["eligible"] == expected_output["eligible"]
return Evaluation(name="eligibility_correct", value=float(correct))

result = langfuse.run_experiment(
name="refund-eligibility",
data=data,
task=task,
evaluators=[eligibility_check],
)

print(result.format())
langfuse.flush()

Suppose the agent approves both orders:

  • 10 days: Expected eligible, agent returns eligible. Score: 1.
  • 45 days: Expected ineligible, agent returns eligible. Score: 0.

A score of 0 flags the case for inspection.

LLM-as-a-Judge

Some checks depend on meaning rather than an exact value. For example, can the agent identify that “i sent it back 3 wks ago, where’s my money?” is a refund status question, even with informal wording?

The judge receives the customer’s message, the available intent options, and the agent’s selected intent. It answers one focused question: Is this the best intent from the available options?

from langfuse import Evaluation
from langfuse.openai import OpenAI

judge = OpenAI()
def intent_judge(*, input, output, **kwargs):
"""Score whether the selected intent fits the customer's message."""
result = judge.chat.completions.create(
model="gpt-4.1-mini",
messages=[
{
"role": "system",
"content": (
"Check only whether the selected intent is the best fit "
"for the customer's message, choosing from the options. "
"Allow for typos and informal wording. Reply PASS or FAIL only."
),
},
{
"role": "user",
"content": (
f"Customer message: {input['message']}\n"
f"Intent options: {input['intent_options']}\n"
f"Selected intent: {output['intent']}"
),
},
],
)
passed = result.choices[0].message.content.strip().upper() == "PASS"
return Evaluation(name="intent_correct", value=float(passed))

Example result

  • Customer message: “i sent it back 3 wks ago, where’s my money?”
  • Intent options: refund_status, start_return, cancel_order
  • Agent selected: refund_status
  • Judge verdict: PASS
  • Langfuse score: intent_correct = 1.0

If the agent selected cancel_order, the judge could return FAIL, scoring intent_correct = 0.0.

A separate judge can check whether the agent followed the refund policy, such as escalating an overdue refund. Keeping each judge focused makes scores easier to interpret. (Langfuse: LLM-as-a-Judge docs)

Pairwise evaluation

Pairwise evaluation compares two versions of the same agent. For example, the current refund agent prompt and an updated prompt answer the same customer messages.

For each message, a judge compares the responses and selects A, B, or tie based on one criterion: Which is more concise while still giving the correct refund status and next step?

Across the dataset, results show which prompt is more often preferred for conciseness while preserving key information. This helps compare configurations, but does not establish whether either prompt is correct or policy-compliant. To check whether responses stay within that threshold, score each one against a policy or expected outcome.

Correctness Without Determinism

Evaluations don’t make agent behavior deterministic. They provide a repeatable way to check correctness across known cases. Code evaluators check clear rules, LLM judges assess meaning, and pairwise comparisons show which configuration better meets a chosen criterion. Add real failures to the dataset so future changes are tested against them.

--

--