AI 智能體在正式環境為何出錯?五類工程問題及修正方法
My AI agent says "done". Is it, though?
作者歸納 AI 智能體在正式環境常見的五類工程故障,並為每類提出首要修正方法。建議限制每次執行步數、在模型外執行權限檢查,並追蹤每項任務成本、固定模型版本及核對實際系統狀態。文中引用的 Reddit 實務者報告屬從業者分享,並非已核實事故。
Why do AI agents look so good in a demo and then behave so strangely once real users touch them? Is it the model? The prompt? Or is it something much more boring?
I spent some time reading what people who actually run agents in production say about it. Mostly on r/AI_Agents and r/LangChain, where people are refreshingly honest about what went wrong. And I noticed something. Almost none of the problems were about the model being "dumb". They were about plain old engineering. Retries, timeouts, money, versions.
The one that caught my attention most is model versioning. It happens often, and we miss it just as often. AI models get updated behind the scenes, and we think that because we pinned a specific version, we're protected from surprises. We're not, at least not fully. More on that in problem four.
So here are the five problems that kept coming up, with the first fix I'd try for each. Links to all sources are at the end.
Wait, why does one task make 31 calls?
Let's start with my favourite. In one r/AI_Agents thread (November 2026), a team described a 4-step task that turned into 31 calls. One external API was unreliable. The tool call timed out, the framework retried, then the agent planned again and... called it again. And again.
The problem is that several layers retry on their own, and they don't know about each other. AWS has a nice bit of arithmetic about this: with five layers and three tries per layer, the load on the database can grow 243 times. 243! From one failed call.
What I'd do:
- Put a hard step limit on every run. Anthropic calls this a "stopping condition".
- Retry in one place only, in the tool code, and only for errors that can actually succeed on a second try. Back off, add some random delay, set an overall deadline.
- When the retry limit is used up, fail the run. Don't let the agent "think about it" and try once more.
Okay, but what if the call actually worked?
This one is worse. Your call times out, but on the other side the action already happened. So the agent does it again. Two emails. Two orders.
In an r/LangChain thread (September 2026), someone reported a payment tool that timed out at 30 seconds, while the charge cleared at 34. The retry charged the customer twice. I really don't want to be the person who explains that to the customer. 😅
And sometimes the agent just does something it shouldn't. Fortune reported in July 2025 that a Replit coding agent deleted a live database during a code freeze. During a code freeze!
Two things to remember here. A timeout doesn't mean the action didn't happen. And an instruction in the prompt is a request, not a control. OWASP says it plainly: do authorization in the downstream systems, don't rely on the LLM for it.
What I'd do:
- Give each intended action a unique ID that survives retries and restarts. The system that performs the action must enforce it and return the first result for a repeat, the way Stripe's idempotency keys work. If it can't, check what actually happened before trying again.
- Check every action in code, outside the model. Who is asking, for which customer, which record. The answer is allowed, denied, or "needs a person".
- Give the agent only the access the task needs. Nothing more.
Why is the 50th message nine times more expensive?
The same team from the first story said they knew their total model bill, but not which customer or workflow caused it. So their pricing was basically a guess. They also estimated that the 50th message in a long session cost about nine times as much as the first one.
Why? Many agent loops send the whole conversation again on every step. Anthropic's Messages API, for example, is stateless. You always send the full history. And without tagging, all of that arrives as one big invoice.
What I'd do:
- Keep the start of the prompt identical between calls, so the provider can cache it. OpenAI's guide says to put timestamps and other changing content at the end.
- On Anthropic's API you turn caching on yourself. Cache reads cost 0.1× the base input price or less, 5-minute cache writes 1.25×.
- Tag every call with customer, workflow and run. Report the cost per task. And name one person who owns that number.
Nobody deployed anything. So why did it change?
Same team again (they had a rough time, honestly). They were on a "latest" model alias when the provider shipped an update. Same prompts, different behaviour. Their tests didn't catch it for a week.
And my other favourite, from a separate r/AI_Agents discussion (October 2026): a "temporary" rule in an agent's instructions, something like "do not publish, pending human review". It stayed there for a week and silently stopped all output. Nobody noticed. Of course nobody noticed, nothing was red. 🙃
Your agent depends on things outside your release process. And this is the part I mentioned at the beginning: a pinned version is not a full guarantee. Even with a fixed model version, Anthropic notes that infrastructure updates can occasionally produce minor differences in behaviour. So pinning helps a lot, but you still have to watch.
What I'd do:
- Use a fixed model version, not an alias the provider can move to a newer model.
- Plan for retirement. Anthropic gives at least 60 days' notice for public models, so put it in the calendar.
- Log the model version the API returns and alert when it changes. Run a small daily test on fixed inputs and judge the outcome, not the wording.
- Give every "temporary" rule an owner and a review date.
Everything is green. So why is it wrong?
This is the one that scares me the most. An API returns 200, so the agent assumes everything worked. But the system may still be in the wrong state, a downstream job may not have finished, or an action may have run twice. On the dashboard, that run is green.
A success log doesn't prove the task was done correctly. Anthropic has a simple example: the agent says a flight is booked, but the real outcome is whether a reservation exists in the database.
What I'd do:
- Write success criteria for each task before launch, and again before any model change. Anthropic's test is nice: two domain experts would reach the same verdict independently.
- Build a small test set from real (anonymised) cases. The same guide says 20 to 50 simple tasks drawn from real failures is a great start. Not 5,000. Twenty.
- Check the end state in the system that holds the truth, not in the agent's summary. And allow three answers: pass, fail, or unknown.
- Every week, read a few runs that "succeeded". Just read them.
So, what's the verdict?
Here's the quick version:
| Problem | What you see | First fix |
|---|---|---|
| Retry storms | One failed call becomes many | Step limit per run, retry limit per tool |
| Side effects without a gate | An action runs twice, or where it shouldn't | Unique ID per action, rule check outside the model |
| Cost nobody owns | Nobody knows what one task costs | Stable prompt start, tagged calls, cost per task |
| Silent changes | Behaviour changes without a release | Fixed model version, review dates for temporary rules |
| Green but wrong | Run says success, the real system disagrees | Written success criteria, independent end-state check |
None of these fixes are about a smarter model. They're limits, gates, owners and checks. Boring stuff. The kind of stuff we already know how to do for normal software, we just somehow forget it when the word "agent" shows up. 😄
But I think the biggest problem is the mindset. We still get caught thinking that models are consistent, predictable and deterministic, like the rest of our code. They're not. It's a hidden trap, and sooner or later every engineer pays the price for it.
And what about you? Which one of these have you already hit? Or do you have a sixth one I should add to the list?
I'd love to hear your stories in the comments!
This article was written with the help of AI and checked by me before publishing. A longer version first appeared on smartmobilehouse.com.
If you liked it, you can also follow me on LinkedIn.
References
- Reddit reports: public r/AI_Agents (October and November 2026) and r/LangChain (September 2026) discussions. These are practitioner reports, not verified incidents.
- AWS: Timeouts, retries and backoff with jitter
- Anthropic: Building effective agents
- Google SRE book: Addressing cascading failures
- Fortune: Replit coding agent wiped a database
- OWASP LLM06: Excessive agency
- Stripe: Idempotent requests
- Anthropic: Working with the Messages API
- OpenAI: Prompt caching
- Anthropic: Prompt caching
- Anthropic: Model IDs and versions
- Anthropic: Model deprecations
- Anthropic: Demystifying evals for AI agents
來源:DEV Community · dev.to