惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Engineering at Meta
Engineering at Meta
雷峰网
雷峰网
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
B
Blog
Y
Y Combinator Blog
WordPress大学
WordPress大学
Microsoft Azure Blog
Microsoft Azure Blog
小众软件
小众软件
G
Google Developers Blog
云风的 BLOG
云风的 BLOG
罗磊的独立博客
博客园 - 三生石上(FineUI控件)
博客园 - 叶小钗
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
量子位
The Cloudflare Blog
T
The Blog of Author Tim Ferriss
博客园_首页
B
Blog RSS Feed
Hugging Face - Blog
Hugging Face - Blog
IT之家
IT之家
阮一峰的网络日志
阮一峰的网络日志
L
LangChain Blog
宝玉的分享
宝玉的分享

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant
When Your Agent Calls the Wrong Tool: Making Function-Cal...
Rishabh Jain · 2026-06-18 · via DEV Community

The first time we put an agent in front of real tools, it did something instructive. Asked to "refund the customer's last order," it called cancel_subscription instead of issue_refund. Both tools existed. Both were plausibly related to an unhappy customer. The model picked the wrong one and executed it with complete confidence.

This is the part of agent engineering that the demos skip. Letting a model generate text is easy. Letting it take actions in your systems - call functions, hit APIs, change state - is where reliability either exists or it does not. Here is how we make function-calling trustworthy enough to put in production.

Fewer tools, sharper names

The more tools you hand an agent, the more chances it has to choose wrong. We have watched accuracy fall off a cliff once a single agent has twenty-plus tools with overlapping purposes. Two fixes: keep the tool set small and distinct, and name and describe each tool so precisely that confusion is hard. refund_order with a description that says "issues a monetary refund for a completed order; does NOT cancel subscriptions" beats a vague handle_order every time. The description is not documentation - it is the instruction the model actually reads when deciding.

Validate arguments before you trust them

Even when the agent picks the right tool, it can pass nonsense: a refund amount larger than the order, a date in the wrong format, a customer ID that does not exist, a negative quantity. The model is generating plausible-looking arguments, not verified ones. So every tool we expose validates its inputs hard, on the server side, before doing anything - type checks, range checks, existence checks, business-rule checks. An invalid call returns a clear error the agent can read and correct, rather than corrupting data. Treat agent-supplied arguments exactly as you would treat input from an anonymous user on the internet: never trusted.

Separate "read" tools from "write" tools - and gate the writes

Reading data is low-risk; changing data is not. We split tools into those two classes and treat them very differently. Read tools an agent can call freely. Write tools - anything that moves money, sends a message, deletes a record, changes an order - go through extra gates: stricter validation, rate limits, and for the highest-stakes actions, a human approval step. The agent prepares the action; a person confirms it. As trust in a specific workflow grows, you can loosen the gate. You do not start there.

Make actions idempotent and reversible where you can

Agents retry. A tool call times out, the agent assumes failure and calls again - but the first call actually went through. Now you have refunded twice. The defense is an idempotency key on every state-changing tool: a deterministic identifier the server checks so a repeated call returns the original result instead of acting again. And wherever the business allows, prefer reversible actions - a "draft" or "pending" state a human can release - over irreversible ones the agent commits instantly.

Give the agent honest errors, not silence

When a tool fails, what you return matters enormously. Return a generic "error" and the agent flails - retries blindly, or invents a success message to the user. Return a specific, readable message - "refund failed: order 4471 is already fully refunded" - and a capable model will reason about it correctly, explain it to the user, or choose a different path. We treat tool error messages as a first-class part of the design, written for a reader who has to decide what to do next.

Log every call, because you will need the trail

When an agent does something surprising in production, the only way to understand it is to see exactly which tools it called, with which arguments, in what order, and what came back. We log every tool invocation as a structured record. This is not optional - it is the difference between "we fixed it in an hour" and "we have no idea what happened." It is also what lets you build the evaluation set that catches the next regression before it ships.

Test the actions, not just the chat

Most teams test whether the agent says the right thing. Far fewer test whether it does the right thing. We build a suite of scenarios - "customer asks for a refund on an already-refunded order," "user requests a cancellation but means a pause" - and assert on the actual tool calls the agent makes, not the words it produces. That is where the real bugs hide, and it is the only way to ship action-taking agents with a straight face.

The shift from a chatbot to an agent is the shift from generating words to taking actions, and actions have consequences. Reliable function-calling is not one trick - it is a stack of small disciplines: a tight tool set, hard validation, gated writes, idempotency, honest errors, and tests that check behavior. Put them in place and an agent becomes genuinely useful. Skip them and you have shipped an unpredictable hand on your production systems.


About Shanti Infosoft: Shanti Infosoft is a CMMI Level 5 AI development company that has delivered 700+ projects across 16+ industries. We help teams move from AI ideas to dependable, production-grade software - shantiinfosoft.com | AI development services.

If your agent calls the wrong tool often enough to make you nervous, we can harden its function-calling layer until it is reliable enough to ship. Talk to our team.

Related reading: AI Writes 4x the Code. Here's the QA Layer That Stops 4x the Bugs

Rishabh Jain is a Director at Shanti Infosoft, where the team builds AI agents and automation for real business operations.