AI Engineering Curriculum
Phase 0: Foundations·3 min read

Module 0.3

How Agents Work

The Agent Loop

A single API call to an LLM is not an agent. An agent is a loop:

1. Receive task
2. Think → what's the next step?
3. Act → call a tool (search, read file, run code, call API...)
4. Observe → get the tool result back
5. Repeat from 2 → until the task is done
6. Return final answer

This loop is what makes agents capable of multi-step tasks. A single LLM call can only work with what's already in the prompt. An agent can go get new information, take actions, and adapt based on results.


Tool Use

Tools are functions you define that the model can choose to call. You build them, the model decides when to use them.

Common examples:

  • search_web(query) - retrieve current information
  • read_file(path) - read a document
  • run_code(code) - execute and return output
  • send_email(to, body) - take an action in the world

Critical detail: The model doesn't execute tools itself. Here's exactly what happens:

1. You send the model a task + list of available tools
2. Model outputs: "I want to call search_web('AI agent frameworks')"
3. Your code actually runs the search
4. You feed the result back to the model
5. Model continues reasoning with that new information

The model is the brain. Your code is the hands.


Memory

Agents have three types of memory:

TypeWhat it isLimit
In-contextEverything in the current conversationContext window cap
ExternalA database the agent queries via a toolUnlimited
In-weightsWhat the model learned during trainingFixed at training time

In-context is the default - everything the agent has seen this session. It's fast but finite.

External memory (via a vector database) is how agents access knowledge larger than the context window. This is what RAG is - covered in Phase 2.

In-weights is general world knowledge baked into the model. You can't update it without retraining.


Reasoning Patterns

Not all agents use the same thinking structure. Three common patterns:

ReAct (Reason + Act) - the most common

Thought: I need to find the current price of NVIDIA stock
Action: search_web("NVIDIA stock price today")
Observation: $875.23
Thought: Now I have the data, I can answer
Answer: NVIDIA is currently trading at $875.23

Plan then Execute - make a full plan first, then carry it out step by step. Good for complex, predictable tasks.

Reflection - after completing a task, the agent reviews its own output and checks for errors before returning the answer. Improves reliability on high-stakes tasks.


Where Things Go Wrong

ProblemWhat's happening
Infinite loopAgent keeps calling tools without making progress
Tool misuseModel calls the wrong tool or passes bad arguments
Context overflowLong agent run fills the context window and breaks
Hallucinated tool callsModel fabricates a tool result instead of actually calling it

These aren't edge cases - they're common. Handling them is a big part of what Phase 2 is about.


Sources