What is an AI agent, and when do you need one?
A plain-language guide to agents, single model calls and ordinary code, and how to choose between them.
· 3 min read · By WebSurge Technologies
“AI agent” is used loosely. In this article it means a language model running in a loop that can choose actions, such as calling a tool or an API, look at the result and decide what to do next until it reaches a goal.
Three levels, in order of complexity
- Ordinary code. If the steps are known and the rules are fixed, write code. It is cheaper, faster and fully testable.
- A single model call. If the hard part is understanding messy input (a sentence, a photo, a document), call a model once and ask for a structured result, then let code take over. Our charter search and calorie scan work this way.
- An agent. If the number and order of steps is not known in advance, and the system must decide which tool to use next, an agent loop can be justified.
When an agent is the right tool
- The task needs several lookups or actions whose order depends on what was found.
- The available tools are well-defined APIs, with clear inputs and outputs.
- A wrong step can be detected, undone or reviewed by a person.
When it is not
- A fixed workflow would do the job. A workflow with one or two model calls is simpler and cheaper.
- The action is hard to undo, such as paying, deleting or sending, and no one reviews it.
- You cannot measure whether the agent did a good job.
What makes an agent safe enough for production
- A small, explicit set of tools. The agent can only do what the tools allow, and each tool checks its own inputs.
- Limits. A cap on steps, time and spend per task, plus per-user quotas and a kill switch. See give every AI feature a price tag and an off switch.
- Evaluation. A test set of real tasks that you rerun whenever the model, prompt or tools change, so quality changes are visible.
- Human review for actions with real consequences.
- Logs. A record of each step and tool call, so mistakes can be traced.
Our default
We start with the simplest level that works. Many projects that ask for an agent turn out to need a single model call and good code, and that is a better result for the client: it is cheaper to run and easier to trust. When an agent is justified, we build it with the limits above from the first version.
Examples at each level
- Ordinary code: calculating a quote from a price list, sending an email when an order ships.
- A single model call: turning a typed sentence into search fields, extracting the supplier, date and total from an invoice, naming the foods in a photo.
- An agent: investigating why a delivery is late by checking the order system, the carrier’s tracking and the warehouse log, then drafting a reply, where the next lookup depends on what the last one found.
How agents fail
- Looping. The agent keeps trying the same step. Cap the number of steps and the time.
- Using the wrong tool, or the right tool with wrong inputs. Each tool should validate its own input and refuse anything unsafe.
- Prompt injection. Text that the agent reads, such as a web page, an email or a document, can contain instructions meant to hijack it. Treat everything a tool returns as data, never as instructions, and never give an agent a tool that can do more than the task needs.
- Quiet drift. A change of model or prompt makes results slightly worse. Only a test set will show it.
How to evaluate an agent
Write down 30 to 50 real tasks with the outcome you would accept. Run the agent on them and record three numbers: how often it succeeds, how many steps it takes and what each task costs. Re-run the set whenever anything changes. If success drops or cost rises, you will see it before your users do.
Keep reading
- Let the model read, and let your code decide
- Our AI integration and agents service
- Case study: aviation AI charter search
Have a project in mind? Book a free consultation.