What Is an AI Agent

“Agent” has been stretched to mean almost anything: a chat window with web search, or a script that calls an API. The useful test is whether the system has a closed loop — can it decide what to do next based on what just happened?

Three parts

An agent is usually made of three pieces:

  1. A model that reads the current state and decides the next step.
  2. Tools the model can call: search, file access, code execution, business APIs.
  3. A loop that feeds execution results back into the model until the task finishes or a stop condition is hit.

Drop the third piece and you have “one model call plus fixed post-processing”, not an agent.

goal → observe → model decides → call tool → result → observe again
                                    ↑____________________|

Agents vs chat vs scripts

Chat Script Agent
Who picks the steps The user, each turn Hard-coded The model, based on results
External tools Usually none Yes Yes
Unexpected situations User supplies context Fails May route around it
Predictability Medium High Low

In one line: a script is “a human already figured out the steps”; an agent is “the model figures it out as it goes.” If the steps are known and the task runs thousands of times a day, write a script. Agents earn their cost when the steps cannot be enumerated in advance.

How tool calling actually works

The common mechanism is function calling (vendors name it differently, the shape is the same): you hand the model a list of tools with names, parameter schemas and descriptions. The model replies with intent — which tool, which arguments — and your code performs the actual call, appending the return value to the context.

{
  "name": "search_docs",
  "arguments": { "query": "Astro content collections glob loader" }
}

The model never executes the tool itself. Your code does, which means permissions, timeouts, retries and auditing stay under your control.

Memory and planning

  • Short-term memory is just the conversation context, bounded by the context window.
  • Long-term memory lives outside the model — files, databases, vector stores — and is retrieved when needed.
  • Planning splits a goal into subtasks. Two common patterns: interleave reasoning and acting, or plan first and then execute. The first is more flexible, the second more controllable.

The context window is a hard limit. The longer a task runs, the more likely earlier facts get compressed or dropped — which is why long-running agents “forget” what they already did.

Limits

  1. Errors compound. If each step succeeds with high probability, twenty steps still end with a surprisingly low overall success rate.
  2. Cost and latency are unpredictable. The number of loops depends on the task, not on your budget.
  3. Reproducibility is poor. The same task can produce different results twice; critical paths need human confirmation.
  4. Security matters. An agent that can run code or write files belongs in a sandbox with narrow permissions.

When not to use an agent

  • Fixed steps, run at high volume: write a script. Cheaper and stable.
  • Output must be identical every time: use deterministic code.
  • Money, permission changes, or public publishing: let the agent draft, require a human to execute.

Summary

Agent = model + tools + loop. Before building one, ask whether the steps can be enumerated up front. If they can, write a script. If not, give the model a loop — with an explicit stop condition and a tight permission boundary.