Agent Experiences

The delegation cycle

Someone hands a task to an agent, the agent tries it, and your service answers. This page covers what each turn of that loop needs from you.

In short

Agents work in a loop. Someone says what they want, the agent breaks it into steps, tries one step against a service, works out what came back, and then retries, changes approach, or hands the problem back to its user. Your service takes part in that loop only through what it sends back. Every response is a result and an instruction at once: it tells the agent what happened and, without saying so, what to do next. A service works well for agents when every response says what failed, why, whether trying again could help, and where things stand now.

Your API (application programming interface, the way other software talks to your service) has a different deal with an agent than with a human developer. A developer reads your docs once, writes code for the case where everything goes right, and fixes failures with error logs and a search engine. An agent does all of that live. It works out what your service does, tries it, and recovers from mistakes on every request, with no prior familiarity and no way to file a bug report. It works mostly from what it can read right now, plus whatever older knowledge it picked up in training.

The five stages

1. Intent

Someone says what they want, usually without all the details: “renew the annual plan on the work account,” “find out why the last invoice is higher.” The agent holds a goal rather than a set of steps. It also has a budget of time, of tokens (the units AI models are billed in), and of its user’s patience. That budget decides how much failure it will put up with before it gives up on your service and tries another route.

2. Breaking it into steps

The agent turns the goal into possible steps, and to do that it needs to know what your service can actually do. It builds that picture from whatever it can read at that moment: a tool list from an MCP (Model Context Protocol) server, which is a connector that lets AI assistants use your product; an OpenAPI description, a standard file listing everything your API can do; a documentation page it can fetch as plain text; or the buttons and links it can see on the page. If none of that exists, it guesses, and a guessing agent sends exactly the broken requests you were worried about.

3. Attempt

It carries out a step. This is the only stage most API design plans for, and it’s the least interesting, because the case where everything goes right is easy. What matters here is that agents try things on speculation. An agent will often send a call it isn’t sure is correct, because trying is cheaper than being certain.

4. Reading the response

The agent reads what came back and decides what it means. This is where a vague response does the most damage. A 400 error (the server saying the request was wrong) with the body "Invalid request" gives it nothing to go on. It doesn’t know which field was wrong, whether the value was badly formed or just not allowed for this account, or whether there’s another way to get the job done. So it retries the same call with a tiny change, makes up a parameter, or tells the user your service is down.

5. Retry, change course, or hand back

Based on what it understood, the agent repeats the step, tries another way, or hands control back to its user. Handing back counts as success. An agent that stops and says “this needs your card details, here’s the link” has done the right thing. What you want to avoid is the silent middle case: an agent that keeps retrying a call that can never work, or that reports success for something that only half happened.

What the loop needs from your service

A clear list of what your service can do

The agent has to learn what’s possible before it can plan. Give it a list it can read, such as a tool list, an OpenAPI document, or a plain-text or markdown (lightly formatted text) copy of your docs at a fixed address. The list should state each action, the inputs it needs, and anything that has to be true first. Two things matter more than covering everything. Where you can, the list should open without signing in, so the agent can plan before it has a login. And it should be accurate about what the current caller is allowed to do, because an action the agent will be refused is worse than one it never saw.

Errors an agent can understand

An agent can’t do anything with “Oops! Something went wrong.” It needs a fixed error code it can make decisions on, the specific field or item at fault, and one more thing almost nobody provides: whether a retry could ever work. You can’t tell that from the status code (the three-digit number every web response carries) alone. A 429 (too many requests) can be retried later, a 400 (bad request) can’t, and a 409 (conflict) depends entirely on the reason.

Unusable

HTTP/1.1 400 Bad Request
Content-Type: application/json

{
  "success": false,
  "message": "Oops! Something went wrong."
}

Nothing here helps the agent decide what to do. It can’t tell what to change, whether the failure is permanent, or whether part of the operation went through. Its best option is to send the exact same request again, which is how one bad response turns into a spike in traffic.

Usable

HTTP/1.1 422 Unprocessable Content
Content-Type: application/problem+json

