You tuned the prompt. You ran the benchmarks. The single-turn outputs look great. Then you deploy your LLM agent and it spirals. It hallucinates API calls. It loops on the same failed action three times. It calls tools that don't exist. The prompt was optimized. So why does the agent still break?

Because most prompt optimization methods were never designed for agents. They were designed for chat.

A new paper under review at ICLR 2026 proposes a different approach. It's called TrajTune, and it tackles a problem that the prompt optimization community has largely ignored: how do you optimize prompts for systems where quality depends on a sequence of decisions, not a single output?

The Problem With Optimizing Prompts One Turn at a Time

Prompt optimization is a hot field. Google DeepMind's OPRO showed that LLMs can optimize their own prompts by treating prompt selection as an optimization problem. DSPy built an entire framework around treating prompts as learnable parameters, running multi-stage programs where each module gets tuned independently. PromptAgent used strategic planning with Monte Carlo tree search to explore better prompts.

These approaches share a common assumption. They evaluate prompt quality based on the text the model generates in response to a single input. Did the model produce the right answer? Did it follow the format? Does the output score well on your metric?

That assumption works fine for question answering, summarization, classification, and other single-turn tasks. It breaks down for agents.

An LLM agent doesn't produce one output. It produces a trajectory: a sequence of thoughts, tool calls, observations, and decisions that unfold over multiple steps. The quality of that trajectory depends on interactions between steps. A bad prompt doesn't just produce a bad answer. It produces a bad plan. The agent picks the wrong tool on step two. It feeds garbage into step three. By step five, the whole thing has collapsed. But the final output might look perfectly reasonable if you only judge the last turn.

Current prompt optimization methods can't see this. They look at outputs. They don't look at paths.

What TrajTune Does Differently

TrajTune, from Bing Zhang, Shubhi Asthana, Hima Patel, and Chad DeLuca, is the first prompt optimization framework built specifically for agentic workflows. The core insight is simple: if agents fail in trajectory-specific ways, you need trajectory-specific feedback to fix the prompts that cause those failures.

The framework has three components that work together.

Structured execution traces. When an agent runs a task, TrajTune doesn't just record whether it succeeded or failed. It captures the full execution trajectory. Every tool call, every observation, every decision point. This gives you a detailed map of where the agent went wrong, not just that it went wrong.

Fine-grained error metrics. From those traces, TrajTune computes specific error categories. Hallucinated tool calls. Repetitive actions that loop without progress. Failed API interactions. These aren't binary pass/fail scores. They're nuanced signals that tell you what kind of failure occurred and where in the trajectory it started.

Adaptive thresholds and multi-LLM feedback loops. This is where it gets interesting. TrajTune doesn't just flag errors. It compares error metrics against adaptive thresholds. When the error rate for a specific failure type crosses its threshold, the system triggers a feedback loop where multiple LLMs analyze the trajectory and collaboratively refine the prompt. The refinement isn't generic. It targets the specific failure pattern that triggered the loop.

Think of it this way. Traditional prompt optimization is like a driving instructor who only sees whether you arrived at the destination. TrajTune is like an instructor who watches your entire route, notices you always drift left on highway on-ramps, and gives you specific coaching for that exact problem.

Why Adaptive Thresholds Matter

You could just set a fixed threshold and trigger refinements whenever errors exceed it. But TrajTune uses adaptive thresholds, and that's a meaningful design choice.

Different agent tasks have different baseline error rates. A finance agent pulling data from volatile APIs will naturally have more failed calls than a code agent working with stable development tools. A fixed threshold that triggers refinements too often wastes compute on unnecessary prompt changes. One that's too high lets persistent errors slide.

Adaptive thresholds adjust to the baseline error profile of each task domain. The system learns what "normal" looks like for a given agent type and only triggers refinements when performance degrades from that baseline. This keeps the feedback loop focused on genuine regressions rather than expected noise.

