Lesson 12: Tools and AI Agents
A language model on its own can only produce words. Give it tools, and it can do things: look up the weather, search the web, run a calculation, send a message, book a ticket. A tool is simply a function the model is allowed to call — a defined action with named inputs — and the model decides when to use it, fills in the inputs from the conversation, and reads the result back into its reply. That combination — a model that can reason about what to do, and tools that let it do it — is what turns a chatbot into something closer to an assistant.
The pattern works like this. The user asks a question the model cannot answer from its own knowledge, such as the weather in a city today. The model recognises that it needs a tool, chooses the weather tool, and produces a structured call — the city name, the date — instead of a plain reply. The system runs the tool, gets the result, and hands it back to the model as new context. The model then writes its answer using that result. If the task needs several steps, the model can call tools in a loop: search, read, calculate, then answer — checking each result before deciding the next step.
From tools to agents
An AI agent is a system that carries this loop further: given a goal, it plans a sequence of steps, uses tools to carry them out, watches the results, and adjusts its plan when something goes wrong. A research agent might be asked to compare three products: it searches for each one, reads the pages, extracts the prices, checks them against each other, and writes a summary. A coding agent might be asked to fix a bug: it reads the code, runs the tests, changes the code, and runs the tests again until they pass. The model is the reasoning part; the tools are its hands.
Agents are powerful, but they are also where the risks grow. A model that can act can also act wrongly: call the wrong tool, misread a result, repeat a step in a loop, or take an action the user never intended — such as sending a message or spending money. That is why real agent systems put guardrails around them: the agent may read freely but must ask before it sends, spends or deletes; every action is logged; and a human can stop it at any time. The rule is simple and worth remembering: the more an agent can do, the more carefully it must be supervised.
When not to use an agent
Agents are exciting, and that is exactly why they are overused. Many jobs do not need a loop of planning and acting at all. If the task is a single, well-defined step — summarise this document, translate this paragraph, sort this feedback — a single model call with a good prompt is faster, cheaper and far easier to debug. If the task follows a fixed sequence that never changes, ordinary code with a model call at one step is more reliable than an agent deciding what to do next each time. An agent earns its place only when the task genuinely needs judgement at each step: when the number of steps is unknown in advance, when the results of one step decide what the next step should be, and when a wrong step can be caught and corrected. A useful test before building an agent is to ask: could I write down the steps in advance? If the answer is yes, write them down in code instead, and let the model do the one part that needs language. Save the agent for the jobs where you truly cannot predict the path.
Agents also inherit every weakness of the model inside them. If the model misunderstands the goal, the whole plan goes wrong. If a tool returns bad data, the agent may build confidently on it. And if the instructions are ambiguous, the agent will fill in the gaps with its own guesses. The skill of working with agents is therefore the skill of writing clear goals, choosing safe tools, and checking the work at each step — the same judgement you have been building throughout this course, now applied to a system that acts on its own.
The agent loop: plan, act, observe, adjust
Each step's result becomes the context for the next decision. The loop only ends when the goal is reached, or when a human stops it.
Watch & Learn
One video to watch for this unit, from a trusted educator.
- What is Retrieval-Augmented Generation (RAG)? — IBM Technology
IBM research scientist Marina Danilevsky explains how RAG pairs a language model with a search step, so answers are grounded in documents and can be checked against their sources.
Key Terms
- Tool
- A defined action a model is allowed to call, such as looking up the weather or searching the web, with named inputs it must fill in.
- Tool call
- The structured request a model produces when it decides to use a tool, giving the tool's name and its inputs.
- AI agent
- A system that works towards a goal by planning steps, using tools to carry them out, observing the results and adjusting its plan.
- Agent loop
- The repeating cycle of planning, acting with a tool, observing the result and adjusting the plan until the goal is done.
- Guardrail
- A limit placed on an agent, such as requiring human approval before it sends, spends or deletes anything.
- Planning
- Breaking a goal into a sequence of steps, which the agent then carries out and revises as results come in.
Discussion Questions
- A model can only produce words. What changes when it is given tools, and what new mistakes become possible?
- An agent is asked to book a flight and books the wrong one. Who is responsible — the model, the tool, or the person who set it going?
- Why should an agent be allowed to read freely but need permission before it sends, spends or deletes?
Practice Questions
- What is a tool, in the context of a language model?
- Describe the tool-use pattern in three steps.
- What is an AI agent?
- Give one example of a task an agent could do that a plain chatbot could not.
- Why do agent systems need guardrails?
Show answers
- A defined action the model is allowed to call, such as looking up the weather, with named inputs. The model decides when to use it, fills in the inputs, and reads the result back into its reply.
- The model chooses a tool and fills in its inputs; the system runs the tool; the result is handed back to the model as context. The model then writes its answer using that result.
- A system that works towards a goal by planning steps, using tools, observing results and adjusting its plan. It carries the tool-use loop further, handling multi-step tasks on its own.
- Comparing three products by searching for each, reading the pages, extracting prices and writing a summary. A plain chatbot can only produce words; an agent can act through tools.
- Because an agent that can act can also act wrongly — calling the wrong tool or taking an unintended action. Guardrails such as approval before sending or spending, logging, and a human stop, keep the agent supervised.