LLM Agents & Tool Use
An LLM agent is a language model that can do things , not just talk. You give it tools (search, code, APIs) and run it in a loop : it reasons about what to do, emits a structured call to a tool, your code runs that tool and returns the result, and the model continues until the task is done. The formula is simple: agent = LLM + tools + a loop .
Learn LLM Agents & Tool Use in our free AI & Machine Learning course — a beginner-friendly interactive lesson with worked examples, a practice exercise and a…
Part of the free AI & Machine Learning course at LearnCodingFast — hands-on lessons with examples you run in your browser, plus practice exercises and a quick quiz.
In this lesson you'll learn function/tool calling, the ReAct (reason + act) loop, planning and multi-step execution, memory, reflection, and the guardrails that keep an agent safe — the same building blocks used by frameworks like LangChain, LlamaIndex, and the native tool APIs from OpenAI and Anthropic.
A plain chatbot answers once and stops. An agent can take actions in the world and react to what it sees. The three ingredients:
Great for a single answer, but it can't look anything up or act on the result.
The loop is what lets it break a task into steps and adapt as it learns more.
This is the most misunderstood part: the model never runs your code . You describe each tool to the model, and when it wants one, it emits a structured call . Your application executes it and returns the result. The steps:
Tip: a tool's schema (clear name, description, typed arguments) is part of the prompt — well-described tools get called correctly far more often.
ReAct stands for Reason + Act . Instead of answering in one shot, the agent interleaves thinking and doing, then observes and repeats:
Run this tiny agent. The “model” is faked so you can watch the reason → act → observe loop without an API key:
And here's what tool calling really looks like — the model emits a structured call, your code runs it:
A useful agent needs more than a loop. Three capabilities turn a toy into something dependable:
Together these give an agent persistence (memory), reliability (reflection), and safety (guardrails) — the difference between a demo and something you'd let run unattended.
📋 The agent loop in pseudocode
⏱ Test Yourself — Timed Quiz
10 quick questions, 12 seconds each. Instant feedback — beat the clock!
Practice quiz
What is the simplest way to describe an LLM agent?
- An LLM plus tools plus a loop
- A faster GPU
- A bigger training dataset
- A spreadsheet macro
Answer: An LLM plus tools plus a loop. An agent is an LLM given tools and run in a loop so it can decide, act, observe, and continue until the task is done.
In tool (function) calling, who actually runs the tool?
- Nobody — the call is only logged
- The language model executes the code itself
- Your application code runs it and returns the result to the model
- The user runs it by hand
Answer: Your application code runs it and returns the result to the model. The model only emits a structured request to call a tool; your code executes it and feeds the result back into the conversation.
What does the model emit when it decides to use a tool?
- A random number
- A structured call naming the tool and its arguments
- A compiled binary
- A new model weight
Answer: A structured call naming the tool and its arguments. Tool calling makes the model output a structured object (tool name plus JSON arguments) that your code can parse and execute.
What do the two parts of the ReAct loop stand for?
- Retry and Accept
- Read and Act
- React and Acquire
- Reason and Act
Answer: Reason and Act. ReAct interleaves Reasoning (thinking about what to do) and Acting (calling a tool), then observing the result and repeating.
Why give an agent a loop rather than a single model call?
- So it can act, observe results, and adjust over multiple steps
- Loops are required by HTTP
- To use more tokens for billing
- To slow it down deliberately
Answer: So it can act, observe results, and adjust over multiple steps. Multi-step tasks need the agent to observe each tool result and decide the next action — a loop enables planning and correction.
Which of these is a typical agent tool?
- The training loss
- A web search function
- The model's softmax layer
- The GPU driver
Answer: A web search function. Tools are external capabilities you expose — web search, code execution, database queries, or third-party APIs.
What role does memory play in an agent?
- It speeds up matrix multiplication
- It compresses the model weights
- It replaces the need for tools
- It lets the agent recall earlier steps, facts, or past tasks
Answer: It lets the agent recall earlier steps, facts, or past tasks. Memory (conversation history or a vector store) lets the agent carry context across steps and sessions instead of forgetting.
What is reflection (self-correction) in an agent?
- The agent deletes its tools
- The agent restarts the GPU
- The agent reviews its own output and fixes mistakes before continuing
- The agent copies the user's last message
Answer: The agent reviews its own output and fixes mistakes before continuing. Reflection has the agent critique or verify its own intermediate work, catching errors before they compound.
Why are stopping conditions and guardrails important?
- They make the model larger
- They prevent infinite loops, runaway costs, and unsafe actions
- They improve image quality
- They are only for training
Answer: They prevent infinite loops, runaway costs, and unsafe actions. Without a max-step limit, budget cap, or action allow-list, an agent can loop forever or take harmful actions.
Which of these is a framework commonly used to build agents?
- LangChain
- Photoshop
- PostgreSQL
- FFmpeg
Answer: LangChain. LangChain, LlamaIndex, and the native tool-calling APIs from providers like OpenAI and Anthropic are common ways to build agents.