It also means TrajTune scales across domains without manual threshold tuning for each new agent type.

The Multi-LLM Feedback Loop

The refinement mechanism itself is worth examining. TrajTune uses multiple LLMs in its feedback loop, not just one. Why?

Single-model prompt refinement has a known weakness. The model that generated the error tends to generate the same error when asked to fix its own prompt. It's operating within the same reasoning patterns that produced the problem in the first place.

By using multiple LLMs in the feedback loop, TrajTune introduces diverse perspectives on what went wrong and how to fix it. One model analyzes the trajectory. Another proposes prompt modifications. A third validates that the modifications actually address the failure mode. This ensemble approach produces more robust prompt refinements than any single model could generate alone.

The loop is iterative. A refined prompt runs through the agent again. The new trajectory gets evaluated. If error metrics still exceed thresholds, another round of feedback fires. This continues until the trajectory meets quality standards or a budget limit is reached.

The Numbers

The paper reports results across three agent domains: finance, software engineering, and IT operations. The headline figures:

  • Hallucination rates reduced by up to 40%
  • Tool success rates improved by 30%
  • Software engineering task accuracy improved by 25%
  • IT-operations success rates boosted by 20%

These are meaningful improvements. But there's a subtler point worth noting. TrajTune also improved success-per-dollar and success-per-minute. The agent completed tasks faster and with fewer API calls because it made fewer mistakes. It didn't need as many retries. The prompt refinements didn't just make the agent more accurate. They made it more efficient.

This is an important detail. In production agent deployments, cost and latency matter as much as accuracy. An agent that gets the right answer on the third retry is less valuable than one that gets it right the first time. TrajTune's trajectory-level optimization naturally reduces waste because it targets the specific failure patterns that cause retries.

How This Differs From Existing Methods

Let me be specific about the gap TrajTune fills.

OPRO treats prompt optimization as a black-box optimization problem. It generates prompt candidates, evaluates them on task performance, and iterates. But the evaluation signal comes from final outputs. OPRO has no visibility into the internal decision sequence of an agent. It can tell you that prompt A produced better answers than prompt B. It can't tell you that prompt A caused the agent to hallucinate tool calls on step 3, or that prompt B led to repetitive loops on step 7.