{
  "type": "https://api.example.com/errors/invalid-currency",
  "title": "Unsupported currency for this account",
  "status": 422,
  "detail": "Account acct_18f settles in USD. GBP is not enabled.",
  "instance": "/v1/orders",
  "errors": [
    {
      "field": "currency",
      "code": "unsupported_value",
      "allowed": ["USD", "CAD"]
    }
  ],
  "retryable": false,
  "docs": "https://docs.example.com/orders#currency"
}

Now the agent can act. It can switch to an allowed value, or stop and tell the user their account isn’t set up for GBP, and retryable: false ends the loop cleanly. The application/problem+json format is a published standard, RFC 9457, so AI models and code libraries already know its layout.

Two rules keep this useful over time. First, treat error codes as part of your API’s public face: once unsupported_value means something, it has to keep meaning it, because agents make decisions on that exact string. Second, never put information in the human-readable detail text that isn’t also in the structured fields. That sentence is a backup, and an agent shouldn’t need it to know what happened.

Safe retries, because agents retry

Retrying is an agent’s main way of recovering, and it retries in exactly the situations where you’d least want it to: timeouts, dropped connections, and vague 500 errors (the server’s way of saying something broke on its side). In every one of those cases the agent doesn’t know whether the first request worked. Suppose your write endpoints (the addresses in your API that change data) can’t safely be called twice. That means they aren’t idempotent (built so that sending the same request twice has the same effect as sending it once). Then the doubt turns into a double charge, a duplicate booking, or two support tickets, and it becomes your problem rather than the agent maker’s.

  • Let callers attach a unique ID of their own to every request that changes something. Developers call this an idempotency (“safe to repeat”) key. If the same key arrives again, send back the original response instead of doing the work a second time.
  • Tie each key to the signed-in account, and keep keys long enough to cover a realistic retry. A key that expires after thirty seconds won’t protect you from an agent that picks the task back up after checking with its user.
  • Say so in the description of what your service can do. An agent that knows which of your endpoints are safe to repeat can retry with confidence. One that doesn’t know has to risk a duplicate or give up.
  • Where a key isn’t practical, give the agent a way to check, such as a lookup by the caller’s own reference number, so it can ask “did my order actually go through?” before trying again.

Clear results when only part of a job worked

Agents naturally work in batches: “update all of these,” “cancel the ones from March.” When a batch half succeeds, a single overall status code is wrong whichever one you pick. A 200 (success) hides the failures. A 500 suggests nothing happened and invites a retry that repeats the part that already worked.

  • Report the result for each item, with an ID that never changes, so the agent can retry only the items that failed.
  • Say plainly how the batch behaves: all or nothing, or as many as possible. The agent can’t guess, and it needs a completely different recovery plan for each.
  • If an operation can’t be all or nothing, offer the undo step (the cancel, the refund, the rollback) as an ordinary action an agent can take, rather than something that needs a support ticket.

Progress updates for long operations

If a job takes longer than a single request can stay open, give the agent a status it can check. Accept the work, send back an ID and a status address straight away, and let the agent check back or subscribe to updates. The status should name the current stage, say whether the job is finished, and suggest when to check again, so the agent doesn’t pick its own interval. If the job might need a person to step in, such as a confirmation or a payment, make that its own clear state, with a link the agent can hand to its user.

The same thinking applies to information that changes. An agent working over several minutes needs to know whether what it fetched earlier is still current. Conditional requests (asking “has this changed since version X?”) and clear version numbers on your data let it check cheaply instead of downloading everything again.

Agents may remember which services worked

Agents may learn which services to try first, through their own memory, through the tools a user keeps connected, and because a route that worked before tends to get tried again. A service that explains its failures and recovers cleanly is more likely to be used again, and one that returns cryptic errors may be quietly avoided without anyone telling you.

The principles page turns these needs into design rules, and implementation covers the specific protocols to build them on.

Further reading from Field Notes

Posts with more on this topic, each with its date.

All Field Notes

Stay Updated

A monthly email about AI search, AI crawler policy (the rules for the AI bots that visit websites), and new standards for agents. It includes every Field Note published that month, and you can unsubscribe at any time.

We store your email address only to send you this newsletter. See our privacy policy.