DEV Community

Cover image for Your APIs Weren't Designed for AI Agents
ibrahim Kılıç
ibrahim Kılıç

Posted on

Your APIs Weren't Designed for AI Agents

Why tool design, not prompt design, decides how reliably agents work with enterprise systems

The agent had access to the CRM API. All of it.

The team wrapped every endpoint as a tool, connected it to the model, and asked a simple question:

"Update the delivery address for Acme's next order."

The agent searched for customers named Acme and found three. It picked the first one. It listed that customer's orders, found two open ones, and updated the one with the earliest date. Then it updated the customer's default address too, because the update endpoint accepted the full customer object and the agent had already loaded it.

Every API call succeeded. Every response was 200 OK.

Two of the three changes were wrong.

This is a hypothetical example, but the pattern is becoming common as teams connect agents to existing enterprise systems, often through protocols such as MCP that make it very easy to expose an API as a set of tools.

Easy to expose is not the same as safe to use.

Most enterprise APIs were designed for a specific kind of caller: a developer who reads the documentation, writes code once, tests it, and then runs the same calls thousands of times in a predictable way.

An agent is a very different caller.

It reads the tool descriptions at runtime. It decides which tool to call based on language. It fills parameters from context. It interprets error messages. And it may combine calls in an order no developer ever tested.

The API didn't change. The caller did.

A Developer and an Agent Use an API Differently

When a developer integrates with an API, a lot of knowledge lives outside the API itself:

  • The developer knows which customer ID to use, because the application already resolved it.
  • The developer knows that the update endpoint replaces the whole object, because they read the documentation, or broke something in testing.
  • The developer knows that "status: 3" means "shipped", because there is an enum in the code.
  • The developer knows not to call the delete endpoint in a loop.

None of this knowledge transfers automatically to an agent.

The agent sees a tool name, a description, and a parameter schema. That is all. If an important rule is not expressed there, or enforced by the system, the agent doesn't know it.

Developer as caller Agent as caller
Learns the API Once, from documentation and testing Every time, from tool descriptions
Chooses the call At design time, in code At runtime, from language
Fills parameters From resolved application state From context and inference
Handles errors With code written in advance By reading the error message
Call sequence Fixed and tested Dynamic and often untested
Mistakes Found in testing, then fixed Can appear at any time in production

This is why wrapping an existing API endpoint by endpoint is usually the wrong starting point.

The tools an agent uses should be designed for an agent.

Design Tools Around Tasks, Not Endpoints

A typical REST API is organized around resources: customers, orders, addresses, invoices. Each one has create, read, update, and delete operations.

That is a good design for developers. It is often a poor design for agents.

To complete one business task, the agent has to chain several low-level calls, keep track of IDs, and make decisions at every step. Each step is another chance to pick the wrong record or the wrong operation.

Compare two approaches for the delivery address example.

Endpoint-based tools:

search_customers(name)
get_customer(customer_id)
list_orders(customer_id)
update_order(order_id, order)
update_customer(customer_id, customer)
Enter fullscreen mode Exit fullscreen mode

A task-based tool:

change_order_delivery_address(order_reference, new_address)
Enter fullscreen mode Exit fullscreen mode

The second tool does fewer things, and that is the point. It can resolve the order safely, validate the address, change only the delivery address, and refuse if the order has already shipped. It cannot accidentally update the customer's default address, because it doesn't offer that operation.

This doesn't mean every agent tool should be a large, rigid workflow. Agents still need flexible read tools for investigation: searching, filtering, and summarizing. But write operations, especially ones with business consequences, are usually safer as narrow, task-shaped tools.

A useful rule:

Broad tools for reading.
Narrow tools for changing things.
Enter fullscreen mode Exit fullscreen mode

Make Ambiguity a First-Class Response

The most dangerous moment in the example was not the update.

It was the search that returned three customers named Acme, and the agent choosing the first one.

Traditional APIs return lists and let the caller decide. That works when the caller is a person looking at a screen, or code with a precise identifier. An agent will often just take the first result and continue.

Agent tools should treat ambiguity as an explicit outcome, not a list to pick from:

  • If a search returns several plausible matches for an action, return them as candidates and say that a choice is required.
  • Include the information needed to distinguish them: city, customer code, last order date, account owner.
  • For write operations, refuse to act on an ambiguous reference instead of guessing.

A response like this is much safer than a plain list:

Ambiguous: 3 customers match "Acme".
- Acme Ltd. (C-1042), Istanbul, last order 2 days ago
- Acme Limited (C-2210), Izmir, last order 8 months ago
- ACME Trading (C-3307), Ankara, no orders
Specify the customer code to continue.
Enter fullscreen mode Exit fullscreen mode

Now the agent can ask the user, or use context to decide, but it is no longer making the choice silently.

Write Errors for the Model That Will Read Them

When a traditional API call fails, the error message is read by a developer, usually once, while debugging.