DSPy and MIPRO are more sophisticated. They support multi-stage programs where each module gets its own optimized prompt. But each module is still evaluated on its individual output quality. The interaction effects between stages, the cascading failures where one module's output degrades the next module's input, are not directly addressed. DSPy has begun exploring multi-turn trajectory-aware optimization (there's an open GitHub issue for it), but it's not yet a core feature.

PromptAgent uses Monte Carlo tree search to explore the prompt space. This is clever for finding better prompts, but the search signal still comes from single-turn evaluations. The trajectory-level dynamics of agent execution aren't part of the optimization objective.

TrajTune's contribution is making the trajectory itself the unit of analysis. The prompt isn't optimized to produce better text. It's optimized to produce better execution paths. That's a fundamental shift in what "better" means for prompt optimization.

Practical Implications

If you're building LLM agents today, TrajTune suggests several practical shifts in how you think about prompt engineering.

Stop evaluating prompts on final outputs alone. When your agent fails, you need to know which step failed, what kind of failure it was, and what prompt patterns correlate with that failure. Logging full trajectories isn't optional for production agents. It's essential infrastructure.

Categorize your failures. Not all agent failures are the same. Hallucinated tool calls, repetitive loops, and incorrect parameter passing are different problems that need different fixes. TrajTune's error categorization approach gives you a vocabulary for diagnosing what's going wrong.

Use diverse feedback sources. If you're iterating on prompts by asking the same model to improve its own instructions, you're probably hitting local optima. Bring in different models or different perspectives to break out of those ruts.

Think about thresholds, not just scores. Raw error rates don't tell you when to intervene. You need to know what's normal for your domain and what's a genuine regression. Building adaptive baselines into your evaluation pipeline makes your optimization loop more efficient.

Budget for iterative refinement. Prompt optimization for agents isn't one-shot. It's a cycle of running, evaluating, diagnosing, refining, and running again. TrajTune's feedback loops formalize this. Plan your development process accordingly.

What Still Needs Work

TrajTune is under review, not yet published. Several questions remain.

The paper tests on finance, software engineering, and IT operations agents. These are all domains with relatively well-defined tool interfaces and measurable success criteria. How well does trajectory-based optimization work for more open-ended agent tasks where success is harder to define? Creative writing agents, research assistants, and multi-modal agents might present different challenges.

The multi-LLM feedback loop adds compute cost. Each refinement cycle requires multiple model calls for analysis, proposal, and validation. The paper shows improvements in success-per-dollar, but the optimization process itself has a cost. The tradeoff between optimization cost and downstream efficiency deserves more analysis.

Adaptive thresholds require baseline data. You need to run the agent enough times to establish what normal looks like before you can detect regressions. For new agent types with limited data, cold-start performance is an open question.

The paper also doesn't deeply address how TrajTune handles environments where the tool landscape changes. If an API gets updated or a new tool gets added, the old trajectory patterns may not apply. How quickly do the adaptive thresholds adjust?

These are research questions, not dealbreakers. TrajTune opens a direction that the prompt optimization community needs to explore.

The Bigger Picture

TrajTune is part of a growing recognition that LLM agents need different tooling than LLM chatbots. The prompt engineering practices we developed for single-turn tasks don't transfer cleanly to agentic workflows.

We're seeing this across the field. TrajAD focuses on trajectory anomaly detection for trustworthy agents. STeCa does step-level trajectory calibration for agent learning. SWE-TRACE optimizes long-horizon software engineering agents through process reward models. TrajEval decomposes code agent trajectories for fine-grained diagnosis. The trajectory is becoming the unit of analysis for agent research.

This makes sense. Agents are fundamentally sequential decision-makers. Their quality emerges from the interaction of many choices over time. Evaluating and improving them requires methods that operate at the same granularity as their execution.

TrajTune's specific contribution is applying this insight to prompt optimization. Prompts are the steering mechanism for agent behavior. If we want better agents, we need better ways to tune that steering. Looking at the full trajectory, not just the final output, gives us a richer signal for doing exactly that.

The shift from output-level to trajectory-level optimization isn't just a technical improvement. It's a conceptual reframe. It says: for agents, the path matters as much as the destination. And the best way to improve the path is to study it directly.

Citations

Suggested Title

Why Your Agent Prompts Keep Failing (And TrajTune Might Fix That)

Word Count

~1,780 words

Fact-Check Notes

  • The TrajTune paper is under review at ICLR 2026, not yet published. Results are from the submitted manuscript and may change during peer review.
  • The specific percentage improvements (40%, 30%, 25%, 20%) come directly from the paper's abstract on OpenReview. They have not yet undergone peer review validation.
  • I characterized OPRO, DSPy/MIPRO, and PromptAgent as "single-turn" optimization methods. This is a simplification. DSPy supports multi-stage programs, and MIPRO optimizes across stages. However, these methods evaluate each module's output independently and do not optimize prompts based on full agent trajectory analysis. TrajTune's distinction is trajectory-level, not stage-level, optimization. This nuance is important for accuracy.
  • The description of TrajTune's three components (structured traces, error metrics, adaptive thresholds with multi-LLM feedback) is based on the abstract. I did not have access to the full paper, so internal architectural details may differ from what I've described. The adaptive threshold mechanism and the multi-LLM feedback loop are confirmed by the abstract. The specific implementation details are inferred from the framework's stated approach.
  • I referenced an open GitHub issue on DSPy for multi-turn trajectory-aware agents (#9243). This confirms that trajectory-aware optimization is an acknowledged gap in existing frameworks, but it doesn't confirm that TrajTune directly addresses DSPy's specific architecture.