The Agent Returned the Right Answer but Took the Wrong Path
Agent reliability depends on more than output quality. This article explores how offline evaluations reveal hidden execution issues before production.
Building agents teaches you a humbling lesson very quickly: a well-written prompt is not the same as a guaranteed workflow. In production, agents occasionally behave in ways that are technically reasonable, yet operationally unexpected. This article shares one such observation and why offline evaluations became critical for catching it.
The Assumption Most Agent Builders Make
When we design an agent workflow, we naturally think like software engineers. If we define a sequence such as:
1. Call Tool A
2. Validate the parameters
3. Call Tool B
we expect execution to follow that exact order every time. After all, that's how traditional software behaves. If the workflow is clearly defined, the system should execute it deterministically.
But agents are not workflow engines. And that distinction matters more than most teams realize.
The Behavior We Observed
Most executions followed the same sequence as mentioned above. However, a small percentage of executions behaved differently
1. Validation
2. Tool A
3. Tool B
The instructions remained unchanged.
The tools remained unchanged.
The input remained unchanged.
Yet so often, the agent reordered the workflow. The deviation wasn't catastrophic, but it was enough to raise an important question:
Why would an agent ignore a clearly defined sequence?
A Common Misconception About Agents
One of the biggest misconceptions in agent development is treating prompts as equivalent to program logic.
Traditional software executes instructions. LLMs interpret instructions. That difference is subtle but significant. An agent's behavior emerges from several competing influences:
- System instructions
- User instructions
- Available tools
- Context provided in the session
- Training data
- Learned reasoning patterns
As engineers, we often focus on the first three. The model, however, is also influenced by the latter three.
Why This Happens
One possible explanation is that validation and reasoning are deeply represented patterns in model training. Across countless examples, models learn behaviors such as:
1. Understand first
2. Validate
3. Act
As a result, when a workflow asks the model to perform an action before validation, there may occasionally be tension between "What the prompt says" and "What the model has learned to do."
Sometimes, the model's learned reasoning pattern leaks through. The result is not necessarily a "failure" in the traditional sense. It's a reminder that agents are probabilistic systems.
The Hidden Risk of Rare Failures
Interestingly, the biggest risk isn't complete failure. It's intermittent failure.
Consider two scenarios:
- Workflow fails 100% of the time. This problem is discovered immediately. Developers spot it within minutes.
- Workflow fails 5% of the time. The issue becomes harder to detect. Manual testing might never uncover it. The first indication may be too late, coming from production.
Many agent-related issues fall into this category:
- Tool ordering issues
- Incorrect tool selection
- Missing validation steps
- Hallucinated assumptions
- Unexpected reasoning paths
These problems are often rare enough to evade traditional testing practices.
Why Offline Evaluations Matter
Prompts define intent. Evaluations verify behavior. Without systematic evaluations, agent testing often becomes anecdotal: "I tested it 15 times, and it worked!"
The problem is that ten samples may not expose a behavior that occurs once every hundred executions. Offline evaluations provide a structured way to discover such patterns. A useful evaluation suite can measure:
- Instruction adherence
- Tool ordering
- Workflow completion
- Correctness
- Hallucination rates
- Safety compliance
- Latency
- Retry behavior
For example:
Test Case:
Expected:
Tool A → Validation → Tool B
Observed:
Validation → Tool A → Tool B
Result:
Fail
What appears to be a random anomaly often turns out to be a measurable behavioral tendency.
What We Learned
One mindset shift proved particularly valuable:
Stop Treating Prompts as Guarantees
Prompts are specifications. They are not enforcement mechanisms. As workflows become more critical, relying exclusively on prompt compliance becomes increasingly risky.
Start Treating Evaluations as First-Class Engineering Artifacts
Many teams invest heavily in prompt engineering while postponing evaluation design. In practice, both should evolve together.
The earlier evaluation datasets are introduced, the easier it becomes to identify behavioral drift and instruction-following issues.
Design Patterns That Reduce Workflow Deviations
Over time, we found several design approaches that improve reliability.
1. Move Critical Orchestration Outside the LLM
If execution order is non-negotiable, enforce it through application logic.
Instead of:
LLM decides the next step
prefer:
Application controls the workflow
LLM performs bounded tasks
2. Introduce Explicit Workflow State
Maintain state such as:
TOOL_A_COMPLETED
VALIDATION_COMPLETED
READY_FOR_TOOL_B
This reduces ambiguity and limits the agent's ability to skip ahead.
3. Gate Tool Availability
Only expose tools that are valid for the current stage. If Tool B should never execute before validation, don't make Tool B available until validation is complete.
4. Build Evaluation Suites Early
Evaluation datasets should be created alongside agent workflows, not after deployment. This practice helps uncover edge cases before users encounter them.
5. Design for Probability, Not Perfection
Perhaps the most important lesson:
Reliable agent systems assume occasional deviations and are engineered to handle them gracefully.
Systems designed around perfect compliance tend to be fragile. Systems designed around probable compliance tend to be resilient.
Final Thoughts
One of the most surprising discoveries in agent development is that a correct prompt does not necessarily produce a perfectly consistent workflow.
Agents are capable, adaptable, and increasingly powerful. But they are not deterministic workflow engines. The observation that inspired this article was simple: an agent occasionally performed validation before executing a tool call despite being explicitly instructed not to.
The lesson, however, was much larger.
As we investigated further through offline evaluations, we realized that output correctness alone was not enough. The agent could arrive at the right answer while still deviating from the expected execution path, calling tools in an unexpected sequence, or violating workflow assumptions that were invisible to the end user.
Those behaviors would have been easy to miss through manual testing alone. By monitoring tool invocations, execution order, tool call counts, and workflow compliance, offline evaluations helped surface issues that would otherwise have remained hidden until production.
As teams move from experimenting with agents to deploying them in production, success will depend less on writing better prompts and more on building robust evaluation frameworks, orchestration mechanisms, and safeguards around inherently probabilistic systems.
Because in the world of agents, the real challenge isn't getting the workflow right once. It's getting it right consistently, predictably, and observably. And that starts with measuring not just what the agent produces, but how it gets there.
Opinions expressed by DZone contributors are their own.