When an agent's tool call fails, the error message is read by the model, immediately, and it decides what to do next based on what it reads.

That makes error messages part of the agent's control flow.

An error like 400 Bad Request or VALIDATION_ERROR_17 gives the agent nothing to work with. It may retry the same call, try a different tool at random, or invent an explanation for the user.

A useful error tells the agent three things:

  • What went wrong, in plain language.
  • Whether retrying could help.
  • What to do instead, if there is an alternative.

For example:

Cannot change the delivery address: order SO-88213 has already shipped.
Retrying will not help.
To change the delivery, create a return or contact the logistics team.
Enter fullscreen mode Exit fullscreen mode

There is one important exception. Error messages should not reveal information the user is not allowed to see. "You don't have permission to view this customer" is fine. Revealing the customer's details in the error is not.

Make Every Write Safe to Repeat

Agents retry.

They retry when a call times out. They retry when they are not sure a previous call succeeded. They sometimes call the same tool twice because they lost track of what they already did, or because a workflow was resumed after an interruption.

In a traditional integration, duplicate calls are a rare edge case. With agents, they are normal behavior.

This makes idempotency essential for every tool that changes something:

  • Accept an idempotency key, so the same request processed twice has the same effect as processing it once.
  • Return the existing result when a duplicate request arrives, instead of creating a second order or sending a second email.
  • Make "already done" a successful response, not an error that encourages another attempt.

Creating two orders because an agent retried is not an AI problem. It is an API that wasn't designed for the caller it now has.

Permissions Belong to the Tool, Not the Prompt

The simplest way to connect an agent is to give it a service account with broad access and describe the rules in the system prompt: "Only update orders for the current user's customers. Never delete records."

That is not a permission model. It is a request.

The previous articles in this series covered why the model should not be the security boundary. The same applies to tools:

  • Each tool should run with the permissions of the user the agent is acting for, not with a powerful technical account.
  • Each tool should expose only the operations the agent needs. If the agent never needs to delete customers, the delete tool should not exist.
  • Sensitive tools should require confirmation or approval, enforced by the system, not suggested in a description.
  • Tool descriptions are not security controls. A description can explain when to use a tool. It cannot prevent misuse.

If an operation would be dangerous when called with the wrong parameters, the tool itself must make that impossible or require approval.

Tool Descriptions Are Part of the Interface

For a developer, documentation is helpful. For an agent, the tool description is the documentation, and it is read every time.

Good tool descriptions are short, precise, and written for the decision the agent has to make:

  • When to use the tool, and when not to. "Use this to change the delivery address of a single open order. Do not use it to change the customer's default address."
  • What the parameters mean in business terms. "order_reference: the sales order number, for example SO-88213."
  • What the tool will not do. "This tool does not change orders that have already shipped."

Avoid descriptions that are copied from internal API documentation, full of technical details the agent doesn't need and missing the business rules it does.

And version them. Changing a tool description can change agent behavior as much as changing the model or the prompt.

The strongest argument against all of this

There is a fair objection.

Building a separate layer of agent-specific tools means more code to write and maintain. Models are getting better at using complex APIs, reading documentation, and recovering from mistakes. Wrapping existing endpoints is fast, and it lets teams experiment immediately.

For exploration and prototypes, that is a reasonable approach.

But production is different. A prototype that occasionally updates the wrong record is a lesson. A production system that does the same is an incident.

The extra layer doesn't need to be large. In many cases, a small number of well-designed task tools covers most of what the agent needs to do, while flexible read tools handle the rest. And the work of designing those tools usually reveals business rules that were never written down anywhere, which is valuable in itself.

Better models make good tools more effective. They don't make unsafe tools safe.

A Practical Checklist

Before connecting an agent to an enterprise system, it is worth asking:

  • Are write operations designed around business tasks, not raw endpoints?
  • Can a tool change more than the task requires, such as a whole object instead of one field?
  • Do searches return explicit ambiguity when several records match?
  • Do write tools refuse to act on ambiguous references?
  • Do error messages explain what went wrong, whether to retry, and what to do instead?
  • Are all write tools idempotent, and is "already done" treated as success?
  • Do tools run with the end user's permissions, not a broad service account?
  • Are dangerous operations removed, or protected by system-enforced approval?
  • Do tool descriptions explain when to use the tool, and when not to?
  • Are tool definitions versioned and tested like any other interface?

If most of these are unclear, the agent is probably using an API designed for someone else.

Conclusion

For years, we designed APIs for developers. We assumed the caller would read the documentation, understand the domain, and write careful code once.

Agents break that assumption.

They are a new kind of caller: capable, flexible, and fast, but without the context a developer brings, and with a tendency to guess when things are unclear.

The answer is not to stop connecting agents to enterprise systems. It is to give them interfaces designed for the way they work: task-shaped tools, explicit ambiguity, clear errors, safe retries, and permissions enforced by the system.

Prompts tell an agent what you would like it to do.

Tools decide what it can actually do.

Top comments (0)