AI Agents Explained

RAG, AI Agents & MCP · AI agents · 8 min read · Updated

An AI agent is a system where a model decides what to do next, uses tools, looks at the result and continues until the task is done. A workflow follows steps you wrote in advance, with the model filling in parts. Many useful products are workflows, and that is a good thing: they are cheaper, faster and more predictable.

The agent loop

  1. The model gets a goal and the available tools.
  2. It decides on an action (call a tool or answer).
  3. Your code runs the action and returns the observation.
  4. The model plans the next step.
  5. It stops when the goal is met, or when a limit is hit.

This is the same tool-use loop from the Claude API course, run for as many turns as the task needs.

Memory

  • Short-term memory: the conversation and recent tool results in the context.
  • Long-term memory: facts stored outside the model (a database or vector store) and retrieved when needed.

Planning and decomposition

Complex tasks work better when broken into sub-tasks. The agent can write a plan, execute steps and revise it as results arrive.

When to use an agent

  • Use a plain prompt when one call is enough.
  • Use a workflow when the steps are known.
  • Use an agent when the steps depend on what is found along the way, such as research or debugging.

Failure modes

  • Looping or wandering: always set a maximum number of steps and a cost budget.
  • Wrong tool or wrong arguments: validate and give clear errors.
  • Compounding errors: a small mistake early spoils later steps.
  • Overreach: acting beyond what the user wanted. Use approvals for sensitive actions.

Human in the loop

For anything with real-world effects, let a person review the plan or approve key actions.

Frequently asked questions

Do I need an agent framework?

Not to start. A simple loop around the model API is enough for many cases. Consider frameworks when you need checkpoints, graphs or multi-agent features.

Are agents always better than workflows?

No. Workflows are simpler and more reliable when the steps are known. Use agents only when the path cannot be planned in advance.