An agent does more than return a reply. It can call a tool, read the result and decide what to do next. The application keeps that process going until the task is done or a limit is reached.
The model is one part of it. You also have to decide which tools it can use, how to handle errors and what counts as finished. Those choices become much easier to understand when you can see each step.
This example uses Peak Bean, the fictional coffee company from the RAG post. Jamie wants a refund for a leaking espresso machine. I have scripted the sequence so you can follow the request without waiting for a real model.
These are the main parts of the example request. Flip between turn 1 and turn 3 and watch what changes.
Follow one request
The transcript below shows the information passed around the loop. The agent looks up the order, checks the refund policy and tries to issue a refund. The first attempt is missing a required field.
The decision notes explain the example. They are not a recording of a model's private reasoning. Step through it and watch how the tool error changes the next request.
Press Step or Run. Follow the transcript and the current position in the loop.
lookup_order search_policy issue_refund send_replyidempotency_key. The next call adds it. The loop then checks the refund result and sends the reply. A requested action and a confirmed result are separate steps.
The conversation keeps growing
Each tool result adds more text to the conversation. If you keep all of it, later requests get longer. Eventually the history may exceed the context window or make the useful information harder to find.
Summarising older results can make room, but a summary can also lose details. Keep the goal, unresolved issues and facts the next step still needs.
Jamie's ticket is loaded below. Add more tickets, then tap a history block to shorten it. You can also use the compact button.
Decide when to retry and when to stop
The missing field in the example is easy to fix. Other failures need different responses. An invalid request needs corrected input. A temporary service failure may need a delayed retry. A permission error may need a person.
Retries also need limits. The simulator below lets you change the failure rate, retry count and total number of tool calls allowed for a ticket.
Choose the failure rate and limits, then run 30 tickets. The same settings give the same result.
Before running an agent
- a clear condition for successful completion
- tool descriptions that explain when to use them
- tool results and errors the loop can inspect
- limits on steps, usage and repeated failures
- retries that address the reason for failure
Problems to watch for
Repeating the same failed call
A retry should have a reason to work. In the transcript, the second refund request includes the missing field. Sending the first request again would not fix it.
Step through the retryKeeping too much history
Old tool responses can take up most of a request. A shorter history helps only if it keeps the information needed to finish the task.
Try compacting the historyChoosing the wrong tool
Tool names, descriptions and input schemas affect which tool the model chooses. It needs to know when an order lookup is useful and when it should search the policy.
Read the available toolsWhat I would check before using this
- The loop checks tool results before claiming that an action succeeded.
- Retries have limits and a reason to succeed.
- The context keeps the goal and the information needed for the next step.
- The application can stop safely and leave a useful handoff when it cannot finish.
For a refund workflow, I would also check permissions and duplicate-request handling outside the model. A clear final reply is useful only if the refund itself has been confirmed.
About this example
The transcript, tool responses and decision notes are scripted. The ticket simulator uses a fixed random seed and simplified failure rules. Its token counts and costs are illustrative, not measured API usage. An uncapped failed ticket is displayed as a 40-step example rather than running forever.