Learning/AI Agents — Complete Guide/Lesson 1
Chapter 1·Lesson 1 of 3·10 min

What are AI agents?

What are AI agents?

Understand agents, autonomy, goals, loops, and when an agent is actually useful.

Concept diagram
flowchart TD
U[User goal] --> C[Context + state]
C --> M[Model decision]
M --> D{Action needed?}
D -->|No| R[Final response]
D -->|Yes| P[Policy validation]
P --> T[Tool execution]
T --> S[Tool result]
S --> C

Lesson overview

What are AI agents?

An AI agent is a software system that uses a model to decide what to do next while operating inside an application-controlled environment. A model predicts outputs; an agent combines that model with instructions, state, tools, policies, execution code, feedback and stopping rules.

Agent vs chatbot

A chatbot commonly follows request → model → response. An agent can receive a goal, decide that more information or an action is required, call an allowed tool, inspect the result and continue until it reaches a defined outcome.

Agent vs workflow

A deterministic workflow says A → B → C. An agent introduces a decision point: given the current state, which allowed action should happen next? Use workflows when the sequence is known. Use agents when the system must choose among several actions based on changing context. Strong products often combine both: deterministic code owns critical paths while the model handles fuzzy decisions.

The agent loop

A practical loop is: receive a goal; assemble context; ask the model for a next decision; validate the decision; authorize it; execute a tool if needed; record the result; repeat; stop when the task is complete or a safety/budget boundary is reached.

Autonomy is a budget

Every additional step adds latency, cost and another opportunity for incorrect or unsafe behavior. Production agents should have maximum steps, timeouts, token/cost budgets, tool allowlists and explicit approval gates. A clear stop condition is mandatory.

When agents make sense

Agents are useful when inputs vary and several actions may be required: research, support triage, coding assistance, data investigation and multi-step operations. They are often unnecessary when a simple function or deterministic API call solves the problem.

The design question is not “Can an LLM do this?” It is “Where does model-driven decision making create enough value to justify the additional control surface?”

Core principle

The model can propose. Your application decides. Authentication, authorization, data access, side effects, budgets and irreversible actions must remain enforceable outside the model.

Learning path

Theory → Example → Code → Practice → Quiz → Challenge → Completion

0/6 done

Step 1

Theory

What are AI agents?

An AI agent is a software system that uses a model to decide what to do next while operating inside an application-controlled environment. A model predicts outputs; an agent combines that model with instructions, state, tools, policies, execution code, feedback and stopping rules.

Agent vs chatbot

A chatbot commonly follows request → model → response. An agent can receive a goal, decide that more information or an action is required, call an allowed tool, inspect the result and continue until it reaches a defined outcome.

Agent vs workflow

A deterministic workflow says A → B → C. An agent introduces a decision point: given the current state, which allowed action should happen next? Use workflows when the sequence is known. Use agents when the system must choose among several actions based on changing context. Strong products often combine both: deterministic code owns critical paths while the model handles fuzzy decisions.

The agent loop

A practical loop is: receive a goal; assemble context; ask the model for a next decision; validate the decision; authorize it; execute a tool if needed; record the result; repeat; stop when the task is complete or a safety/budget boundary is reached.

Autonomy is a budget

Every additional step adds latency, cost and another opportunity for incorrect or unsafe behavior. Production agents should have maximum steps, timeouts, token/cost budgets, tool allowlists and explicit approval gates. A clear stop condition is mandatory.

When agents make sense

Agents are useful when inputs vary and several actions may be required: research, support triage, coding assistance, data investigation and multi-step operations. They are often unnecessary when a simple function or deterministic API call solves the problem.

The design question is not “Can an LLM do this?” It is “Where does model-driven decision making create enough value to justify the additional control surface?”

Core principle

The model can propose. Your application decides. Authentication, authorization, data access, side effects, budgets and irreversible actions must remain enforceable outside the model.

Step 2

Example

Example: support resolution agent

A support agent receives a customer question. It can search documentation, inspect an order, draft a response and—only after approval—issue a refund.

The customer request never becomes a refund API call directly. The agent proposes the action; application code verifies identity, order ownership, refund limits and current state before execution.

Step 3

Code

Minimal bounded loop

typescript
while (!isFinished(state) && state.steps < MAX_STEPS) {
  const decision = await model.decide(state);
  if (decision.type === "final") return decision.text;

  const tool = registry.get(decision.tool);
  if (!tool) throw new Error("Tool not allowed");

  const args = tool.schema.parse(decision.args);
  await tool.authorize(context, args);
  const result = await tool.execute(context, args);
  state = reduce(state, result);
}

The model proposes an action; trusted application code validates, authorizes and executes it.

Step 4

Practice

Practice

Choose one feature in your product that could use an agent.

  1. Define the user's goal.
  2. List every decision the system must make.
  3. List the minimum tools required.
  4. Separate read operations from writes.
  5. Define a maximum step count.
  6. Define the exact conditions that stop the run.
  7. Identify one place where a deterministic workflow is safer.

If you cannot describe the stop condition, the agent boundary is not ready.

Step 5

Quiz

1. What makes an agent different from a model?

2. Where should authorization be enforced?

Step 6

Challenge

Challenge

Design a bounded support agent with five tools. Give it a maximum of six tool calls, one human approval gate for refunds, and a deterministic fallback when the model cannot decide. Draw the state transitions and explain why each tool is allowed.

Complete every stage

Work through every step in order, then the lesson will be marked complete.

Each chapter and subtopic has its own public URL under /ai-agent.