AI Agent

Let a language model work in a loop: decide the next action, call a tool, look at the result, and repeat until the goal is reached.

Description

An agent is a model with tools (search, read a file, query a database, call an API) running in a loop. Each turn it looks at the goal and everything so far, chooses an action, your code executes the tool, and the result goes back into the next turn. It stops when it decides the task is done or hits a limit.

Unlike a fixed chain, the agent chooses its own path, which makes it good at open-ended tasks such as debugging, research or multi-step support cases. That same freedom makes it less predictable and more expensive, so give it clear tools, tight limits and a way to hand off to a person.

System design

goal1goal + history2call tool: run_tests3execute4approve deploy?5result + steps taken6UserAgent loopmax 15 stepsLanguage modeldecides next actionToolssearch · read · run testsHuman approvalirreversible actions

AI Agent system design diagram

  1. User (client).
  2. Agent loop (service): max 15 steps.
  3. Language model (language model): decides next action.
  4. Tools (function): search · read · run tests.
  5. Human approval (client): irreversible actions.
  6. Step 1: User → Agent loop: goal.
  7. Step 2: Agent loop → Language model: goal + history.
  8. Step 3: Language model → Agent loop: call tool: run_tests.
  9. Step 4: Agent loop → Tools: execute.
  10. Step 5: Agent loop → Human approval: approve deploy?.
  11. Step 6: Agent loop → User: result + steps taken.
  1. The user gives a goal, such as "fix the failing test in checkout".
  2. The loop sends the goal and everything that has happened so far to the model.
  3. The model answers with an action: call a tool with arguments, or stop.
  4. The loop executes the tool and adds the result to the history. Steps 2–4 repeat until the model says it's done or a limit is reached.
  5. Anything irreversible, such as deploying or deleting, waits for a person to approve.
  6. The user gets the result and a log of the steps taken.
AWS
Amazon Bedrock Agents and AgentCore; Lambda as tools; Step Functions for approvals.
Azure
Azure AI Foundry Agent Service; Functions as tools; Logic Apps approvals.
Google Cloud
Vertex AI Agent Builder and Agent Engine; Cloud Run as tools.

When to use it

Use it when

  • The steps can't be known in advance and depend on what's discovered along the way.
  • The task needs several tools, such as searching, reading, running code and updating records.
  • Some slowness and cost are acceptable in exchange for handling open-ended work.

Avoid it when

  • The steps are always the same. A prompt chain is cheaper, faster and more predictable.
  • Mistakes are costly and can't be reviewed: payments, deletions, legal commitments without a person approving.
  • One retrieval plus one answer is enough. That's RAG.

Pitfalls

  • Too many or badly described tools, so the model picks wrong. Fewer, well-named tools with clear descriptions and examples.
  • No limits: runaway loops burning tokens. Cap steps, time and cost.
  • Dangerous tools without guardrails. Require confirmation for irreversible actions and run tools with least privilege.
  • Poor observability. Log every step, tool call and result so you can see why it did what it did.

Alternatives

Prompt Chaining

Choose it when the sequence of steps is known; code controls the path, not the model.

Retrieval-Augmented Generation

Choose it when the task is answering from documents in one retrieval step.

Workflow with one model step

Choose it when most of the process is deterministic and only one step needs judgement.